Looking for logic -- Programming a LED-MATRIX-display Clock -->

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.

You can use arrays and loops:

byte minuteRow[] = {16,17,18,18,19,16,17,18,,18,19,19...};
byte minuteColumn[] = {1,1,1,2,2,1,1,1,2,2,3...};
.
.
.
for (minute=0; minute<now.minute()+1; minute++) {
    matrix.drawPixel(minuteRow[minute], minuteColumn[minute], matrix.Color333(2, 0, 0)); 
}

I have no idea how the output should look like. I also don't understand why your code sets some pixels twice, and never turns pixels off (same colour used everywhere).

When you write a subroutine that sets a pixel, your code will shrink to lines like this
drawPixel(16, 1);

Of course you can use loops to display data from an array. You also can add further subroutines that e.g. draw a straight line, from a starting point (pixel) to an end point.

You also can clear the display whenever the display mode changes, then output whatever pixels should be on.

Thanx for responding.

Lets see if i comprehend this:

byte minuteRow[] = {16,17,18,18,19,16,17,18,,18,19,19...};

Here I create a byte and fill this container and specify the all numbers used on the X-Axis of the display? Correct?

byte minuteColumn[] = {1,1,1,2,2,1,1,1,2,2,3...};

Here it's the same but for the y-axis? Right?

for (minute=0; minute<now.minute()+1; minute++) {
** matrix.drawPixel(minuteRow[minute], minuteColumn[minute], matrix.Color333(2, 0, 0));**
}

This is a bit difficult to understand. Lets see.
Here i create a minute state (minute=0;)? Shouldn't i specify this earlier?
This is compared (is this number smaller>) to now.minute.
Then one (+1) is added to able to skip trough the numbers in the container?
Then once again a number is added with ++?

Then i understand that the pixels are drawn from the filled container/array on the correct x and y axis....

I'm starting to grasp it a bit, but i don't understand where that minute (minute=0;) state came from.

Okay, conclusion:
back to school for me. I'll go and do a quick course/refresher at code-academy on arrays & loops.

Thanks for you logic

You have a list of row coordinates and a list of column coordinates. Together they form a list of the LEDs in the order you want them to illuminate. The loop starts with the first LED (minute=0) and illuminates successive LED's until the number of LEDs represents the current minute. Perhaps I was wrong to add 1 to the upper limit... Do you illumunate the first LED for minute 0 or for minute 1? The arrays all start with index 0. The minute++ does the counting.

termijt:
If you need to see my code, i will provide.

Please provide it.

Hi,

Why have we got two threads running about the same project?

Tom.... :slight_smile: