Pages: [1]
Author Topic: Arduino code for converting RTC time to 12h  (Read 3925 times)
Posts: 2

View Profile Email
« on: August 26, 2013, 09:11:01 PM »

So close to being done my build! The last step is to just convert the time from 24h to 12h format. I'm having problems here though. I pull the time from a breakaway RTC board, which comes back as the now variable. I then try to convert it from 24h to 12h as follows:

if (now.hour() > 12)
  long hours = now.hour()-12;
  Serial.print(now.hour(), DEC);
  long hours = now.hour();

If I try compiling this code, it claims that the 'hours' variable is never established later
(when it is called for at:
int lowerHours = hours % 10;)

I tried putting in a dummy line of:
long hours = 0;
before the if statement just to get it established. This lets the code work and the serial.print output is showing that it's making the right calculation for the time, but the hour is always 0.
Any suggestions?

Figured it out. I needed to just do hours = inside the if after establishing it prior, not long hours =.
« Last Edit: August 28, 2013, 02:40:24 PM by skoba » Logged

Pages: [1]
Jump to: