From aa575f67a33fb15cf5db6a2a4db73aba72352da8 Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Sat, 3 Jul 2021 22:54:50 -0400 Subject: [PATCH] Create/modify read string code --- .../arduino/crawler_slave/crawler_slave.ino | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crawler_software/arduino/crawler_slave/crawler_slave.ino b/crawler_software/arduino/crawler_slave/crawler_slave.ino index 447eef9..201cd47 100644 --- a/crawler_software/arduino/crawler_slave/crawler_slave.ino +++ b/crawler_software/arduino/crawler_slave/crawler_slave.ino @@ -10,16 +10,23 @@ // This servo is used to wipe and clean the camera lens Servo windowWiperServo; +// This is a variable capable of storing up to 4 items +char instruction[4] = ""; + void setup() { // Attach the wiper servo to pin 9 windowWiperServo.attach(9); + // This is only useful for debugging + Serial.begin(9600); + // This is the address the pi will speak to us at Wire.begin(0x8); // Call receiveEvent when data received Wire.onReceive(receiveEvent); - + + Serial.print("Finished Setup."); } // Just loop to keep the running code alive, and wait for events to happen. @@ -28,9 +35,11 @@ void loop() { } // This method runs when we receive a message -void receiveEvent(int howMany) { - while (Wire.available()) { // loop through all but the last - int pos = Wire.read(); // receive byte as a int - windowWiperServo.write(pos); +void receiveEvent(int n) { + for (int i = 0; i < n; i++) //n is equal to the number of data bytes received + { + instruction[i] = Wire.read(); } + + Serial.print(instruction); }