Actuate a servo once per minute

Hi,

I'm working on a mechanical clock:

The clock uses one servo that has to be actuated once every minute. The design uses Geneva gears to increment the other digits automatically. For example, after the right-most digit goes to 9, the digit next to it automatically gets incremented when the right-most digit flips from 9 to 0.

I have everything working and I'm currently using the Servo example "Sweep" modified as follows:

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

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

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 <= 38; pos += 1) { 
    // in steps of 1 degree
    myservo.write(pos);              
    delay(100);                       
  }
  for (pos = 38; pos >= 0; pos -= 1) { 
    myservo.write(pos);              
    delay(100);                       
  }
}

This works as a demo, but as you can see from the video, it just increments the numbers but isn't keeping time. Basically, I need to have it sweep from 0 to 38 and back once per minute and then stop until the next minute. Everything else is automatic. Looking for tips on how best to accomplish that. I know time can be tricky when it needs to be accurate. Thanks.

If you need that kind of accuracy, you may have to use a Real Time Clock (RTC). Arduino millis() timing may not be accurate enough.

How 'bout a millis() timer? Compiles on Nano, but untested:

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

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

unsigned long startTime, endTime = 60000; // 60 seconds, adjust number to calibrate

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.write(pos);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  startTime = millis();
  doSweep();
}

void loop() {
  if(millis() - startTime > endTime)
  {
    startTime += endTime;
    doSweep();
  }
}

void doSweep()
{  
  for (pos = 0; pos <= 38; pos += 1) {
    // in steps of 1 degree
    myservo.write(pos);             
    delay(100);                       
  }
  for (pos = 38; pos >= 0; pos -= 1) {
    myservo.write(pos);             
    delay(100);                       
  }
}

Thanks... I'll test it out... seems like a good start even if it doesn't work.