#include <Servo.h>
#include <ezButton.h>
const int BUTTON_PIN = 7; // button pin
const int SERVO_PIN = 9; // servo pin
ezButton button1(BUTTON_PIN); // ezButton object, attach to pin 7
ezButton button2(12);
Servo servo; // servo object
int angle = 0; // initialize servo angle
void setup() {
Serial.begin(9600); // initialize serial
button1.setDebounceTime(50); // debounce time to 50 milliseconds
button2.setDebounceTime(50);
servo.attach(SERVO_PIN); // servo object, attach to pin 9
servo.write(angle); // set to initizalized angle
}
void loop() {
button1.loop(); // call loop function at least once
button2.loop();
if(button1.isPressed()) {
Serial.println("The button is pressed");
// change angle of servo motor
if(angle == 0)
angle = 180;
else if(angle == 180)
angle = 0;
// control servo motor arccoding to the angle
servo.write(angle);
}
else if (button2.isPressed()){
Serial.println("The second button is pressed");
}
}