Cleanup slave software again.

This commit is contained in:
Kenwood 2021-06-29 22:57:51 -04:00
parent acc5bffb71
commit 67daffd667
1 changed files with 14 additions and 15 deletions

View File

@ -1,23 +1,20 @@
/* Sweep /* Crawler Slave
by BARRAGAN <http://barraganstudio.com> *
This example code is in the public domain. * This code runs on the crawler i2c network
* and provides a cleaner, less CPU intensive control over PWM devices.
modified 8 Nov 2013 */
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Wire.h> #include <Wire.h>
#include <Servo.h> #include <Servo.h>
Servo myservo; // create servo object to control a servo // This servo is used to wipe and clean the camera lens
// twelve servo objects can be created on most boards Servo windowWiperServo;
int pos = 0; // variable to store the servo position
void setup() { 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); Wire.begin(0x8);
// Call receiveEvent when data received // 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() { void loop() {
delay(10); delay(50);
} }
// This method runs when we receive a message
void receiveEvent(int howMany) { void receiveEvent(int howMany) {
while (Wire.available()) { // loop through all but the last while (Wire.available()) { // loop through all but the last
int pos = Wire.read(); // receive byte as a int int pos = Wire.read(); // receive byte as a int
myservo.write(pos); windowWiperServo.write(pos);
} }
} }