From 21330c945d3796d2da2c2229f67994972682e508 Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Sun, 4 Jul 2021 21:37:58 -0400 Subject: [PATCH] Finalize (mostly) new and improved slavecode --- .../arduino/crawler_slave/crawler_slave.ino | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crawler_software/arduino/crawler_slave/crawler_slave.ino b/crawler_software/arduino/crawler_slave/crawler_slave.ino index 7ef159b..47abae0 100644 --- a/crawler_software/arduino/crawler_slave/crawler_slave.ino +++ b/crawler_software/arduino/crawler_slave/crawler_slave.ino @@ -15,15 +15,23 @@ int id; int val; void setup() { + // For debugging + //Serial.begin(115200); + // Attach the wiper servo to pin 9 windowWiperServo.attach(9); // This is the address the pi will speak to us at - Wire.begin(0x8); + Wire.begin(0x4); // Call receiveEvent when data received Wire.onReceive(receiveEvent); - + + // Setup LED + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + + //Serial.println("Started"); } // Just loop to keep the running code alive, and wait for events to happen. @@ -33,9 +41,14 @@ void loop() { // This method runs when we receive a message void receiveEvent(int n) { - if (Wire.available() == 2) { // Dont do anything if this is not true + Wire.read(); + digitalWrite(LED_BUILTIN, HIGH); + if (true) { // Dont do anything if this is not true id = Wire.read(); // ID of the servo/device to access val = Wire.read(); // Value to assign + + //Serial.println(id); + //Serial.println(val); switch(id) { case 1: @@ -43,4 +56,5 @@ void receiveEvent(int n) { break; } } + digitalWrite(LED_BUILTIN, LOW); }