Hello, like many, I am very new to Arduino. I am building yet another type of door opener, a style of which I could not find anywhere else on this site. There is a PIR mounted on either side of a door and when motion is detected, a continuously rotating servo attached to a gearbox will rotate a swing arm and push off the frame to open the door. I would like it to then pause for 10 seconds, and then the arm needs to rotate back to its original position. The code I wrote is below, it doesn't work correctly as it does not pause or switch rotation directions after a pause.
#include <Servo.h>
Servo myservo;
int pos = 0;
const int inputPin = 2;
void setup()
{
pinMode(inputPin, INPUT);
myservo.attach(9);
}
void loop(){
int val = digitalRead(inputPin);
if (val == HIGH)
{
for(pos = 0; pos < 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 180; pos >=1; pos -= 1)
{
myservo.write(pos);
delay(15);
}
}
}
Please advise me on how to clean up the code
Thanks.