Hello all!
EDIT: Solution posted in reply #6. Mystery solved. Many thanks!
I've been swimming around in these forums for a while now learning as I go, but I've recently hit a wall, and I'm hoping someone might be able to help me out or point me in the right direction.
I'm new to coding and programming as of mid-April, and am writing this program in stages, tackling one goal/issue at a time. I've taken several different programs, from different people, and spliced them together to create what you see below. Source links for the original programs are included in the comments.
EDIT: The full program has too many lines of code to include in its entirety, and I know how much everyone loves program snip-its, so I hope that the file I've attached works. The code posted below is the section where I'm having some trouble, for what it's worth.
// Print the time to the seven-segment LED display.
void DisplayTime() {
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
ReadRTCTime(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
hours = hour;
minutes = minute;
seconds = second;
// Show the time on the display by turning it into a numeric value,
// like 3:30 turns into 330, by multiplying the hour by 100 and then adding the minutes.
int TimeValue = hours * 100 + minutes;
// Set PM flag. <-- This is the code that is presenting issues/not working properly.
// I'm not sure if maybe I have it in the wrong spot, or if it's conflicting with other code.
if (!TIME_24_HOUR && hours >=12) {
ClockDisplay.writeDigitRaw(2, 0x04);
}
// 24-hour to 12-hour conversion.
if (!TIME_24_HOUR) {
if (hours > 12) { // 00:00 = midnight.
TimeValue -= 1200;
}
else if (hours == 0) { // 12:00 = noon.
TimeValue += 1200;
}
}
// Print the time value to the seven-segment LED display.
ClockDisplay.print(TimeValue, DEC);
// Add zero padding when in 24-hour mode and it's midnight.
if (TIME_24_HOUR && hours < 10) {
ClockDisplay.writeDigitNum(0, 0); // Pad ten's hour zero.
if (hours == 0) {
ClockDisplay.writeDigitNum(1, 0); // Pad one's hour zero.
}
}
if (TIME_24_HOUR && minutes < 10) {
ClockDisplay.writeDigitNum(3, 0); // Pad ten's minute zero.
}
// Blink the center colon. <-- Not sure if this part is giving issues for the PM flag.
if ((seconds % 2) == 0) {
ClockDisplay.drawColon(true);
}
else if ((seconds % 2) == 1) {
ClockDisplay.drawColon(false);
}
// Now push out to the display the new values that were set above.
ClockDisplay.writeDisplay();
}
What I'm trying to do right now is create a PM flag for the 12-hour setting, which should be pretty simple. I've created a condition for which the LED in question should light only for PM time. The issue I'm having is that when I incorporate this code into the DisplayTime function, the LED (lower left dot) does not light, and nothing else changes.
EDIT: If I place the code in the DisplayTime function, followed by writeDisplay(); to force the code to the display, the center colon flashes as intended while the PM LED flickers on and off seemingly randomly.
EDIT: If I place the code in a different function, the opposite happens, with the PM LED lit correctly and the colon flickering on and off in rhythm.
I think there may be an addressing conflict within the LED display module/backpack, but I a haven't figured it out yet. I'm calling drawColon(true/false); with a set of conditions to trigger the blinking center colon.
I've consulted Adafruit's 1.2" seven-segment display guide and many different sites and forum threads, but I'm clearly missing something. Everything else in this program works perfectly. I've not yet trimmed the fat, so there are most certainly superfluous lines of code here and there. But the program as it exists does everything else that I've wanted it to do up until this point.
I am using an Arduino Nano (running IDE 1.8.9) with Adafruit's DS3231 RTC breakout and 1.2" seven-segment display w/backpack (HT16K33).
This is just a fun exercise for me, and I've been doing a lot of Googling to figure out what I could be missing. Any help would be greatly appreciated!
My apologies for the super long post, and if this is not the appropriate sub-forum (I saw a similar post here before).
- JB
Clock_Version_2.4.ino (12.3 KB)