Advertisement
Guest User

2 buttons

a guest
Jan 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. const int incSwitch = 8;
  4. const int decSwitch = 7;
  5. const int servoPin = 13;
  6.  
  7. int angle = 90;
  8. int change = 2; // this value determines how much the angle changes each time through the loop
  9.  
  10. Servo servo;
  11.  
  12. void setup(){
  13.  
  14. pinMode(incSwitch, INPUT); // initialize pins
  15. pinMode(decSwitch, INPUT);
  16.  
  17. digitalWrite(incSwitch, LOW); // set internal pull up resistors
  18. digitalWrite(decSwitch, LOW);
  19.  
  20. servo.attach(servoPin);
  21. }
  22.  
  23. void loop(){
  24.  
  25. if( digitalRead(incSwitch) == HIGH) {
  26. // here if increment switch pressed
  27. angle = angle + change;
  28. }
  29. if( digitalRead(decSwitch) == HIGH) {
  30. // here if decrement switch pressed
  31. angle = angle - change;
  32. }
  33. angle = constrain(angle, 0, 180); // limit value of angle
  34. servo.write(angle);
  35. delay(20);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement