Go Down

Topic: Who needs a Software Real Time Clock? (Read 12 times) previous topic - next topic


After an absence I got back to this project and this time was able to get it working on a different mac with no problem on arduino 11. It runs for days with no problems. Now I cannot get it to compile on arduino 12 as it consistently is giving stdlib.h errors. I have tried the newest playground files. Anything you could point me to would be appreciated.


Hi hotcarrier, the code in the playground compiles without problem under 0012 on my machine. Have you tried to compile the playground example sketch? If that compiles ok then perhaps post your sketch, it maybe something there causing the problem.

Good Luck!


I am sure that I am doing something dumb here... but I am running into a mental block or some such craziness trying to get the hour component to show up in 12hr increments rather than the 24hr setup.
The Date Time code is working quite well - so I know it is something I am not doing right - I have tried to assign the DateTime.hour like so:

 hours = (DateTime.Hour);
 if (hours > 12) {hours = hours - 12;}

So... I am pretty sure it is something dumb I am doing, but at this point I cant figure it out.

I have the minutes and seconds working well - I am breaking out the tens and ones of each one, and displaying on a 7 segment LED setup.  

Help is greatly appreciated!  :D


Dec 22, 2008, 03:32 pm Last Edit: Dec 22, 2008, 03:34 pm by mem Reason: 1
to convert to 12 hour format you do the following:
between 0000 and 0059, add 12 hours
between 0100 and 1159, straight conversion to AM
between 1200 and 1259, straight conversion to PM
between 1300 and 2359, subtract 12 hours

Here is a function you can put in your sketch that will convert the 24 hour format from the library to 12 hour format

Code: [Select]
byte hours24To12(byte hours){
 if( hours == 0 )
   return 12; // 12 midnight
 else if( hours  > 12)
   return hours - 12 ;
   return hours ;

Determining AM/PM is easier, if the 24 hour value is < 12 its AM , otherwise its PM

I will add these functions to the next release of the library, let me know how you get on.


Dec 22, 2008, 07:43 pm Last Edit: Dec 22, 2008, 08:19 pm by b94cast Reason: 1
Thanks for the code  :)

edit - fixed my code, and it works great now!  :D

Go Up