Reputation: 1
Using the alarm library, I don't get the alarm to work:
#include <Time.h>
#include <TimeAlarms.h>
void setup()
{
Serial.begin(9600);
while (!Serial)
{
;
}
setTime(8,29,0,1,1,10); // set time to 8:29:00am Jan 1 2010
Alarm.timerRepeat(15, Repeats);
}
void Repeats()
{
Serial.print("alarmed timer!");
digitalWrite(10,1);
}
void loop()
{
}
Upvotes: 0
Views: 1768
Reputation: 1
Add Alarm.delay(0); this way your program won't freeze and your alarm will work...
Upvotes: 0
Reputation: 2880
I suppose you are using this library.
If you read in the help, you can see this:
Normal Running Usage
Alarm.delay(milliseconds); Alarms and Timers are only checks and their functions called when you use this delay function. You can pass 0 for minimal delay. This delay should be used instead of the normal Arduino delay(), for timely processing of alarms and timers.
so in order for the alarms to be called, you have to add this:
void loop(){
Alarm.delay(1000); // wait one second between clock display
}
If you prefer to check the alarm faster, you can use a lower delay (e.g. 100). You can also use 0, so the function doesn't block, but it is not mandatory for your application.
By the way, I THINK (so I can be wrong) that the call to setTime
is used just by the other functions, not by the timer. So you can omit it. Moreover you missed the pinmode statement..
In the end.. Try this code and let us know.
#include <Time.h>
#include <TimeAlarms.h>
void setup()
{
Serial.begin(9600);
while (!Serial) ;
pinMode(10, OUTPUT);
Alarm.timerRepeat(15, Repeats);
}
void Repeats()
{
Serial.print("alarmed timer!");
digitalWrite(10,1);
}
void loop()
{
Alarm.delay(500);
}
Upvotes: 2