38 lines
804 B
C++
38 lines
804 B
C++
/* 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
|
|
*/
|
|
|
|
#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
|
|
|
|
void setup() {
|
|
myservo.attach(9); // attaches the servo on pin 9 to the servo object
|
|
|
|
Wire.begin(0x8);
|
|
|
|
// Call receiveEvent when data received
|
|
Wire.onReceive(receiveEvent);
|
|
|
|
}
|
|
|
|
void loop() {
|
|
delay(10);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|