My Teensy alarm clock

bigpilot

Well-known member
DSCN0632.jpg

It has one feature which I'm still missing on most if not all stand alone clocks and alarm clocks: automatic daylight savings time adjustment. I'm doing this without radio-adjustment or a connection to the Internet.

There's currently no 'snooze' function implemented, but I've got a big red button somewhere if I feel the need in the future ;)

I wrote the C code all by myself, including the HD44780 device driver.

I can post the code and schematics if people are interested.
 
Last edited:
I can post C code and schematics if people are interested

Sure ... post it.:D

automatic daylight savings time adjustment

What you need to do is collect, from the internet, the projected bi-yearly dates for the daylight
savings time adjustment. (10 years worth) Install these date values in a table and read it to see if
you need to add 1 hour or substract 1 hour to the RTC. (Spring forward or fall back) :cool:
 
View attachment Alarm Clock.zip

Here's the source code, including the Make file.

NOTE: updated the zip file to fix some bugs. The alarm wouldn't sound if the alarm time was exactly on the hour. Also I fixed the bugs with the leap year and the days in the month as discussed in the posts below.

NOTE: Updated the source code again to fix the DST because when the clock is set backwards the routine keeps being called so it gets stuck between 01:00 and 02:00. I made the check daily to resolve this issue.
 
Last edited:
What you need to do is collect, from the internet, the projected bi-yearly dates for the daylight
savings time adjustment. (10 years worth) Install these date values in a table and read it to see if
you need to add 1 hour or substract 1 hour to the RTC. (Spring forward or fall back) :cool:

No, I'm computing it from rules. Look at the function CompensateForDaylightSavingsTime() in my code.
 
No, I'm computing it from rules. Look at the function CompensateForDaylightSavingsTime() in my code. .

Cool, shorter way of doing it. You show October in your rules? You must not be in the USA?

void CompensateForDaylightSavingsTime( void )
{
if ( timedate.month == MARCH && timedate.date == GetDateOfLastSundayOfTheMonth( MARCH ) && timedate.hour == 2 )
{
timedate.hour = 3;
}

if ( timedate.month == OCTOBER && timedate.date == GetDateOfLastSundayOfTheMonth( OCTOBER ) && timedate.hour == 2 )
{
timedate.hour = 1;
}
}

DST Rule <----- For US citizens
Starts: Second Sunday in March
Ends: First Sunday in November
Time: 2 am local time

BTW ... not to nick-pick but just being helpful ...

Thirty days hath September,
April, June, and November;
Thirty-one the others date,
Except in February, twenty-eight;
But in leap year we assign
February, twenty-nine.

Jan should be 31 ?

const char days_in_month[] = {30, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
Last edited:
You're right. The days_in_months array should be:

Code:
const char days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

and the leap year compensation should be:

Code:
  if ( IsLeapYear() && month == FEBRUARY )
  {
    return 29;
  }

Thanks for your observation.
 
So you are saying that your auto DST algorithm will not work for US citizens because it is made for a different country DST?
 
So you are saying that your auto DST algorithm will not work for US citizens because it is made for a different country DST?

That is correct. I originally wanted to make it a menu option so you could select between different countries, but haven't implemented it (yet).
 
So you are saying that your auto DST algorithm will not work for US citizens because it is made for a different country DST?
Or to put it another way, most European countries and the USA changed on the same dates for a few years, then the US went its own way with a different formula.
 
then the US went its own way with a different formula.
They did to "save more energy" and to prevent school children from being run over, due to darkness, going to school as the story goes.

BTW ... cool "Teensy 2" project.

Below ... Untested auto DST code patch for Yankees - US citizens.

Untested auto DST code patch for Yankees - US citizens.


/*
DST Rule <----- For US citizens
Starts: Second Sunday in March
Ends: First Sunday in November
Time: 2 am local time
*/




void CompensateForDaylightSavingsTime( void ) // patch for Yankees

{
if ( timedate.month == MARCH && timedate.date == GetDateOfSecondSundayOfTheMonth( MARCH ) && timedate.hour == 2 ) // spring forward
{
timedate.hour = 3; //
}

if ( timedate.month == NOVEMBER && timedate.date == GetDateOfFirstSundayOfTheMonth( NOVEMBER ) && timedate.hour == 2 ) // fall back
{
timedate.hour = 1; // <------<<<< needs lockout flag to prevent multiple updates
}

}


int GetDateOfSecondSundayOfTheMonth( int month ) // spring forward - 2nd sunday
{
int date = 1;

while ( DayOfWeek( timedate.year, month, date ) != SUNDAY )
{
date++;
}

date++;

while ( DayOfWeek( timedate.year, month, date ) != SUNDAY )
{
date++;
}

return date;
}


int GetDateOfFirstSundayOfTheMonth( int month ) // fall back - 1st sunday
{

int date = 1;

while ( DayOfWeek( timedate.year, month, date ) != SUNDAY )
{
date++;
}

return date;
}
 
Last edited:
I've used a power measuring wall wart to test the power consumption and it uses 4W continuously. That's probably because I'm not using interrupts for the keys or sleep mode.

I'm keeping the power consumption down by keeping the input voltage at the lowest possible level (7.5V) to minimize the voltage drop across the voltage regulator.
 
Last edited:
Back
Top