Cleanup slave software again.
This commit is contained in:
parent
acc5bffb71
commit
67daffd667
|
@ -1,23 +1,20 @@
|
|||
/* Sweep
|
||||
by BARRAGAN <http://barraganstudio.com>
|
||||
This example code is in the public domain.
|
||||
|
||||
modified 8 Nov 2013
|
||||
by Scott Fitzgerald
|
||||
http://www.arduino.cc/en/Tutorial/Sweep
|
||||
*/
|
||||
/* 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>
|
||||
|
||||
Servo myservo; // create servo object to control a servo
|
||||
// twelve servo objects can be created on most boards
|
||||
|
||||
int pos = 0; // variable to store the servo position
|
||||
// This servo is used to wipe and clean the camera lens
|
||||
Servo windowWiperServo;
|
||||
|
||||
void setup() {
|
||||
myservo.attach(9); // attaches the servo on pin 9 to the servo object
|
||||
// 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
|
||||
|
@ -25,13 +22,15 @@ void setup() {
|
|||
|
||||
}
|
||||
|
||||
// Just loop to keep the running code alive, and wait for events to happen.
|
||||
void loop() {
|
||||
delay(10);
|
||||
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
|
||||
myservo.write(pos);
|
||||
windowWiperServo.write(pos);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue