Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- const int incSwitch = 8;
- const int decSwitch = 7;
- const int servoPin = 13;
- int angle = 90;
- int change = 2; // this value determines how much the angle changes each time through the loop
- Servo servo;
- void setup(){
- pinMode(incSwitch, INPUT); // initialize pins
- pinMode(decSwitch, INPUT);
- digitalWrite(incSwitch, LOW); // set internal pull up resistors
- digitalWrite(decSwitch, LOW);
- servo.attach(servoPin);
- }
- void loop(){
- if( digitalRead(incSwitch) == HIGH) {
- // here if increment switch pressed
- angle = angle + change;
- }
- if( digitalRead(decSwitch) == HIGH) {
- // here if decrement switch pressed
- angle = angle - change;
- }
- angle = constrain(angle, 0, 180); // limit value of angle
- servo.write(angle);
- delay(20);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement