I recently bought a Uno R4 and having quite a fun time learning C++ programming for it. I have a few questions about arrays and how to use them correctly...or most efficiently. And a general problem question or 2.
Some background...
I have max7200 LED matrix board with 4 modules for a total of 256 LED's. I ran the max7200 example 'Hardware Mapper" program and it reported I had an ICStation module.
I also found an open source software called LED Matrix Studio which I used to design my animation.
I designed a simple little eye wink animation in Matrix Studio. I did so with a setting of 32x8 since that's what my module is. It gave me the following array code. I had 4 steps in the array to show the eye closing. I'm only posting 1 for simplicity....
0x00, 0x70, 0x0E, 0x00, 0x00, 0x88, 0x11, 0x00, 0x01, 0x24, 0x24, 0x80, 0x02, 0x72, 0x4E, 0x40, 0x02, 0x72, 0x4E, 0x40, 0x01, 0x24, 0x24, 0x80, 0x00, 0x88, 0x11, 0x00, 0x00, 0x70, 0x0E, 0x00 // 1
So when I plugged all 32 of those values into the array like this...
byte winkLFrame1[32] = { 0x00, 0x70, 0x0E, 0x00, 0x00, 0x88, 0x11, 0x00, 0x01, 0x24, 0x24, 0x80, 0x02, 0x72, 0x4E, 0x40, 0x02, 0x72, 0x4E, 0x40, 0x01, 0x24, 0x24, 0x80, 0x00, 0x88, 0x11, 0x00, 0x00, 0x70, 0x0E, 0x00 }; // Left eye frame 1
and set up the for loop to go through all 32 parts of the array line it didn't work right. So I did a new design using an 8x8 setting in Matrix Studio and that worked. Here is my working code. I'm not sure why it wouldn't work with the 32 byte long array lines. It would have been much easier. Could anyone point me to where I might have went wrong? Also looking at my code can I get some pointers as to a better way to do those arrays? Is it better to put them in a .h file? My end goal is it have several animations and you press a different button on the breadboard to fire off a particular animation. So that'll be a lot of lines of array code in my main program. I don't know if it would be that big a deal with the R4 since it has so much more memory, but I'd like to learn good habits now instead of trying to break bad ones later.
Sorry for the long post. Just hoping to cram as much learning into one post as I can
#include <MD_MAX72xx.h>
#include <SPI.h>
#define delay_blink 75 // how long to wait between steps in the wink animation
#define delay_look 75 // how long to wait between steps in the look animation
#define delay_betweenAni 1000 // how long to wait between animation sets
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
// CLK Pin > 13 CLK
// Data Pin > 11 DIN
// CS Pin > 10 CS
#define CS_PIN 10
// Hardware SPI connection
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Left eye wink animation
byte winkLFrame1[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 }; // Left eye frame 1
byte winkLFrame2[8] = { 0x00, 0x3C, 0x42, 0x99, 0x99, 0x42, 0x3C, 0x00 }; // Left eye frame 2
byte winkLFrame3[8] = { 0x00, 0x00, 0x7E, 0x99, 0x99, 0x7E, 0x00, 0x00 }; // Left eye frame 3
byte winkLFrame4[8] = { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00 }; // Left eye frame 4
byte winkLFrame5[8] = { 0x00, 0x00, 0x7E, 0x99, 0x99, 0x7E, 0x00, 0x00 }; // Left eye frame 5
byte winkLFrame6[8] = { 0x00, 0x3C, 0x42, 0x99, 0x99, 0x42, 0x3C, 0x00 }; // Left eye frame 6
byte winkLFrame7[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 }; // Left eye frame 7
// Right eye doesn't blink
byte winkRFrame1[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 };
byte winkRFrame2[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 };
byte winkRFrame3[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 };
byte winkRFrame4[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 };
byte winkRFrame5[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 };
byte winkRFrame6[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 };
byte winkRFrame7[8] = { 0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18 };
void setup() {
mx.begin();
mx.control(MD_MAX72XX::INTENSITY, 3);
mx.clear();
}
void loop() {
drawWink();
delay(delay_betweenAni);
}
// Wink animation
void drawWink() {
for (int i = 0; i <= 8; i++) {
mx.setRow(1, 1, i, winkLFrame1[i]);
mx.setRow(2, 2, i, winkRFrame1[i]);
}
delay(delay_blink);
for (int i = 0; i <= 8; i++) {
mx.setRow(1, 1, i, winkLFrame2[i]);
mx.setRow(2, 2, i, winkRFrame2[i]);
}
delay(delay_blink);
for (int i = 0; i <= 8; i++) {
mx.setRow(1, 1, i, winkLFrame3[i]);
mx.setRow(2, 2, i, winkRFrame3[i]);
}
delay(delay_blink);
for (int i = 0; i <= 8; i++) {
mx.setRow(1, 1, i, winkLFrame4[i]);
mx.setRow(2, 2, i, winkRFrame4[i]);
}
delay(1000);
for (int i = 0; i <= 8; i++) {
mx.setRow(1, 1, i, winkLFrame5[i]);
mx.setRow(2, 2, i, winkRFrame5[i]);
}
delay(delay_blink);
for (int i = 0; i <= 8; i++) {
mx.setRow(1, 1, i, winkLFrame6[i]);
mx.setRow(2, 2, i, winkRFrame6[i]);
}
delay(delay_blink);
for (int i = 0; i <= 8; i++) {
mx.setRow(1, 1, i, winkLFrame7[i]);
mx.setRow(2, 2, i, winkRFrame7[i]);
}
delay(delay_blink);
}