Finalize (mostly) new and improved slavecode

This commit is contained in:
Kenwood 2021-07-04 21:37:58 -04:00
parent 32bd0f5b55
commit 21330c945d
1 changed files with 17 additions and 3 deletions

View File

@ -15,15 +15,23 @@ int id;
int val; int val;
void setup() { void setup() {
// For debugging
//Serial.begin(115200);
// Attach the wiper servo to pin 9 // Attach the wiper servo to pin 9
windowWiperServo.attach(9); windowWiperServo.attach(9);
// This is the address the pi will speak to us at // This is the address the pi will speak to us at
Wire.begin(0x8); Wire.begin(0x4);
// Call receiveEvent when data received // Call receiveEvent when data received
Wire.onReceive(receiveEvent); 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. // Just loop to keep the running code alive, and wait for events to happen.
@ -33,14 +41,20 @@ void loop() {
// This method runs when we receive a message // This method runs when we receive a message
void receiveEvent(int n) { 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 id = Wire.read(); // ID of the servo/device to access
val = Wire.read(); // Value to assign val = Wire.read(); // Value to assign
//Serial.println(id);
//Serial.println(val);
switch(id) { switch(id) {
case 1: case 1:
windowWiperServo.write(val); windowWiperServo.write(val);
break; break;
} }
} }
digitalWrite(LED_BUILTIN, LOW);
} }