Currently working on using an 8x8 LED matrix driven by a MAX7219.
The hook-up (display is mounted 90 degrees counterclockwise, but it doesn't flop around)
What I am doing now is using a WPF app I made to quickly draw the images I want the LED to display and copying/pasting them into my Arduino sketch.
Basically it works.
Here is the code
/*This sketch is partially based on the pdf file that
came with my MAX7219 8x8 LED display which was included
in my 16Hertz brand starter kit off of Amazon. It included
a sketch which demonstrated the display cycling through
numbers 0-9 and letters A-Z without needing a library. Author is unknown
*/
const int CLKpin = 10;
const int CSpin = 9;
const int DINpin = 8;
//int pin1 = A0; //Used with stopPin to stop between frames until button pressed. Currently disabled
const int fps = 175; //The time in ms each frame is displayed
const int numberOfFrames = 40; //***MUST BE SET EQUAL to NUMBER of FRAMES PASTED and MAKE SURE FILM[] HAS SAME NUMBER***
//Here is where to paste info from my C# hexMapper program
unsigned char frame1[] = {0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81};
unsigned char frame2[] = {0x40, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02};
unsigned char frame40[] = {0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E};
// This is where I am wanting to dynamically create the film array size based on numberOfFrames
// and use a for loop to fill the film array with the frames I paste into the sketch before uploading.
// Currently manually adding and deleting frames in the film array as
// numberOfFrames changes, which is tedious
unsigned char *film[] = {frame1, frame2, frame3, frame4, frame5, frame6, frame7, frame8, frame9,
frame10, frame11, frame12, frame13, frame14, frame15, frame16, frame17, frame18, frame19, frame20,
frame21, frame22, frame23, frame24, frame25, frame26, frame27, frame28, frame29, frame30, frame31,
frame32, frame33, frame34, frame35, frame36, frame37, frame38, frame39, frame40
};
void setup() {
pinMode(CLKpin, OUTPUT);
pinMode(CSpin, OUTPUT);
pinMode(DINpin, OUTPUT);
//pinMode(pin1, INPUT); disabled since not attached
//Serial.begin(9600); disabled since not sending data to serial monitor
MatrixStartUp();
}
void loop() {
for (int filmloop = 0; filmloop < numberOfFrames; filmloop++) {
delay(fps);
// while (analogRead(pin1) < 100 ) { } //Button press advances frame
// delay(250);//Comment out these two lines for continous frames or if switch and pins for this are not attached
for (int cell = 1; cell < 9; cell++) {
Matrix(cell, film[filmloop][cell - 1]);
}
}
}
void MatrixData(unsigned char DATA) {
digitalWrite(CSpin, LOW); //Set pin low so data is read
for (int count = 8; count >= 1; count--) {
digitalWrite(CLKpin, LOW); //Set pin low to put into buffer
digitalWrite(DINpin, DATA & 0x80);
DATA = DATA << 1;
digitalWrite(CLKpin, HIGH); //Lock buffer
}
}
void Matrix(unsigned char row, unsigned char column) {
MatrixData(row);
MatrixData(column);
digitalWrite(CSpin, HIGH); //Set pin high to stop data read
}
//On initial power-up, all control registers are reset,
//the display is blanked, and the display is in shutdown mode
//So must set everything needed.
void MatrixStartUp(void) {
Matrix(0x09, 0x00); //disables the internal max7219 decoder so values 0-7(data being sent)can be read
Matrix(0x0A, 0x03); //sets display intensity 1-31
Matrix(0x0B, 0x07); //tells chip the display is 8x8
Matrix(0x0C, 0x01); //sets chip to operating mode
Matrix(0x0F, 0x01); //tests display by lighting all LEDs....oddly this works without VCC and battery GND attached
delay(1000); //Holds test output for one second
Matrix(0x0F, 0x00); //Takes display out of testmode
}
The issue that pops up and what I would like to fix is when I create an animation that is a different frame amount of my previous animation.
What I would like to be able to do is paste in my frames(however many) then change my numOfFrames variable to match and be done.
The problem with that lies here
unsigned char *film[] = {frame1, frame2, frame3, frame4, frame5, frame6, frame7, frame8, frame9,
frame10, frame11, frame12, frame13, frame14, frame15, frame16, frame17, frame18, frame19, frame20,
frame21, frame22, frame23, frame24, frame25, frame26, frame27, frame28, frame29, frame30, frame31,
frame32, frame33, frame34, frame35, frame36, frame37, frame38, frame39, frame40
};
Right now I have to either add or delete members of the film[] as my number of frames changes.
What I would like to do is something like this
unsigned char *film[] = new unsigned char[numOfFrames];
for (int frameToFilm = 0; frameToFilm < numOfFrames; frameToFilm++){
film[frameToFilm] = frame[frameToFilm + 1];
}
But there is lots wrong with that, and I don't know how to fix it.
First I am establishing the array incorrectly.
Second am trying to create a specific variable name (like frame1, frame2 etc) by attaching the current frameToFilm value to the end of frame and I can't seem to make the complier see frame1 == frame[a variable equal to 1]. Just get variable frame is not declared. So how would I attach the for loop value of frameToFilm to end up with frame1, frame2 etc being used?
And since I am here asking stuff anyway....
Anyone know of a way to clear the buffer inside the MAX7219?
Right now I have to write
unsigned char blank[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
to the display to blank the screen.
I tried the sleepmode on it but it still remembers the previous frame it displayed when it wakes up.