'Pausing' Servo, then restarting minutes later.

Hi all,

Firstly, I apologise if this is a duplicate in any way of any other topics/posts already out there. I took a little bit of time to research and see if I could find the answer to my problem, but I am really new to Arduino and some of the language completely confused me.

I am working on a project where I need two servo's to perform the simple Sweep function simultaneously. I want this to work in 'cycles'. For example, I would like the power to the Arduino to be switch on, the two servos to then sweep for around 5 minutes let's say, then stop for 5 minutes, then start again for 5 minutes and so on.

Is this feasible in any way?! I've read up on Delays and Millis but I am finding it difficult to input this data to the Sweep code that's already available on the Arduino software.

Thanks in advance.

Max.

Yes, it is perfectly feasible to do, and even to do other things seemingly at the same time.

A simple way would be to put all the sweep code at the start of "loop()", and then a big five minute delay at the end of "loop()"

Hey AWOL,

Thanks for your reply.

Would you be able to give me any examples of how I would add this into the existing Sweep code.

E.g. what do I put in here and where?

// Sweep
// by BARRAGAN <http://barraganstudio.com> 
// This example code is in the public domain.


#include <Servo.h> 
 
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 = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

It depends on how accurate you need to be.

void loop() 
{ 
  unsigned long startTime = millis ();
  while (millis () - startTime <= fiveMinutes ) {
	  for(pos = 0; pos < 180; pos++)  // goes from 0 degrees to 179 degrees

etc, with a delay (fiveMinutes); before the end of "loop()" and an appropriate deefinition of "fiveMinutes" would be a very quick and dirty way.

On the other hand, if you need exactly five minutes of sweep, or you need to do other stuff, then you'll need to look at blink without delay for clues.

Thanks AWOL,

I'll try it out in the next couple of hours and come back with questions if I have any.

Max.