First of all, I do not have all that much programming experience. I want to control a servo with a button, so that I press the button and it moves the servo in a certain way, but this code will not work for me. I press the button and the servo will go back and forth 4-5 times.
#include <Servo.h>
Servo door;
int button;
void setup() {
pinMode(4, INPUT);
door.attach(9);
door.write(0);
}
void loop() {
button = digitalRead(4);
if (button == HIGH) {
delay(10);
button = digitalRead(4);
if (button == HIGH) {
door.write(180);
delay(1000);
door.write(0);
delay(1000);
}
}
}
Thanks,
Jack