Pages: [1] 2   Go Down
Author Topic: Time Alarms Library  (Read 3115 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 : http://www.onlineconversion.com/unix_time.htm

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

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
}
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: March 16, 2010, 03:53:07 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
  }





« Last Edit: March 17, 2010, 05:35:04 am by lukejr » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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);
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 20
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have this..
Code:
/*
 * 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'..
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
Logged

Pages: [1] 2   Go Up
Jump to: