summaryrefslogtreecommitdiff
path: root/CODE/debug/IR/communication/rx_teensy/rx_teensy.ino
diff options
context:
space:
mode:
authorAbel Tim <abel@abel-ms7c95.home>2025-03-20 20:16:00 +0100
committerAbel Tim <abel@abel-ms7c95.home>2025-03-20 20:16:00 +0100
commitd4a5a8e430abccc7a08861654dac21ecec3eeb3d (patch)
tree3053b527885a77434338910d48d8733f727083bf /CODE/debug/IR/communication/rx_teensy/rx_teensy.ino
parent73cc3da30e15e061a26752c0f8967a64a86d99c6 (diff)
downloadrobotica-d4a5a8e430abccc7a08861654dac21ecec3eeb3d.tar.gz
robotica-d4a5a8e430abccc7a08861654dac21ecec3eeb3d.zip
send messages via serial
Diffstat (limited to 'CODE/debug/IR/communication/rx_teensy/rx_teensy.ino')
-rw-r--r--CODE/debug/IR/communication/rx_teensy/rx_teensy.ino67
1 files changed, 28 insertions, 39 deletions
diff --git a/CODE/debug/IR/communication/rx_teensy/rx_teensy.ino b/CODE/debug/IR/communication/rx_teensy/rx_teensy.ino
index f135d87..96e14eb 100644
--- a/CODE/debug/IR/communication/rx_teensy/rx_teensy.ino
+++ b/CODE/debug/IR/communication/rx_teensy/rx_teensy.ino
@@ -1,46 +1,35 @@
-String tlocd = "";
-String locd "";
-String irs1 = "";
-String irs2 = "";
-String am1 = "";
-String am2 "";
-bool readloc = false;
-unsigned long datatime = 0;
-
+int incomingbyte = 0;
+bool iswriting = false;
+String tlocdat = ""; //temporary location data
+String locdat = ""; //location data
+int nir = "-99"; // which ir sensor it is
+int pir = "-99"; // amount of pulses it had
void setup() {
- Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
- Serial2.begin(9600);
+ Serial.begin(9600);
+ Serial1.begin(9600); //19200
}
void loop() {
- // send data only when you receive data:
- if (Serial2.available() > 0) {
- datatime = millis();
- byte byteRead = Serial2.read();
-
- if(byteRead == 's'){
- tlocd = ""; 0
-
- readloc = true;
- }
- else if(byteRead == 'e'){
- readloc = false;
- locd = tlocd;
- }
- else if(readloc == true){
- tlocd += (char)byteRead;
+ if (Serial1.available() > 0) {
+ incomingbyte = Serial1.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;
}
- 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);
+ //Serial.println(locdat);
+ sscanf(locdat.c_str(), "%d, %d", &nir, &pir);
+ Serial.print("IR sensor N: ");
+ Serial.print(nir);
+ Serial.print(", with ");
+ Serial.print(pir);
+ Serial.println(" pulses.");
+ delay(10);
}