summaryrefslogtreecommitdiff
path: root/code/debug/communication/rx/rx_decode_teensy/src/main.cpp
blob: f91d6d39e02d68836db352fbecd31e10ca96cb93 (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
42
43
44
45
46
47
48
#include <Arduino.h>

int incomingbyte = 0; 
bool iswriting = false;
String tlocdat = "";  //temporary location data 
String locdat = "";   //location data
int ir1 = -99;  
int ir2 = -99;
int ir3 = -99;
int ir4 = -99;
int ir5 = -99;
int ir6 = -99;
int ir7 = -99;
int ir8 = -99;


void setup() {
  Serial.begin(9600);
  Serial3.begin(9600); //19200
}

void loop() {
  if (Serial3.available() > 0) {
    incomingbyte = Serial3.read();
    //Serial.print(char(incomingbyte));
    if (incomingbyte == 's'){
      iswriting = true;
      tlocdat = "";
    }else if(incomingbyte == 'e'){
      iswriting = false;
      locdat = tlocdat;        
    }else if(iswriting == true){
      //Serial.print(char(incomingbyte));
      tlocdat += (char)incomingbyte;  
    }
  }
  //Serial.println(locdat);
  sscanf(locdat.c_str(), "%d, %d, %d, %d, %d, %d, %d, %d", &ir1, &ir2, &ir3, &ir4, &ir5, &ir6, &ir7, &ir8); //split recieved data into seperate variables
  Serial.print("IR sensor N: ");
  Serial.print(ir1);
  Serial.print(ir2);
  Serial.print(ir3);
  Serial.print(ir4);
  Serial.print(ir5);
  Serial.print(ir6);

  delayMicroseconds(1);
}