Go Down

Topic: [SOLVED] Clock alarm test/lesson using Timealarms.h, very strange behavior (Read 496 times) previous topic - next topic

Ashton

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: [Select]
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: [Select]
//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.

PaulS

Code: [Select]
  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: [Select]
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.

Ashton

#2
Mar 22, 2013, 03:29 pm Last Edit: Mar 22, 2013, 03:37 pm by Ashton Reason: 1
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);

PaulS

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

Ashton

Terrific!  Thanks Paul.

That solved it.
Thanks for your time.

Go Up