Indefinite array display on LED matrix

does anyone know how to make a random array display on a led matrix for an indefinite duration using the ledcontrol.h library? i can now only do it for a certain duration and then it changes to another random array.

here is the code i have:

#include <LedControl.h>

int DIN = 12;
int CS = 10;
int CLK = 11;

int Tx[4] = {2,3,3,4};
int Ty[4] = {0,0,1,0};

int Ix[4] = {2,3,4,5};
int Iy[4] = {0,0,0,0};

int Lx[4] = {2,3,4,4};
int Ly[4] = {0,0,0,1};

int Jx[4] = {2,2,3,4};
int Jy[4] = {1,0,0,0};

int Zx[4] = {2,3,3,4};
int Zy[4] = {1,1,0,0};

int Sx[4] = {2,3,3,4};
int Sy[4] = {0,0,1,1};

int Ox[4] = {3,4,3,4};
int Oy[4] = {0,0,1,1};

int x[4];
int y[4];

LedControl lc=LedControl(DIN, CLK, CS,2);

void setup() {
  // put your setup code here, to run once:
  for(int i=0;i<2;i++){
    lc.shutdown(i,false);
    lc.setIntensity(i,8);
    lc.clearDisplay(i);
  }
  randomSeed(analogRead(0));
}  
void loop() {
  // put your main code here, to run repeatedly:
  block();
  for(int i = 0; i < 4; i++) {
      lc.setLed(0, y[i], x[i], true);
    };
    delay(1000);
    for(int i = 0; i < 4; i++) {
      lc.setLed(0, y[i], x[i], false);
    };
    delay(1000);
}

void block() {
  long block = random(1,8);
  if(block == 1) {
    memcpy(x, Tx, 8);
    memcpy(y, Ty, 8);
  } else if(long== 2) {
    memcpy(x, Ix, 8);
    memcpy(y, Iy, 8);
  } else if(long== 3) {
    memcpy(x, Lx, 8);
    memcpy(y, Ly, 8);
  } else if(long== 4) {
    memcpy(x, Jx, 8);
    memcpy(y, Jy, 8);
  } else if(long== 5) {
    memcpy(x, Zx, 8);
    memcpy(y, Zy, 8);
  } else if(long== 6) {
    memcpy(x, Sx, 8);
    memcpy(y, Sy, 8);
  } else if(long== 7) {
    memcpy(x, Ox, 8);
    memcpy(y, Oy, 8);
  }    
}

What is " indefinite duration" ? - random period of time? Or you mean the picture should be shown indefinitely until you give the explicit command to change it?

yes the picture should be shown indefinitely until i give the command to change it

Just use a random number instead of 1000

You should use sizeof instead of hard coding 8. On a 32 bit arduino (MKR, ESP,…) you have 4 bytes for an int.

So you need to add, for example, a button control to the code. And call the block() function only if the button is pressed.

The Arduino button tutorial should be a good start point

so I just have to check if any light on the matrix is on and it should work?

Well you should know if any light is on, your code will have done that.

sorry, I don't understand. Which light?

just any light of the object that i lit on

The answer is even more cryptic…

Explain what are your components and how they are connected and what you try to do.

do yourself a favour and please read How to get the best out of this forum

@koningmidas

What an object, what a light?? In previous messages you did not write anything similar.
Please describe your task in detail, what exactly you are trying to achieve.

A fuzzy description of the task leads to the fact that the helpers wasted their time ...

so i am making tetris. for the hardware, i have an arduino uno, two 8x8 led matrices with max7219chip and a joystick.
now i have the problem that i want to display a random block for a time until i give the code that this is no longer allowed. for now i can display a random block but for a certain duration and then it changes to another block again. would like to know how to solve this because on google i don't really find the solution.

Write your algorithm in very simple steps

select a random number
Use that number to identify an image (explain how)
Display the image
Wait for x seconds (what is x?) or a joystick movement whatever comes first

Sorry, your descpition is still unclear for me, perhaps because my English is not native. I don't see any connection with "light in matrix", mentioned in the post#6
Good luck for your project.

There are tons of examples of Tetris projects with arduino

Here are a few (scroll down also past the tutorial)

https://create.arduino.cc/projecthub/archievkumar19/the-tetris-4de129

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