|
1 | 1 | // Sweep
|
2 |
| -// by BARRAGAN <http://barraganstudio.com> |
| 2 | +// by BARRAGAN <http://barraganstudio.com> |
3 | 3 | // This example code is in the public domain.
|
4 | 4 |
|
5 | 5 |
|
6 |
| -#include <Servo.h> |
7 |
| - |
8 |
| -Servo myservo; // create servo object to control a servo |
9 |
| - // a maximum of eight servo objects can be created |
10 |
| - |
11 |
| -int pos = 0; // variable to store the servo position |
12 |
| - |
13 |
| -void setup() |
14 |
| -{ |
15 |
| - myservo.attach(9); // attaches the servo on pin 9 to the servo object |
16 |
| -} |
17 |
| - |
18 |
| - |
19 |
| -void loop() |
20 |
| -{ |
21 |
| - for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees |
22 |
| - { // in steps of 1 degree |
23 |
| - myservo.write(pos); // tell servo to go to position in variable 'pos' |
24 |
| - delay(15); // waits 15ms for the servo to reach the position |
25 |
| - } |
26 |
| - for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees |
27 |
| - { |
28 |
| - myservo.write(pos); // tell servo to go to position in variable 'pos' |
29 |
| - delay(15); // waits 15ms for the servo to reach the position |
30 |
| - } |
31 |
| -} |
| 6 | +#include <Servo.h> |
| 7 | + |
| 8 | +Servo myservo; // create servo object to control a servo |
| 9 | +// a maximum of eight servo objects can be created |
| 10 | + |
| 11 | +int pos = 0; // variable to store the servo position |
| 12 | + |
| 13 | +void setup() |
| 14 | +{ |
| 15 | + myservo.attach(9); // attaches the servo on pin 9 to the servo object |
| 16 | +} |
| 17 | + |
| 18 | + |
| 19 | +void loop() |
| 20 | +{ |
| 21 | + for (pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees |
| 22 | + { // in steps of 1 degree |
| 23 | + myservo.write(pos); // tell servo to go to position in variable 'pos' |
| 24 | + delay(15); // waits 15ms for the servo to reach the position |
| 25 | + } |
| 26 | + for (pos = 180; pos >= 1; pos -= 1) // goes from 180 degrees to 0 degrees |
| 27 | + { |
| 28 | + myservo.write(pos); // tell servo to go to position in variable 'pos' |
| 29 | + delay(15); // waits 15ms for the servo to reach the position |
| 30 | + } |
| 31 | +} |
0 commit comments