Advertisement
Guest User

Untitled

a guest
May 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. /*
  2. This sketch is modified from the 'Sweep' example sketch by BARRAGAN
  3. and the modification by Scott Fitzgerald
  4. */
  5.  
  6. #include <Servo.h> //This is necessary when working with servos. It includes the servo library.
  7.  
  8. Servo myservo; // create servo object to control a servo
  9. // twelve servo objects can be created on most boards
  10.  
  11. int pos = 0; // variable to store the servo position. also this is the starting position of the servo
  12.  
  13. void setup() {
  14. myservo.attach(9); // attaches the servo on pin 9 to the servo object- needs to match the pin servo is on board
  15. // if you change to another pwm pin on the board (11, 10, 9, 6, 5, 3) change above number to match
  16. }
  17.  
  18. void loop() {
  19. for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees in steps of 1 degree
  20. /* experiment with changing these values! quick explanation:
  21. this runs through a loop that starts at 0 (pos = 0) and ends when the servo position
  22. reaches the limit. this will continue to loop until the end condition is met.
  23. the last value is the amount that the servo moves in degrees.
  24. once you develop your project idea, experiment with these values! remember to re-upload your code
  25. if you change anything.
  26. */
  27. myservo.write(pos); // tell servo to go to position in variable 'pos'
  28. delay(15); // waits 15ms for the servo to reach the position. experiment with this number too!
  29. } // end of the first for loop that begins on line 18
  30.  
  31. for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
  32. /* experiment with changing these values as well! right now this is set so that
  33. the servo moves at the same rate 'forward' and 'backward'
  34. depending on your project, you may not want this to be the case!
  35. */
  36.  
  37. myservo.write(pos); // tell servo to go to position in variable 'pos'
  38. delay(15); // waits 15ms for the servo to reach the position
  39. } // end of the second for loop that begins on line 30
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement