#include "Servo.h"
Servo myServo;
const byte PinServo = A5;
const byte PinButUp = 9;
const byte PinButDn = 8;
int ang = 90; // define servo
void setup() {
Serial.begin(115200);
Serial.println("button-servo");
pinMode (PinButDn, INPUT_PULLUP);
pinMode (PinButUp, INPUT_PULLUP);
myServo.attach (PinServo);
myServo.write (ang); // set servo to initial value of ang
}
void loop() {
if (LOW == digitalRead(PinButUp)) {
if (ang < 180) // increment ang if less than 180
ang++; // same as ang = ang + 1
}
else if (LOW == digitalRead(PinButDn)) {
if (ang > 0) // decrement ang if greater than zero
ang--;
}
myServo.write (ang); // set servo to value of ang
delay (25); // 25 msec delay, increament by 40 / sec
}