Hi, I would like to turn a servo counterclockwise for 5 seconds only once while the time is between 07:00-19:00. And while the time is between 19:00-07:00, I would like it to turn clockwise for 5 seconds only once. How can I achieve it?
I think putting another if statement after turning servo with a condition of the same time interval could work. Is there any other way?
Here is void loop side of my function's current status:
if((now.hour()>= 7) && (now.hour()<=19))
{
myservo.write(45); // Turn servo counter clockwise
delay(5000); // For 2 seconds
myservo.write(90); // Stop servo
delay(100);
}
else
{
myservo.write(135); // Turn servo clockwise
delay(2000); // For 2 seconds
myservo.write(90); // Stop servo
delay(100);
}
}
I think you will need a variable to record the fact that the movement has taken place, otherwise it will keep doing it during the time period. Something like this pseudo code
if time between 07 and 19
if movedCCW == false
myservo.write(45); // Turn servo counter clockwise
delay(5000); // For 5 seconds
myservo.write(90); // Stop servo
delay(100);
movedCCW = true;
movedCW = false;
if time between 19 and 07
if movedCW == false
myservo.write(135); // Turn servoclockwise
delay(5000); // For 5 seconds
myservo.write(90); // Stop servo
delay(100);
movedCW = true;
movedCCW = false;
...R
Hi, I would like to turn a servo counterclockwise for 5 seconds only once while the time is between 07:00-19:00.
At some random time during that 12 hour window? If not, then make it turn when the time BECOMES 7:00.