Rev | Line | |
---|
[136] | 1 | /* Sweep
|
---|
| 2 | by BARRAGAN <http://barraganstudio.com>
|
---|
| 3 | This example code is in the public domain.
|
---|
| 4 |
|
---|
| 5 | modified 8 Nov 2013
|
---|
| 6 | by Scott Fitzgerald
|
---|
| 7 | http://arduino.cc/en/Tutorial/Sweep
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | #include <Servo.h>
|
---|
| 11 |
|
---|
| 12 | Servo myservo; // create servo object to control a servo
|
---|
| 13 | // twelve servo objects can be created on most boards
|
---|
| 14 |
|
---|
| 15 | int pos = 0; // variable to store the servo position
|
---|
| 16 |
|
---|
| 17 | void setup()
|
---|
| 18 | {
|
---|
| 19 | myservo.attach(9); // attaches the servo on pin 9 to the servo object
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | void loop()
|
---|
| 23 | {
|
---|
| 24 | for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
|
---|
| 25 | { // in steps of 1 degree
|
---|
| 26 | myservo.write(pos); // tell servo to go to position in variable 'pos'
|
---|
| 27 | delay(15); // waits 15ms for the servo to reach the position
|
---|
| 28 | }
|
---|
| 29 | for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
|
---|
| 30 | {
|
---|
| 31 | myservo.write(pos); // tell servo to go to position in variable 'pos'
|
---|
| 32 | delay(15); // waits 15ms for the servo to reach the position
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.