Compare commits

..

No commits in common. "acc5bffb71cd2432d59115b63edb77de66261f8c" and "6a74fcb472f6424bcf3d734519b414b9713a08ee" have entirely different histories.

1 changed files with 10 additions and 14 deletions

View File

@ -7,7 +7,6 @@
http://www.arduino.cc/en/Tutorial/Sweep http://www.arduino.cc/en/Tutorial/Sweep
*/ */
#include <Wire.h>
#include <Servo.h> #include <Servo.h>
Servo myservo; // create servo object to control a servo Servo myservo; // create servo object to control a servo
@ -18,20 +17,17 @@ 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 myservo.attach(9); // attaches the servo on pin 9 to the servo object
Wire.begin(0x8); for (pos = 70; pos <= 130; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
// Call receiveEvent when data received myservo.write(pos); // tell servo to go to position in variable 'pos'
Wire.onReceive(receiveEvent); delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 130; pos >= 70; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
} }
void loop() { void loop() {
delay(10); delay(1000);
}
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);
}
} }