Advertisement
Jay_

Arduino Chapter 4

Mar 8th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. // Sweep
  2. // by BARRAGAN  
  3.  
  4. #include <Servo.h>
  5.  
  6. Servo myservo;  // create servo object to control a servo
  7.                 // a maximum of eight servo objects can be created
  8.  
  9. int pos = 0;    // variable to store the servo position
  10.  
  11. void setup()
  12. {
  13.   myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  14. }
  15.  
  16.  
  17. void loop()
  18. {
  19.   for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  20.   {                                  // in steps of 1 degree
  21.     myservo.write(pos);              // tell servo to go to position in variable 'pos'
  22.     delay(15);                       // waits 15ms for the servo to reach the position
  23.   }
  24.   for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  25.   {                                
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement