Hi arduinians,
I'm an absolute code-newbie, so i hope you can enlighten me and help me to build better code.
I'm busy programming a clock using:
Arduino Uno
Adafruit RGB LED 16x32 Display
DS1307 RTC
An IR-remote module
The idea is to create a clock with a couple of different faces (ways of displaying time), that i will be able to skip trough (display_mode_next) using an signal interrupt of any remote.
So far i've got 2 different clockfaces programmed
1 that uses a standard display text aproach: matrix.print (now.hour, DEC) etc.
1 that draws rectangles at specific times (now.seconds, now.minute, and now.hour)
So far i'm happy with these clockfaces because they work. Although i realize that my code for these, could probably be a lot simpeler.
The problem i'm having right now is the third clockface:
I would like the sketch to light a specific LED on the matrix for every second, every minute and every hour, but also display the LED's for the seconds and minutes that came before.
So at 1 second my code would be
if ((now.seconds() == 1))
{
matrix.drawPixel(16, 1, matrix.Color333(2, 0, 0));
}
That seems logical, until you realize that at 59 seconds its:
else if ((now.seconds() == 59))
{
matrix.drawPixel(16, 1, matrix.Color333(2, 0, 0));
matrix.drawPixel(17, 1, matrix.Color333(2, 0, 0));
matrix.drawPixel(18, 1, matrix.Color333(2, 0, 0));
matrix.drawPixel(18, 2, matrix.Color333(2, 0, 0));
matrix.drawPixel(19, 2, matrix.Color333(2, 0, 0));
matrix.drawPixel(16, 1, matrix.Color333(2, 0, 0));
matrix.drawPixel(17, 1, matrix.Color333(2, 0, 0));
matrix.drawPixel(18, 1, matrix.Color333(2, 0, 0));
matrix.drawPixel(18, 2, matrix.Color333(2, 0, 0));
matrix.drawPixel(19, 2, matrix.Color333(2, 0, 0));
matrix.drawPixel(19, 3, matrix.Color333(2, 0, 0));
matrix.drawPixel(20, 3, matrix.Color333(2, 0, 0));
matrix.drawPixel(21, 3, matrix.Color333(2, 0, 0));
matrix.drawPixel(21, 4, matrix.Color333(2, 0, 0));
matrix.drawPixel(22, 4, matrix.Color333(2, 0, 0));
matrix.drawPixel(22, 5, matrix.Color333(2, 0, 0));
matrix.drawPixel(23, 5, matrix.Color333(2, 0, 0));
matrix.drawPixel(24, 5, matrix.Color333(2, 0, 0));
matrix.drawPixel(24, 6, matrix.Color333(2, 0, 0));
matrix.drawPixel(25, 7, matrix.Color333(2, 0, 0));
matrix.drawPixel(25, 8, matrix.Color333(2, 0, 0));
matrix.drawPixel(24, 9, matrix.Color333(2, 0, 0));
matrix.drawPixel(24, 10, matrix.Color333(2, 0, 0));
matrix.drawPixel(23, 10, matrix.Color333(2, 0, 0));
matrix.drawPixel(22, 10, matrix.Color333(2, 0, 0));
matrix.drawPixel(22, 11, matrix.Color333(2, 0, 0));
matrix.drawPixel(21, 11, matrix.Color333(2, 0, 0));
matrix.drawPixel(21, 12, matrix.Color333(2, 0, 0));
matrix.drawPixel(20, 12, matrix.Color333(2, 0, 0));
matrix.drawPixel(19, 12, matrix.Color333(2, 0, 0));
matrix.drawPixel(19, 13, matrix.Color333(2, 0, 0));
matrix.drawPixel(18, 13, matrix.Color333(2, 0, 0));
matrix.drawPixel(18, 14, matrix.Color333(2, 0, 0));
matrix.drawPixel(17, 14, matrix.Color333(2, 0, 0));
matrix.drawPixel(16, 14, matrix.Color333(2, 0, 0));
matrix.drawPixel(15, 14, matrix.Color333(2, 0, 0));
matrix.drawPixel(14, 14, matrix.Color333(2, 0, 0));
matrix.drawPixel(13, 14, matrix.Color333(2, 0, 0));
matrix.drawPixel(13, 13, matrix.Color333(2, 0, 0));
matrix.drawPixel(12, 13, matrix.Color333(2, 0, 0));
matrix.drawPixel(12, 12, matrix.Color333(2, 0, 0));
matrix.drawPixel(11, 12, matrix.Color333(2, 0, 0));
matrix.drawPixel(10, 12, matrix.Color333(2, 0, 0));
matrix.drawPixel(10, 11, matrix.Color333(2, 0, 0));
matrix.drawPixel(9, 11, matrix.Color333(2, 0, 0));
matrix.drawPixel(9, 10, matrix.Color333(2, 0, 0));
matrix.drawPixel(8, 10, matrix.Color333(2, 0, 0));
matrix.drawPixel(7, 10, matrix.Color333(2, 0, 0));
matrix.drawPixel(7, 9, matrix.Color333(2, 0, 0));
matrix.drawPixel(6, 8, matrix.Color333(2, 0, 0));
matrix.drawPixel(6, 7, matrix.Color333(2, 0, 0));
matrix.drawPixel(7, 6, matrix.Color333(2, 0, 0));
matrix.drawPixel(7, 5, matrix.Color333(2, 0, 0));
matrix.drawPixel(8, 5, matrix.Color333(2, 0, 0));
matrix.drawPixel(9, 5, matrix.Color333(2, 0, 0));
matrix.drawPixel(9, 4, matrix.Color333(2, 0, 0));
matrix.drawPixel(10, 4, matrix.Color333(2, 0, 0));
matrix.drawPixel(10, 3, matrix.Color333(2, 0, 0));
matrix.drawPixel(11, 3, matrix.Color333(2, 0, 0));
matrix.drawPixel(12, 3, matrix.Color333(2, 0, 0));
matrix.drawPixel(12, 2, matrix.Color333(2, 0, 0));
matrix.drawPixel(13, 2, matrix.Color333(2, 0, 0));
matrix.drawPixel(13, 1, matrix.Color333(2, 0, 0));
matrix.drawPixel(14, 1, matrix.Color333(2, 0, 0));
matrix.drawPixel(15, 1, matrix.Color333(2, 0, 0));
}
Because there are 59 different second states and also 59 different minute states, I'm going to end up with so much lines of code, that my sketch will be completely unreadable and way to big for the upload.
So what i need from you is a logical approach to this problem. I'm just not seeing it, being so new to this. Can i do something with a goto statement or a while loop?
Before someone answers that is illogical to keep drawing all the pixels every second, remember that the remote is used to skip display_modes. When you skip to a displaymode at a specific second all the corresponding LED for that second have to be burning, to be able to read the time correctly (hope this makes sense).
If you need to see my code, i will provide.