Time Alarms Library

I've used the example sketch from the time alarms library just to set a led to stay on at a certain time of day using the 'alarmrepeat function'..

Currently, and in the examples, it's only accurate to one day. Is it possible to include a date value in the alarm...???

I originally tried the 'onceoff' alarm function, but I could only set an alarm after a certain amount of seconds...

you can give it a time and day of week for a once only or a repeat alarm.

If you want to give it a specfic day you need to pass the date and time as a time_t. The easist way to convert a date to time_t is to use an online utility such as : Online Conversion - Unix time conversion

enter the date and time and copy the unix timestamp into a the alarm function call
timerOnce(1293278400, AlarmHandler); // set alarm for christmas day 2010

thanks..

I'm going to set it to a particular day of the week, at a specific time..

I have this...

Alarm.alarmRepeat(7,00,00,MorningAlarm); // seven pm

}

void MorningAlarm()
{
Serial.println("Alarm: - Seven");
digitalWrite (ledPin, HIGH);
delay(300000);
digitalWrite (ledPin, LOW);
}

How would I add a day to that alarm repeat function...?

thank you.

to set an alarm to repeat every Tuesday at 7 am:

Alarm.alarmRepeat(dowTuesday,7,00,00,MorningAlarm); // every Tuesday seven am

the names of the days of the week are defined in Time.h :
dowSunday, dowMonday, dowTuesday, dowWednesday, dowThursday, dowFriday, dowSaturday

thank you... that's all working now..
but, the last part is being more difficult than i thought..

I have this..

void loop()

{val = digitalRead(buttonPin);
digitalWrite(releasePin, val);
delay(120000);
digitalWrite(releasePin, LOW);
delay(100);
}

{
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}

and get this error:

error: expected unqualified-id before '{' token

in relation to the bracket before digital clock display...

the original code (from the example), which works fine, only had this:

void loop()
{
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}

Your code to display the clock is not in a function. If you are new to programming, try going through some of the tutorials that show how to use functions in a sketch.

It may be easier to start with blinking LEDs and move to external libraries when you are comfortable creating your own functions.

have fun!

i wouldn’t be trying this at all… it’s just been a long while since i have and i’m trying to get something done this week…

i was confused because in the second example without the button value, the code works fine… the problem only appears when i add the extra part to read the button pin…

thankyou again

Perhaps you didn't post all the code but what you did post will have errors because the block of code is not within a function.

If you think the compiler errors relate to the TimeAlarms functionality then please post your entire sketch

Well, here is the original code, which is working fine as is:

/*

  • TimeAlarmExample.pde
    */

#include <Time.h>
#include <TimeAlarms.h>

int solenoidPin = 13;
int releasePin = 10;
int buttonPin = 2;

int val = 0;

void setup()
{
Serial.begin(9600);
Serial.println("ANNIVERSARY ALARM - 7:50 3/23/2010 - STARTUP TIME = ");
Serial.println();

setTime(6,50,00,3,16,10); // set time to 6:50:00am March 16 2010

Alarm.alarmRepeat(7,00,00,EveningAlarm); // Seven Am

pinMode(buttonPin, INPUT);

}

void EveningAlarm()
{
Serial.println(“Alarm: - Seven AM”);
digitalWrite (solenoidPin, HIGH);
delay(3000);
digitalWrite (solenoidPin, LOW);
}

void loop()

{digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}

void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}

void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}

So, I suppose, how do I properly add this piece below, it’s just to run separately to the actual alarm, in order to operate the ‘release pin’ when the buttons pressed…

{val = digitalRead(buttonPin);
digitalWrite(releasePin, val);
delay(120000);
digitalWrite(releasePin, LOW);
delay(100);
}

You would put the code to read the buttons in loop.

If you don’t want the 1 second delay between button checks but still want the clock to display every second you can do something like this in loop:

unsigned long  prevtime;
  
void loop()
{
  if( prevtime < now() ){
   // has the clock time advanced?
    prevtime = now();
    digitalClockDisplay();  
  }
  boolean buttonState = digitalRead(buttonPin); 
  if (buttonState == HIGH) {     
   // turn LED on:    
   digitalWrite(ledPin, HIGH);  
  } 
  else {
   // turn LED off:
   digitalWrite(ledPin, LOW); 
 }
 Alarm.delay(100); 
}

thanks so much… i just breadboarded it and it’s working… although now when i try the day of week the alarm doesn’t set…

does it have something to do with the start time and alarm time being so close…?

/*

  • TimeAlarmExample.pde
    */

#include <Time.h>
#include <TimeAlarms.h>

int solenoidPin = 13;
int buttonPin = 3;

int buttonState = 0;

void setup()

{
Serial.begin(9600);
Serial.println("ANNIVERSARY ALARM - 6:50am 3/23/2010 - STARTUP TIME = ");
Serial.println();

setTime(6,49,55,3,23,10); // set time to 6:49:00AM, March 23 2010

Alarm.alarmRepeat(dowTuesday,6,50,00,MorningAlarm); // Tuesday, 6:50:00 AM
}

void MorningAlarm()

{
Serial.println(“Alarm: - Six Fifty - Anniversary”);
digitalWrite (solenoidPin, HIGH);
delay(4000); // Fifteen Minutes to open, examine and close the box
digitalWrite (solenoidPin, LOW);
}

unsigned long prevtime;

void loop()
{
if( prevtime < now() ){
// has the clock time advanced?
prevtime = now();
digitalClockDisplay();
}
boolean buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(solenoidPin, HIGH);
delay(4000);
digitalWrite(solenoidPin, LOW);
}
else {
// turn LED off:
digitalWrite(solenoidPin, LOW);
}
Alarm.delay(100);
}

void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}

void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}

I am traveling so its difficult for me to try your code.

try changing the loop code back and see if that gets it going.

Also, its easier to read your code if you put it in a code block - use the icon in the edit menu with the # (pound sign)

I’ve tried a few different things, and comparing changes to the timealarms example program…

It seems that the date of week section only functions when I don’t make significant changes to the code, ie: if I took out the serial print text from the start, the dow function won’t work…

I have this…

/*
 * TimeAlarmExample.pde
 */

#include <Time.h>
#include <TimeAlarms.h>

int solenoidPin = 6;
int buttonPin = 10;

int buttonState = 0;  

void setup()

{
  Serial.begin(9600);    
 Serial.println("ANNIVERSARY ALARM - 6:50am 3/23/2010 - STARTUP TIME = ");
  Serial.println();
  
  setTime(6,49,58,3,18,10); // set time to 10:53:00PM, March 17 2010 

  
  Alarm.alarmRepeat(dowThursday,6,50,0,MorningAlarm);  //  6:50:00 AM 
}


void MorningAlarm()

{
  Serial.println("Alarm: - Six Fifty - Anniversary");
  digitalWrite (solenoidPin, HIGH);  
  delay(900000);                    // Fifteen Minutes to open, examine and close the box
  digitalWrite (solenoidPin, LOW);
}


unsigned long  prevtime;

void loop()
{
  if( prevtime < now() ){
   // has the clock time advanced?
    prevtime = now();
    digitalClockDisplay();
  }
  boolean buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
   // turn LED on:
   digitalWrite(solenoidPin, HIGH);
   delay(10000);
   digitalWrite(solenoidPin, LOW);
  }
  else {
   // turn LED off:
   digitalWrite(solenoidPin, LOW);
 }
 Alarm.delay(100);
} 


void digitalClockDisplay()
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.println(); 
}

void printDigits(int digits)
{
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

Which works when I take out the ‘dowThursday’…

are you using the latest download from the playground?

If you are and still have a problem, here is a work-around that you can try

void MorningAlarm()

{
  if(dayOfWeek(now()) == dowThursday)
  {
    Serial.println("Alarm: - Six Fifty - Anniversary");
    digitalWrite (solenoidPin, HIGH);
    delay(900000);                    // Fifteen Minutes to open, examine and close the box
    digitalWrite (solenoidPin, LOW);
  }
}

this code uses the daily alarm but only executes the code if the day is tuesday.

It's all working now... thanks for all the help....

i think next time I'll start a little further down..

did you use the latest download or the work-around posted above?

Free Alarm memory.
In order to get only 6 alarms, can we free memory by deleting alarm ?

I have 4 devices to wake up and shut off each days.

So I have 8 alarms at minimum to program.
I know that I can set number to 8 but if I can optimize by removing some alarm or do a fifo-like algorythm... I am interested by any idea.

Can you explain me why this stop the first timer when the second start ?

      Alarm.timerRepeat( 1, FunctionalWrapper::AfficheHeureLnk );
      Alarm.timerRepeat(5, FunctionalWrapper::AfficheDateLnk  );

First func show me the time every seconds. The second func should show Date every 5 seconds.

At 5 seconds after the first call AfficheHeureLnk, it restart the sketch, all setup etc...

Hi epanda

In order to get only 6 alarms, can we free memory by deleting alarm ?
No, alarms that repeat are declared statically. You will only use 24 more bytes of RAM to declare 8 alarms (see the readme file distributed with the library for info on how to declare more alarms). If you are short of RAM and don't need all 128 bytes of Serial buffer, you can reduce that buffer by 24 bytes)

Can you explain me why this stop the first timer when the second start ? ?
Not without seeing your code

The first step is for you to see if the problem is caused by something in your AfficheHeureLnk and AfficheDateLnk functions. Try your sketch with using stub functions

Static void AfficheHeureLnk()
{
Serial.println("In AfficheHeureLnk");
}

Static void AfficheDateLnk
{
Serial.println("In AfficheDateLnk");
}

If that works correctly then have close look at the code in your functions.
If that still has a problem then post the sketch.