From 32bd0f5b55d765f5b2f705bb50634e6fa9924c39 Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Sun, 4 Jul 2021 20:36:13 -0400 Subject: [PATCH] Add sanity check --- .../arduino/crawler_slave/crawler_slave.ino | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crawler_software/arduino/crawler_slave/crawler_slave.ino b/crawler_software/arduino/crawler_slave/crawler_slave.ino index 8a1d2ee..7ef159b 100644 --- a/crawler_software/arduino/crawler_slave/crawler_slave.ino +++ b/crawler_software/arduino/crawler_slave/crawler_slave.ino @@ -33,12 +33,14 @@ void loop() { // This method runs when we receive a message void receiveEvent(int n) { - id = Wire.read(); // ID of the servo/device to access - val = Wire.read(); // Value to assign - - switch(id) { - case 1: - windowWiperServo.write(val); - break; + if (Wire.available() == 2) { // Dont do anything if this is not true + id = Wire.read(); // ID of the servo/device to access + val = Wire.read(); // Value to assign + + switch(id) { + case 1: + windowWiperServo.write(val); + break; + } } }