I've just figured out how to get the RTC to display 12-hour clock instead of 24, but when it comes to displaying PM, it's displaying 87... Google says it's ASCII... 80 for P, 7 for M.
// format a number of minutes into a readable time (24 hr format)
void printMins(int mins, //time in minutes to print
boolean ampm = true //print am/pm?
) {
int hr = (mins % 1440) / 60;
int mn = mins % 60;
if (hr < 10) {
lcd.print(" ");
}
lcd.print(hr);
lcd.print(":");
if (mn < 10) {
lcd.print("0");
}
lcd.print(mn);
}
I see down in the sketch where it displays the time, it uses DEC for decimal, and HEX gives me 57 instead of 87, but what do I specify to display in letters? I could just input the PM manually then.
The issue is that ampm is declared as a byte, but you are assigning it a string ("PM" or "AM"). Since ampm is a single byte, when you try to print it, it prints the ASCII value of the first character.
void loop() {
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
const char* ampm; // Change to a pointer to a string
getDate(&second, &minute, &hour, &m, &dayOfWeek, &dayOfMonth, &month, &year);
oldMinCounter = minCounter;
minCounter = hour * 60 + minute;
if (hour >= 12) {
ampm = "PM";
if (hour > 12) {
hour -= 12;
}
} else {
ampm = "AM";
}
lcd.setCursor(0, 0);
printHMS(hour, minute, second);
lcd.setCursor(9,0);
lcd.print(ampm); // Now prints correctly
}
Changed ampm to const char*:
Previously, ampm was a byte, which caused "PM" to be interpreted as ASCII values.
Now, ampm is a pointer to a string (const char*), which correctly stores "AM" or "PM".
Changed the logic of the am pm process:
For PM Side, hour in only reduced for values grater than 12, that way pm looks like 12, 1 , 2, ...
For am side no changes are done, since 12PM == 0AM the clock displays hour in the following order: 0 , 1, 2, ....
Crap... I completely missed that. I saw the code scroll, and immediately thought that was my initial post with our looking at the avatar. Sorry about that. My way didn't work... fast forwarded to midnight, and still says pm. Will give your suggestion a shot.
Cheers.
Edit: Also, the base for the conversion came from Google AI, I merely tried to work it into someone else's sketch to display am/pm. I didn't write any of it except for trying to patch.
Well it shows AM and PM... but reversed... lol. The clock was at 12:35 AM, or 0035hrs, but it said PM. I then set the clock back to 9:35 PM here on the West Coast, and now it says AM. I guess I could just set it ahead, but the rest of the menu is for setting the timer schedule for an LED lighting fixture, and it's calculated in minutes... ie: 12PM becomes 720 minutes. I can't tell if the menu has updated to 12-hour or still at 24-hour though... something broke, and now the clock is permanently stuck in position, covering over where the timer in the menu should be. I'll work on it tomorrow.
Cheers, and thanks. Greatly appreciated.
Edit: actually, the menu in minutes is only for setting the duration of the lighting fade period, the start and end times are still regular hours and minutes, so it should be ok. I'm probably missing an lcd.clear somewhere. I'll figure it out.
Edit2: Doh! I put the lcd.print(ampm); in the wrong spot. It still displays AM when it's PM, but I can see the menus properly... and they're still at 24-hour clock. I need to set the lcd.print properly for the menus. Easy enough.
OK... I'm an idiot... lol. Set the sketch back to 24-hour, and it's reading 10:00... it should be saying 22:00. I must have messed it up somewhere tonight. At least that's fixed. :-p