Finalize (mostly) new and improved slavecode
This commit is contained in:
parent
32bd0f5b55
commit
21330c945d
|
@ -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,14 +41,20 @@ 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:
|
||||
windowWiperServo.write(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue