I'm trying to get my arduino to turn on/off things at a particular time (a light for example) using an external RTC to keep the time. I'm trying to use the Alarms library with the time library but it doesn't seems to work.
Regarding the code below, when it get's to ledAlarm at whatever time i set the alarm at, it doesn't light the LED attached to pin 13.
Do you know what i have to do so i can get my Arduino to turn things on/off at particular times? my Arduino and RTC is working and programmed to the correct time. I just can't get the Alarms to work. :-/
Thanks for you help.
#include <DS1307RTC.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
int ledpin = 13; // pin 13 is assigned to ledpin variable
void setup() {
setSyncProvider(RTC.get); // the function to get the time from the RTC
lcd.begin(8, 2); // set up the LCD's number of rows and columns:
pinMode(ledpin, OUTPUT); // sets pin 13, ledpin as an output
}
void loop()
{
lcd.setCursor(0,0);
digitalClockDisplay();
lcd.setCursor(0,1);
lcd.print("Hello");
Alarm.alarmRepeat(18,0,0, ledAlarm); // calls ledAlarm below at specified time
}
void ledAlarm(){
for (int blinky = 0; blinky < 10; blinky++ ) { // For loop blinks the led on and off 10 times
digitalWrite(ledpin, HIGH); // sets the LED on
Alarm.delay(1000); // waits for a second
digitalWrite(ledpin, LOW); // sets the LED off
Alarm.delay(1000); // waits for a second
}
}
void digitalClockDisplay(){
// digital clock display of the time
lcd.print(hour());
printDigits(minute());
printDigits(second());
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}