Advertisement
Guest User

servo

a guest
May 6th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1.  
  2.  
  3. #include <Servo.h>
  4. int button1 = 6; //button pin, connect to ground to move servo
  5. int press1 = 0;
  6. int button2 = 5; //button pin, connect to ground to move servo
  7. int press2 = 0;
  8. Servo servo1;
  9. Servo servo2;
  10. int extend = 5; // variable to store and set the servo position
  11. int lift = 5; // variable to store and set the servo position
  12.  
  13. void setup()
  14. {
  15. Serial.begin(9600);
  16. pinMode(button1, INPUT); //out and down
  17. pinMode(button2, INPUT); //up and in
  18. servo1.attach(7); //extend servo
  19. servo2.attach(8); //lift servo
  20. servo1.write(extend); //starting position
  21. servo2.write(lift); //starting position
  22. digitalWrite(6, HIGH); //enable pullups to make pin high
  23. digitalWrite(5, HIGH); //enable pullups to make pin high
  24. Serial.println("servo button sweep test 12-23-2013");
  25. }
  26. void loop()
  27. {
  28. press1 = digitalRead(button1);
  29. if (press1 == LOW)
  30. {
  31. if (extend<175)
  32. {
  33. extend=(extend+1);
  34. if(extend>180) extend=180; //limit upper value
  35. Serial.println(extend); //for serial monitor debug
  36. servo1.write(extend); // tell servo to go to position in variable 'extend'
  37. delay(100); // waits 100ms to slow servo movement
  38. }
  39. else
  40. {
  41.  
  42. lift=(lift+1);
  43. if(lift>180) lift=180; //limit upper value
  44. Serial.println(lift); //for serial monitor debug
  45. servo2.write(lift); // tell servo to go to position in variable 'lift'
  46. delay(100); // waits 100ms to slow servo movement
  47. }
  48. }
  49. press2 = digitalRead(button2);
  50. if (press2 == LOW)
  51. {
  52. if (lift>5)
  53. {
  54. lift=(lift-1);
  55. if(lift<0) lift=0; //limit upper value
  56. Serial.println(lift); //for serial monitor debug
  57. servo2.write(lift); // tell servo to go to position in variable 'lift'
  58. delay(100); // waits 100ms to slow servo movement
  59.  
  60. }
  61. else
  62. {
  63. extend=(extend-1);
  64. if(extend<0) extend=0; //limit upper value
  65. Serial.println(extend); //for serial monitor debug
  66. servo1.write(extend); // tell servo to go to position in variable 'extend'
  67. delay(100); // waits 100ms to slow servo movement
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement