and here is the beginning of the master arduino code that connects with the RTC, so that you can get an idea of what is going on (I could not copy the whole code, due to the website's word limitation)
// Alarm Clock and Lamp Dimmer
#include "LedControl.h"
#include <Time.h>
#include <Wire.h>
#include <DS3232RTC.h> // DS3231 library that returns time as time_t
#include <EEPROM.h> // to read & write to EEPROM memory
// debugging elements, comment out the next 3 lines if debugging is not needed
/*
#define DEBUG 1
const unsigned long debugDelay = 10000;
unsigned long serialPrintTimer = 0;
*/
// Time LED display control elements
// pin 12 is connected to the DataIn
// pin 11 is connected to the CLK
// pin 10 is connected to LOAD
// 1 = only a single MAX72XX
LedControl lc=LedControl(12,11,10,1);
boolean LEDTimeOff = false;
const unsigned long LEDTimeTurningOffLength = 7000; // time until to start turning off LED display
const unsigned long LEDTimeOffDelayIncrements = 10000; // time between LED intensity decreases
// delay to space out reducing LED display intensity. Delay incremended each intensity decrease
unsigned long LEDTimeOffDelay = LEDTimeOffDelayIncrements;
const int LEDTimeMaxIntensity = 3; // max intensity (0-15).
int LEDTimeIntensity = LEDTimeMaxIntensity;
boolean showingTemperature = false;
// time element
tmElements_t storedTime;
// alarm elements
tmElements_t alarmTime;
tmElements_t stopAlarmTime;
const int stopAlarmOffset = 7; // number of minutes for alarm music to run for
boolean alarmOn = true;
boolean alarmRunning = false;
boolean alarmStopped = false;
// lamp elements. lampState 0 = Off, 1 = downwards, 2 = upwards, 3 = fully on
int lampState = 0;
tmElements_t startDawnTime;
int startDawnOffset = -10; // minutes before alarm music starts for the dimmer to start
int dawnDimmerLength = 20; // length in minutes 1-60 of dawn running time
boolean dawnSimulatorReady2Run = true;
tmElements_t stopDuskTime;
const int duskDimmerLength = 10; // length in minutes 1-60
boolean duskModeRunning = false;
tmElements_t lampTurnOffTime;
int mintutesOfNoInput = 120;
// settings elements
char minuteOrHour = 'm';
unsigned long noInputTime = 0;
unsigned long flashingTimer = 0;
unsigned long flashDelay = 600;
boolean flashingState = false;
int dawnTrackNumber = 0; // first dawn tract
int duskTrackNumber = 100; // first dusk tract
// 0-99 where 0 = one song
int numberOfDawnSongs = 44;
// 0-99 where 0 = song one. Need to add 100 to use the tract with
// the sound module functions.
int numberOfDuskSongs = 22;
// button elements
// array of pin numbers for the 4 buttons, including the tilt switch, which is last.
const int buttonPins[] = {A0, A1, A2, A3, 9};
int buttonState[] = {LOW, LOW, LOW, LOW, LOW};
int buttonLastState[] = {LOW, LOW, LOW, LOW, LOW};
// 0 is change to LOW, 1 change to HIGH, 2 = no change
int buttonChangedTo[] = {2, 2, 2, 2, 2};
unsigned long buttonLastDebounce[] = {0, 0, 0, 0, 0};
unsigned long buttonTimers[] = {0, 0, 0, 0, 0};
const long debounceDelay = 50;
// RGB LED elements
const int RGBLEDPins[] = {3, 6, 5}; // red, green and then blue
const int RGBMaxBrightness = 80; // max brightness (0-255)
int RGBLEDValues[] = {0, 0, 0};
// 0 = red, 1 = green, 2 = blue
int RGBLEDColour2Change = 1;
int RGBLEDUpOrDown = 1; //0 = down, 1 = up
unsigned long RGBLEDTimer = 0;
unsigned long RGBLEDTimer2 = 0;
void setup()
{
int EEPROMCounter = 0;
int bytesFromMasterToSlave = 0;
// MAX72XX LED controller wake up and show time
lc.shutdown(0,false);
/* Set the brightness 0-15 */
lc.setIntensity(0,LEDTimeIntensity);
/* and clear the display */
lc.clearDisplay(0);
// RGB LED setup
for(int i = 0; i < 3; i++)
{
pinMode(RGBLEDPins[i], OUTPUT);
analogWrite(RGBLEDPins[i], 0);
}
/*
// time setup (comment out if you don't want to reset the time when power turned off)
storedTime.Hour = 18;
storedTime.Minute = 16;
storedTime.Second = 00;
storedTime.Day = 17;
storedTime.Month = 7;
storedTime.Year = CalendarYrToTm(2014);
RTC.write(storedTime);
*/
// the function to get the time from the RTC
// I have changed to using a DS3231
setSyncProvider(RTC.get);
setSyncInterval(3600); // resyn interval (3600 = seconds in one hour, 86400 = seconds in one day)
//to help with showing the time on the LED display
storedTime.Hour = hour();
storedTime.Minute = minute();
// to check all of the LED screen elements are working
lc.setDigit(0,0,8,false);
lc.setDigit(0,1,8,false);
lc.setDigit(0,2,8,true);
lc.setDigit(0,3,8,true);
delay(2000);
lc.clearDisplay(0);
delay(1000);
// check RGB LEDs are working
for(int i = 0; i < 3; i++)
{
analogWrite(RGBLEDPins[i], RGBMaxBrightness);
delay(2000);
analogWrite(RGBLEDPins[i], 0);
}
delay(1000);
showTimeLED(storedTime);
//alarm setup
alarmTime.Hour = 12;
alarmTime.Minute = 01;
startDawnTime = alarmTime;
changeTime(startDawnTime, startDawnOffset);
stopAlarmTime = alarmTime;
changeTime(stopAlarmTime, stopAlarmOffset);
lampTurnOffTime.Hour = hour();
lampTurnOffTime.Minute = minute();
changeTime(lampTurnOffTime, mintutesOfNoInput);
#ifdef DEBUG
Serial.begin(9600);
Serial.println(" ");
Serial.println("Welcome to the Alarm clock serial interface");
Serial.println(" ");
if(timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
#endif
// button setup
for(int i = 0; i < 5; i++)
pinMode(buttonPins[i], INPUT);
// I2C bus join and turn off the lamp
Wire.begin();
TWBR = 152; // 50 kHz. TWBR = 72; // 100 kHz (default)
Wire.beginTransmission(4); // transmit to device #4
Wire.write(0); // turn off the lamp
Wire.write(0); // zero minutes
Wire.write(0); // zero minutes
Wire.endTransmission();
Wire.requestFrom(5, 1);
bytesFromMasterToSlave = Wire.read();
// stops all music
Wire.beginTransmission(5);
Wire.write(0);
Wire.write(0);
Wire.write(0);
Wire.write(0);
Wire.write(0);
Wire.write(0);
Wire.write(0);
Wire.write(0);
Wire.write(0);
Wire.endTransmission();
#ifdef DEBUG
Serial.print("Number of Bytes to send to I2C #5 = ");
Serial.println(bytesFromMasterToSlave);
#endif
randomSeed(analogRead(0));
// checking if EEPROM has been previously written to and all
// the variables have been set
for(int i = 0; i < 7; i++)
if(EEPROM.read(i) == 255)
EEPROMCounter++;
if(EEPROMCounter == 0) // i.e. no 255 values read (non set values)
{
// alarm on or off
if(EEPROM.read(0) == 0) // off
alarmOn = false;
else // on
alarmOn = true;
// alarm time
alarmTime.Hour = EEPROM.read(1);
alarmTime.Minute = EEPROM.read(2);
// number of dawn songs
numberOfDawnSongs = EEPROM.read(3);
// number of dusk songs
numberOfDuskSongs = EEPROM.read(4);
// dawn start up before alarm
startDawnOffset = -1 * EEPROM.read(5);
// dawn simulation length
dawnDimmerLength = EEPROM.read(6);
#ifdef DEBUG
Serial.println("EEPROM values used");
#endif
}
#ifdef DEBUG
if(alarmOn == false)
Serial.println("Alarm off");
else
Serial.println("Alarm on");
Serial.print("Alarm time: ");
Serial.print(alarmTime.Hour);
Serial.print(":");
Serial.println(alarmTime.Minute);
Serial.print("Number of dawn songs = ");
Serial.println(numberOfDawnSongs+1);
Serial.print("Number of dusk songs = ");
Serial.println(numberOfDuskSongs+1);
Serial.print("Dawn start offset = ");
Serial.print(startDawnOffset);
Serial.println(" minutes");
Serial.print("Dawn Dimmer run time = ");
Serial.print(dawnDimmerLength);
Serial.println(" minutes");
#endif
}
void showTimeLED(tmElements_t tm)
{
lc.setDigit(0,0,tm.Hour/10,false);
lc.setDigit(0,1,tm.Hour%10,false);
lc.setDigit(0,2,tm.Minute/10,true);
lc.setDigit(0,3,tm.Minute%10,true);
}