Pages: [1]   Go Down
Author Topic: [SOLVED] Clock alarm test/lesson using Timealarms.h, very strange behavior  (Read 371 times)
0 Members and 1 Guest are viewing this topic.
Illinois, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm testing a simple clock with alarm output, based on this post discussing timealarms http://arduino.cc/forum/index.php/topic,37693.0.html .

My question is, when the sketch is uploaded with the current time, the time displayed is not what is hard coded.  For example, using
Code:
setTime(9,07,0,03,22,13);
 results in the correct time, but the date is displayed as 04/06/2014.  Earlier today in the 7 AM hour, the month was 5 and year was 2015.

I do get my expected alarm output at the set time.

Code follows:
Code:
//This sketch  triggers a daily alarm output

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Time.h>
#include <TimeAlarms.h>
LiquidCrystal_I2C lcd(0x27,20,4);

void setup() // the setTime results in  8:56:00  4/06/2014
{
  setTime(8,56,0,3,22,13); // set time to 8:56:00 am Mar 22 2013
  // create the alarms
  Alarm.alarmRepeat(8,45,0, MorningAlarm);  // every morning
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  pinMode(13, OUTPUT);
}

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

// functions to be called when an alarm triggers:
void MorningAlarm(){
  digitalWrite(13, HIGH);  //alarm test output
  delay(5000);
  digitalWrite(13, LOW);  
}

void digitalClockDisplay()
{
char buf[19];
  sprintf(buf, "%02d:%02d:%02d %02d/%02d/%4d", hour(), minute(), second(), month(), day(), year());
  lcd.print(buf);
  lcd.setCursor(0,0);
}  

Any suggestions appreciated.
« Last Edit: March 22, 2013, 10:56:39 am by Ashton » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  setTime(8,56,0,3,22,13); // set time to 8:29:00am Jan 1 2010
No, it doesn't. Comments that are obvious, and wrong, look stupid. I suggest that you get rid of it.

Code:
char buf[19];
  sprintf(buf, "%02d:%02d:%02d %02d/%02d/%4d", hour(), minute(), second(), month(), day(), year());
2+1+2+1+2+1+2+1+2+1+4+1 is not 19. Stuffing 20 characters into a 19 element array will cause problems.
Logged

Illinois, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
No, it doesn't. Comments that are obvious, and wrong, look stupid. I suggest that you get rid of it.
Comments corrected.
Buffer size corrected.

Same results  04/06/2014 from input of  setTime(9,07,0,03,22,13);
« Last Edit: March 22, 2013, 09:37:20 am by Ashton » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hours, minutes, seconds, day, month, year is the order of arguments to set time. Today is 22, 3, 13 in that order.
Logged

Illinois, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Terrific!  Thanks Paul.

That solved it.
Thanks for your time.
Logged

Pages: [1]   Go Up
Jump to: