Hi I'm new to the arduino, and completely new to programming, but I do have some experience with circuits and wiring. I'm trying to create a simple button controlled servo that would go to a set position of 90 degrees, wait 2 seconds, then go back to position 0. I've tried a few methods of programming this. One result I get is that the servo will go to its position only if the button is held, then go back down when the button is released. The other result is that the servo will go to the set position on a single press, but never go back. I've been using the If command, but I don't know if that's the right one to use.
Here's the code that I originally thought would do it. As I said, I want a momentary button press to set a servo to a preset position, wait two seconds, then go back to it's original position.
#include <Servo.h>
int button1 = 2;
int press1 = 0;
Servo servo1;
void setup()
{
pinMode(button1, INPUT);
servo1.attach(9);
}
void loop()
{
press1 = digitalRead(button1);
if (press1 == HIGH)
{
servo1.write(90);
delay(2000)
servo1.write(0);
}
}
Any help would be greatly appreciated.
Casey