#include <Servo.h>
Servo myservo; // Create servo object to control a servo
int buttonPin = 4; // Push button pin
int pos = 0; // Variable to store the servo position
void setup() {
myservo.attach(3); // Attach the servo on pin 3 to the servo object
pinMode(buttonPin, INPUT_PULLUP); // Initialize the push button pin as an input with internal pull-up resistor
}
void loop() {
int buttonState = digitalRead(buttonPin); // Read the state of the push button
if (buttonState == LOW) { // Button is pressed
if (pos < 90) {
pos++; // Increment the servo position
myservo.write(pos); // Move the servo to the new position
delay(15); // Delay to allow the servo to move
}
}
}