Finalize (mostly) new and improved slavecode
This commit is contained in:
parent
32bd0f5b55
commit
21330c945d
|
@ -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,9 +41,14 @@ 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:
|
||||||
|
@ -43,4 +56,5 @@ void receiveEvent(int n) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue