Programing a Servo and RTC to sweep on a specific DATE and time (month/day)

Hi everyone, Just posting something I've been working on and trying to see how at the end of the void loop I can set it to where a servo sweeps on a specific month/day

#include <Wire.h>
#include <RTC.h>
#include <Servo.h>

static DS3231 RTC;
Servo myservo;

void setup()
{
Serial.begin(9600);
RTC.begin();

Serial.print("Is Clock Running: ");
if (RTC.isRunning())
{
Serial.println("Yes");
Serial.print(RTC.getDay());
Serial.print("-");
Serial.print(RTC.getMonth());
Serial.print("-");
Serial.print(RTC.getYear());
Serial.print(" ");
Serial.print(RTC.getHours());
Serial.print(":");
Serial.print(RTC.getMinutes());
Serial.print(":");
Serial.print(RTC.getSeconds());
Serial.print("");
if (RTC.getHourMode() == CLOCK_H12)
{
switch (RTC.getMeridiem()) {
case HOUR_AM:
Serial.print(" AM");
break;
case HOUR_PM:
Serial.print(" PM");
break;
}
}
Serial.println("");
delay(1000);
}
else
{
delay(1500);

Serial.println("No");
Serial.println("Setting Time");
//RTC.setHourMode(CLOCK_H12);
RTC.setHourMode(CLOCK_H24);
RTC.setDateTime(__DATE__, __TIME__);
Serial.println("New Time Set");
Serial.print(__DATE__);
Serial.print(" ");
Serial.println(__TIME__);
RTC.startClock();

} 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 >= 0; 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
}
}

Hello,

Something like this

void loop()
{
  static bool done = false;

  if ( done == false && RTC.getMonth() == month && RTC.getDay() == day )
  {
    moveServo();
    done = true;
  }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.