Thanks for the help! Robin I gave your idea a try and it really cleaned up the code. Done for tonight but I will try to get the if statements working so both servos can move at the same time. I am happy with what all of you have helped me get working so far!
void loop()
{
sweep(); // sweep arrow and check for button press
}
void door() // open door wait then close door
{
buttonStateDoor = digitalRead(buttonPinDoor); // read the state of the pushbutton value:
if (buttonStateDoor == HIGH) // check if the pushbutton is pressed.
{
digitalWrite(ledPinDoor, HIGH); // turn LED on
myservoDoor.write(3); // close door
}
else
{
digitalWrite(ledPinDoor, LOW); // turn LED off
myservoDoor.write(91); // open door
delay(5000); // wait
myservoDoor.write(3); // close door
digitalWrite(ledPinDoor, HIGH); // turn LED on
}
}
void sweep() // sweep arrow and check for button press
{
for(posArrow = 0; posArrow < 180; posArrow += 1) // goes from 0 to 180 degrees
{
door(); // checks for button press if true then open and closes door
myservoArrow.write(posArrow); // tell servo to go to position in variable 'posArrow'
delay(15); // waits for the servo to reach the position
}
for(posArrow = 180; posArrow>=1; posArrow-=1) // goes from 180 to 0 degrees
{
door(); // checks for button press if true then open and closes door
myservoArrow.write(posArrow); // tell servo to go to position in variable 'posArrow'
delay(15); // waits for the servo to reach the position
}
}