as of right now i have my arduino uno programmed to make the the servo move every 3 min. what i want to do though is after the servo has moved 12 times, i want it to stop for 10 hours and then start up again and does this in an endless loop till the power is unpluged
#include <Servo.h> //include the servo libary
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 15; pos < 85; pos += 85) // interverls
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(180000); // waits 3 minutes for the servo to reach the position
}
for(pos = 85; pos>=15; pos-=85) // max rotation
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(500); // waits .5 second for the servo to reach the position
}
}
First move the movement code from your sketch to a separate function. I called it move().
Then the code in loop() becomes relative simple,
(not tested myself)
#include <Servo.h> //include the servo libary
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
unsigned long tick = 0;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for (inti=0; i< 12; i++) move();
delay(10L * 60L * 60L * 1000L); // 10 hours but add an L to make it a long !!
}
void move()
{
for(pos = 15; pos < 85; pos += 85) // interverls
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(180000); // waits 3 minutes for the servo to reach the position
}
for(pos = 85; pos>=15; pos-=85) // max rotation
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(500); // waits .5 second for the servo to reach the position
}
}
theres a problem with the code the highlighted part
#include <Servo.h> //include the servo libary
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
unsigned long tick = 0;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{ for (inti=0; i< 12; i++) move();
delay(10L * 60L * 60L * 1000L); // 10 hours but add an L to make it a long !!
}
void move()
{
for(pos = 15; pos < 85; pos += 85) // interverls
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(180000); // waits 3 minutes for the servo to reach the position
}
for(pos = 85; pos>=15; pos-=85) // max rotation
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(500); // waits .5 second for the servo to reach the position
}
}