LED matrix - timed interrupts and pattern timing

Hello,

I built a 8x8 LED matrix. Hardware is no issue but I am struggling with some code concepts. I would like to display several patterns. As I understand the recommended way to do that is to use interrupts which control the multiplexing of the rows: Tutorial: Using Timed Interrupts with the Arduino at the example of a 8 x 8 LED Matrix Display - YouTube
This tutorial was very helpful. However they demonstrate this technique with a fixed pattern (the letter "E"), what I do not understand is how you can specify the timing a custom pattern must be shown. E.g: show "E" for five seconds, after that show "A" for three seconds, after that show "B" for four seconds...

Can anybody help me with this and possibly clarify with a simple beginner-friendly code example?

Best regards
C

I strongly recommend that instead of doing software multiplexing, it is better to use suitable hardware like MAX7219 for example. This will make your program much simpler.

The code from the video displays whatever is in "byte pattern[8][8]". You can copy new data into that array whenever you want to change the display.

Note: The "E" macro used to initialize 'pattern' is not a valid way to assign a new value to 'pattern'. You can use byte pattern[8][8] = E; but you can't later say:
pattern = E; because C++ doesn't do array assignment. You can change #define E to const byte E[8][8] = and change:
byte pattern[8][8] = E;
to
byte pattern[8][8];
and in setup initialize it with:
memcpy(pattern, E, sizeof pattern);
Later you can use memcpy(pattern, A, sizeof pattern); to change the display to whatever you put in the A array.

thank you, but what is still unclear to me is how you can set the time a certain letter can be shown. Is a do while loop with a counter the correct approach?
Eg something like: byte pattern[8][8]='content fot letter A'
int counter=0
do...execute interrupt function...counter++ while counter < 10000
byte pattern[8][8]='content fot letter B'
counter = 0
do...execute interrupt function...counter++ while counter < 5000
...

If the matrix is being refreshed by interrupts, you have full control in the loop to change the values in the matrix at will.

Therefore your problem is simply how to make things happen at certain times.

Typically ppl use millis() and expand on the basic concept of "blink without delay"

Read here, maybe something catches your imagination:

HTH

a7

If your code isn't doing anything else you can use delay();

void loop()
{
  memcpy(pattern, E, sizeof pattern);
  delay(5000);
  memcpy(pattern, A, sizeof pattern);
  delay(3000);
  memcpy(pattern, B, sizeof pattern);
  delay(4000);
}
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.