diff options
| author | Abel Tim <abel@abel-ms7c95.home> | 2025-03-20 20:16:00 +0100 |
|---|---|---|
| committer | Abel Tim <abel@abel-ms7c95.home> | 2025-03-20 20:16:00 +0100 |
| commit | d4a5a8e430abccc7a08861654dac21ecec3eeb3d (patch) | |
| tree | 3053b527885a77434338910d48d8733f727083bf | |
| parent | 73cc3da30e15e061a26752c0f8967a64a86d99c6 (diff) | |
| download | robotica-d4a5a8e430abccc7a08861654dac21ecec3eeb3d.tar.gz robotica-d4a5a8e430abccc7a08861654dac21ecec3eeb3d.zip | |
send messages via serial
| -rw-r--r-- | CODE/debug/IR/communication/rx_teensy/rx_teensy.ino | 67 | ||||
| -rw-r--r-- | CODE/debug/IR/communication/tx_seeed/tx_seeed.ino | 21 |
2 files changed, 43 insertions, 45 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); } diff --git a/CODE/debug/IR/communication/tx_seeed/tx_seeed.ino b/CODE/debug/IR/communication/tx_seeed/tx_seeed.ino index fe6d1da..c77e618 100644 --- a/CODE/debug/IR/communication/tx_seeed/tx_seeed.ino +++ b/CODE/debug/IR/communication/tx_seeed/tx_seeed.ino @@ -1,4 +1,5 @@ -long randNumber; +long randNumber1; +long randNumber2; void setup() { Serial.begin(9600); @@ -9,11 +10,19 @@ void setup() { } void loop() { - randNumber = random(300); - Serial.println("transmission test"); - Serial1.println("transmission test"); - Serial.println(randNumber); - Serial1.println(randNumber); + randNumber1 = random(999); + randNumber2 = random(1, 8); + Serial1.print("s"); + Serial1.print(randNumber2); + Serial1.print(", "); + Serial1.print(randNumber1); + Serial1.print("e"); + + Serial.print("s"); + Serial.print(randNumber2); + Serial.print(", "); + Serial.print(randNumber1); + Serial.println("e"); delay(1000); |
