element14 and Arduino were kind enough to send me the new Arduino Uno R4 WiFi and an R4 Minima to try out. I have a 12 year old grandson who is interested in computers and plan to introduce him to Arduino this summer. He is already knowledgable about Scratch and has used it with Lego and to animate short cartoons. Since one of his main interest in computers is games, animation with the Arduino seemed a good place to start.
The Uno R4 WiFi has a 12 column x 8 row LED matrix on the board.
There is an Arduino example and an online link to a web page that generated images but I felt it abstracted too much away and he wouldn't learn any more than what he would using Scratch. To gain more understanding I created a spreadsheet array with 12 columns and 8 rows as follows:
To start, the cells are full of zeros - equivalent to all the LEDs off. To turn on a cell, enter a one. The spreadsheet has conditional formatting to turn the cell red when a one is entered. This allows simple images to be quickly created. To show how the data is stored in memory a second array is used as follows:
The data is stored in three 32-bit unsigned integers as shown in the blue, yellow, and green outlined areas. The cells correspond to individual bits. It would be possible to enter binary numbers directly off of the first array but real nerds use hexadecimal notation. So multiply the ones and zeros in the first array by the corresponding binary bit value in the second array to get the following:
Now if we add the numbers in the shaded areas up we get the base 10 value of the three unsigned integers and it can be converted to hex if desired as shown in the outlined boxes:
But what about animation? Just duplicate the arrays down the page and cut and paste the desired areas into new areas in zeroed out areas kind of like moving a sprite as shown below. The values for the next frame are auto-magically calculated.
Now we have all the values necessary to create an animation. Arduino provides a library for displaying animations but it wouldn't be hard to create one if I could be bothered to look up where the memory locations of the LEDs are. For now I will use the library. The animation code is all in setup with the loop empty as shown below:
#include "Arduino_LED_Matrix.h"
#include "animation.h"
ArduinoLEDMatrix matrix;
void setup() {
Serial.begin(115200);
matrix.loadSequence(animation);
matrix.begin();
matrix.play(true);
}
void loop() {
}
The data for the animation which was developed in the spreadsheet is stored as C arrays in animation.h. The fourth integer is in the time in milliseconds before moving to the next frame.
const uint32_t animation[][4] = {
{ //13
0x0,
0x0,
0x0,
100
},
{ //12
0x0,
0x10010010,
0x1001000,
100
},
{ //11
0x100,
0x20020030,
0x2002001,
100
},
{ //10
0x300,
0x40040070,
0x4004003,
100
},
{ //9
0x600,
0x900900F0,
0x8009006,
100
},
{ //8
0xC01,
0x201201E0,
0x1001200C,
100
},
{ //7
0x101902,
0x502503D0,
0x21025019,
100
},
{ //6
0x203204,
0xA04A07A0,
0x4204A032,
100
},
{ //5
0x506509,
0x50950F40,
0x84094064,
100
},
{//4
0xA0CA12,
0xA12B1E81,
0x81280C8,
100
},
{ //3
0x1519525,
0x52573D12,
0x11251191,
100
},
{ //2
0x2A32A4A,
0xA4AF7A24,
0x224A2322,
100
},
{ //1
0x2A32A4A,
0xA4AF7A24,
0x224A2322,
100
},
{ //0
0x5465495,
0x495EF448,
0x44944644,
10000
}
};
And here you have it:
It is a fun little board. The Qwiic connector will make it easy to use some of the breakout boards I have on hand and it has the memory, speed, and WiFi to power the little robots I often make. Thanks for reading and comments are always welcome.
Top Comments