I am attempting to control an 8X8 LED Matrix based on inputs. The easiest way I can see to do this is with an 8X8 integer array in which I can control the integers to either be a 0 or a 1. I am using the MAX7219 LED matrix driver. I can send it the entire matrix with the following code segments:
#include <LedControl.h>
int DIN = 12;
int CS = 11;
int CLK = 10;
int fill[8][8] = {
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
};
LedControl lc=LedControl(DIN,CLK,CS,0);
void setup(){
lc.shutdown(0,false);
lc.setIntensity(0,15);
lc.clearDisplay(0);
}
void loop(){
delay(1000);
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
fill[i][j] = 1;
}
}
Print(fill);
delay(1000);
for (int i = 0; i < 8; i++){
for (int j = 0; j < 8; j++){
fill[i][j] = 0;
}
}
Print(fill);
}//End Void Loop
void Print(int a[8][8]){
for (int q = 0; q < 8; q++){
for (int w = 0; w < 8; w++){
if (a[q][w] == 1){
lc.setLed(0,q,w,true);
}
else{
lc.setLed(0,q,w,false);
}
}
}
}
I have had no issues with getting this to work, however, I am not a fan of how when it fills the matrix by setting each LED individually, you can see the sweep of the LEDs as they light up individually across the screen. I would prefer it to be nearly instantaneous.
This code appears to do it instantly, but I am not sure how to control each LED individually based on inputs.
#include <LedControl.h>
int DIN = 12;
int CS = 11;
int CLK = 10;
byte full[8]= {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
byte empty[8]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
LedControl lc=LedControl(DIN,CLK,CS,0);
void setup(){
lc.shutdown(0,false);
lc.setIntensity(0,15);
lc.clearDisplay(0);
}
void loop(){
printByte(full);
delay(1000);
printByte(empty);
delay(1000);
}
void printByte(byte character [])
{
int i = 0;
for(i=0;i<8;i++)
{
lc.setRow(0,i,character[i]);
}
}
So my main questions is: Is there an easy way to control each LED easily (like in the 8X8 matrix in the first code segment) and convert the 8 integers in a row into one byte to print (like in the second code segment)? This way I could run a function to convert the matrix to a series of 8 bytes to send to the matrix.
I am a mechanical engineer, so am not extremely familiar with code. I am trying to learn though!
Thank you in advance for your comments!