3x3 led matrix

So i made the LED matrix from this blog: LED Matrix and Arduino – basbrun.com.

Here is the code i downloaded from the linked site:

byte leds[9][6] = {{LOW, HIGH, HIGH, HIGH, LOW, LOW},
                  {LOW, HIGH, HIGH, LOW, HIGH, LOW},
                  {LOW, HIGH, HIGH, LOW, LOW, HIGH},
                  {HIGH, LOW, HIGH, HIGH, LOW, LOW},
                  {HIGH, LOW, HIGH, LOW, HIGH, LOW},
                  {HIGH, LOW, HIGH, LOW, LOW, HIGH},
                  {HIGH, HIGH, LOW, HIGH, LOW, LOW},
                  {HIGH, HIGH, LOW, LOW, HIGH, LOW},
                  {HIGH, HIGH, LOW, LOW, LOW, HIGH}
};
byte n[9][9] = {{0,0,0,0,1,0,0,0,0},  // 1
               {1,0,0,0,0,0,0,0,1},  // 2
               {1,0,0,0,1,0,0,0,1},  // 3
               {1,0,1,0,0,0,1,0,1},  // 4
               {1,0,1,0,1,0,1,0,1},  // 5
               {1,0,1,1,0,1,1,0,1},  // 6
               {1,0,1,1,1,1,1,0,1},  // 7
               {1,1,1,1,0,1,1,1,1},  // 8
               {1,1,1,1,1,1,1,1,1}}; // 9
                                  
byte misc[11][9] = {{0,0,0,1,1,0,1,1,0},
                   {1,1,0,1,1,0,0,0,0},
                   {0,1,1,0,1,1,0,0,0},
                   {0,0,0,0,1,1,0,1,1},
                   {1,0,1,0,1,0,1,0,1},
                   {1,0,0,1,0,0,1,0,0},
                   {0,1,0,0,1,0,0,1,0},
                   {0,0,1,0,0,1,0,0,1},
                   {1,1,1,0,0,0,0,0,0},
                   {0,0,0,1,1,1,0,0,0},
                   {0,0,0,0,0,0,1,1,1}
                 };
                 
byte prop[4][9] = {{0,0,0,1,1,1,0,0,0},
                  {0,0,1,0,1,0,1,0,0},
                  {0,1,0,0,1,0,0,1,0},
                  {1,0,0,0,1,0,0,0,1}
                 };
                 
byte raider[4][9] = {{1,0,0,1,0,0,1,0,0},
                     {0,1,0,0,1,0,0,1,0},
                     {0,0,1,0,0,1,0,0,1},
                     {0,1,0,0,1,0,0,1,0},
                     };

void setup()
{ 
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  
  clearLeds(); 
  
  digitalWrite(2, LOW);  
  digitalWrite(5, HIGH); 
  delay(1000);
  digitalWrite(2, HIGH);  
  digitalWrite(5, LOW); 
  delay(1000);
}

void loop()
{
  for( int repeat=0; repeat<10; repeat++)
  {
    for(int i=0; i<4; i++)
    {      
      for(int j=0; j<200; j++)
      {
        printPatern(raider[i]);
      }
    }
  }
  
  for( int repeat=0; repeat<10; repeat++)
  {
    int i = random(11);
    {      
      for(int j=0; j<250; j++)
      {
        printPatern(misc[i]);
      }
    }
  }
  
  for( int repeat=0; repeat<1; repeat++)
  {
    for(int i=0; i<3; i++)
    {
      for(int j=0; j<3; j++)
      {
        clearLeds();
        digitalWrite(i+2, LOW);
        digitalWrite(j+5, HIGH);
        delay(200);
      }
    }
  }
  
  for( int repeat=0; repeat<1; repeat++)
  {
    for(int i=0; i<9; i++)
    {      
      for(int j=0; j<200; j++)
      {
        printPatern(n[i]);
      }
    }
  }
  
  for( int repeat=0; repeat<10; repeat++)
  {
    for(int i=0; i<4; i++)
    {      
      for(int j=0; j<200; j++)
      {
        printPatern(prop[i]);
      }
    }
  }  
}

void clearLeds()
{
  digitalWrite(2, HIGH);  
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);  
  digitalWrite(6, LOW);  
  digitalWrite(7, LOW);
}

void printPatern(byte* number)
{
  for(int i=0; i<9; i++)
  {
    if(number[i] == 1)
    {
      for(int j=0; j<6; j++)
      {
        digitalWrite(j+2, leds[i][j]);        
      }      
    }    

    delayMicroseconds(100);
  }
}

It works as it should, but i have some questions about program (i'm quite new to arduino).

byte leds[9][6]

I don't know what the numbers in [ ] mean and why in some cases there is {LOW, HIGH, HIGH, HIGH, LOW, LOW}
and in other cases {0,0,0,1,1,0,1,1,0}

Could someone please explain this "byte" thing to me :roll_eyes:

Byte means a collection of 8 bits, that is 8 signals that each are either 0/LOW or 1/HIGH.
8 of such signals can be combined to 2^8 == 256 different combinations.
But as usual reality is more complicated than this. There are different conventions on how to interpret these 256 combinatins of bits. These conventions are agreements between people, some of them wearing a tie which can induce a lack of oxygen.

Nevertheless the agreement says that the "c" datatype byte is to be interpreted as values from 0 to 255 inclusive. This what is called an unsigned interpretation. A signed interpretation would mean values from -128 to 127 inclusive. (a char, even this one is 8 bits)

Now enter the world of of logic and boolean algebra (almost the same). In this realm 0, false and LOW are equivalent. So are 1, true and HIGH. So the convention here is that anything outputting a false value outputs a 0 or a LOW value and anything outputting a true value outputs a 1 or a high value. So far so good. the problem is how to interpret values other than 0 or 1.

The convention here is to interpret 0 as false and anything different from 0 as true.

Does this make sense? I hope so, you will see the values 1, HIGH and true being used interchangeably and the same goes for 0, LOW and false.

Thank you, i get this LOW,HIGH,0,1,true,false.

But now into the programming, what is the easiest way to control 3x3 led matrix. I've seen some different ways, but i want to know what way is the most efficient, short and easy.

That would depend on the circuit, whether it is multiplexed or charlieplexed or something else

I don't really know what those 2 things mean, but my circuit looks like that:

EDIT: i looked things up on google and i think my circuit is multiplexed

Hi, i'm quite new to arduino. I know how to make 3x3 led matrix so now I want to know how to program it.

What is the easiest (begginer) and fast way to do it ?

ps: my matrix circuit is multiplexed

Details.
Lacking.

so now I want to know how to program it.

This tells you the basic idea.
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html
Note you need series resistors in each column or row.

So this "walking bit", when you run this code do you see the steps of "walking"

or do you see the whole picture at once ?

You see the whole picture at once (if your loop runs fast enough)

So what does numbers 4 and 9 stands for in the code i gave on the top
byte raider[4][9]
i can see there are 4 lines and 9 states in each line, but why 9 states if there are 3 rows and 3 columns ? and why are there 4 lines?

So what does numbers 4 and 9 stands for in the code i gave on the top

It is the dimension of the array, it reserves memory for the variable.

i can see there are 4 lines and 9 states in each line, but why 9 states if there are 3 rows and 3 columns ?

A 3 by 3 matrix contains 9 LEDs that is where the 9 comes in.
The 4 is four different patterns the code will show.

Thank you, now i get this, but the thing i don't know now is how let say here:

byte prop[4][9] = {{0,0,0,1,1,1,0,0,0},
                  {0,0,1,0,1,0,1,0,0},
                  {0,1,0,0,1,0,0,1,0},
                  {1,0,0,0,1,0,0,0,1}
                 };

the program knows what led has to be 0 or 1.
I know the LEDs are 1-9, but how does the program know that there are pins 2-7 for columns and rows?

but how does the program know that there are pins 2-7 for columns and rows?

Because of this:

  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);

BTW, using 36 bytes to store 5 bytes-worth of data is not a good use of precious resources.

It is not a very good bit of code but it calculates the pin numbers to use. Consider this bit:-

for(int j=0; j<3; j++)
      {
        clearLeds();
        digitalWrite(i+2, LOW);
        digitalWrite(j+5, HIGH);
        delay(200);
      }

It uses a loop from 0 to 2 and calculates the pin to use by adding 2 to the number or 5 to the number.
This is quite shoddy programming but it will work. The proper way to do this would be to use an array indexed on the variable J.

So what should i use for storing that data ?

If a LED can only be on or off (one bit), using a whole byte (eight bits) to represent the same information seems overkill (to me)

ur000s:
So what should i use for storing that data ?

Store it where? It is stored in the code when it runs it is transferred into SRAM memory.

So i didn't really get the answer what is the best/easiest way to control 3x3 matrix. Is the code i gave the one i should use ?
example:

byte prop[4][9] = {{0,0,0,1,1,1,0,0,0},
                  {0,0,1,0,1,0,1,0,0},
                  {0,1,0,0,1,0,0,1,0},
                  {1,0,0,0,1,0,0,0,1}
                 };

Or are there any better and efficient ways to do it?

unsigned int prop[4] = {0x38, 0x54, 0x92, 0x111};

Is more space efficient (8 bytes vs. 36 bytes), but "better" "easier" "more efficient" are all subjective.

Edit: arithmetic ccorrection