37 lines
856 B
C++
37 lines
856 B
C++
/* Crawler Slave
|
|
*
|
|
* This code runs on the crawler i2c network
|
|
* and provides a cleaner, less CPU intensive control over PWM devices.
|
|
*/
|
|
|
|
#include <Wire.h>
|
|
#include <Servo.h>
|
|
|
|
// This servo is used to wipe and clean the camera lens
|
|
Servo windowWiperServo;
|
|
|
|
void setup() {
|
|
// Attach the wiper servo to pin 9
|
|
windowWiperServo.attach(9);
|
|
|
|
// This is the address the pi will speak to us at
|
|
Wire.begin(0x8);
|
|
|
|
// Call receiveEvent when data received
|
|
Wire.onReceive(receiveEvent);
|
|
|
|
}
|
|
|
|
// Just loop to keep the running code alive, and wait for events to happen.
|
|
void loop() {
|
|
delay(50);
|
|
}
|
|
|
|
// This method runs when we receive a message
|
|
void receiveEvent(int howMany) {
|
|
while (Wire.available()) { // loop through all but the last
|
|
int pos = Wire.read(); // receive byte as a int
|
|
windowWiperServo.write(pos);
|
|
}
|
|
}
|