Here is the loaded code
#include <Time.h>
// ===================================================================================
// = library includes =
// ===================================================================================
#include <avr/eeprom.h>
#include <Servo.h>
#include <Time.h>
// ===================================================================================
// = Servo object instatiation =
// ===================================================================================
Servo oServo;
// ===================================================================================
// = Global variable to hold time and interval =
// ===================================================================================
time_t NextEvent;
#define Interval 10 //this is 600 seconds or 10 minutes
// ===================================================================================
// = Array to hold servo positions =
// = these are the servo PWM signals that you will need to tune to your servo =
// ===================================================================================
byte ServoPos[] = {0,51,102,204,255};
// ===================================================================================
// = Structure to hold state =
// ===================================================================================
struct ServoParams_t
{
byte Position;
int Direction;
} ServoParams;
// ===================================================================================
// = Setup code =
// ===================================================================================
void setup()
{
oServo.attach(9); // Attach the oServo object to use pin 9
LoadSettings(); // Read from the EEPORM
if(ServoParams.Direction > 1) ServoParams.Direction = 1; // just a bit of safety in the case of the EEPROM value being out of range
if(ServoParams.Direction < -1) ServoParams.Direction = -1; // just a bit of safety in the case of the EEPROM value being out of range
NextEvent = now() + (Interval); // Set the first interval time
}
// ===================================================================================
// = Main Program loop =
// ===================================================================================
void loop()
{
if(now() >= NextEvent)
{
NextEvent = now() + (Interval); // Set the next interval time
ServoParams.Position += ServoParams.Direction; // Increment or decrement the servo posistion array pointer
if (ServoParams.Position >= 4 || ServoParams.Position <= 0) ServoParams.Direction = -ServoParams.Direction; // check for range end and swap direction
oServo.write(ServoPos[ServoParams.Position]); // Write value to oServer Object
SaveSettings(); // Store state in EEPROM
}
}
// ===================================================================================
// = EEPROM Storage Handlers =
// ===================================================================================
void LoadSettings(void)
{
eeprom_read_block((void*)&ServoParams, (void*)(sizeof(ServoParams)), sizeof(ServoParams));
}
void SaveSettings(void)
{
eeprom_write_block((const void*)&ServoParams, (void*)(sizeof(ServoParams)), sizeof(ServoParams));
}