summaryrefslogtreecommitdiff
path: root/CODE/debug/IR/communication/rx_teensy/rx_teensy.ino
blob: 8e1ecfa749cf2b650373b4c2e98757ee8c7743ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
String tlocd = "";
String locd = "";
bool readloc = false;
unsigned long datatime = 0;

void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  Serial2.begin(9600);
}

void loop() {
  // send data only when you receive data:
  if (Serial2.available() > 0) {
    datatime = millis(); 
    byte byteRead = Serial2.read();

    if(byteRead == 's'){
      tlocd = ""; 
      readloc = true;
    }
    else if(byteRead == 'e'){
      readloc = false;
      locd = tlocd;
    }
    else if(readloc == true){
      tlocd += (char)byteRead;
    }
    else{
    if(millis() - datatime > 5000){
      Serial.println("Err no data recieved for 5 sec");  
      locd = "999";
    }
    Serial.println(locd);
  }

    // say what you got:
    Serial.print(char(byte byteRead));
  }
  
  delay(111);
}