We will also need some bitmaps to animate the running figure. We will use static bitmaps stored in program memory. The first frame of the 10-frame animation is:
As can be seen, the bitmap is made up of 0's and 1's; a 1 bit indicates that the corresponding LED will be lit when it is drawn to the dot matrix display. The first two bytes are the width and height of the bitmap in pixels. In this case, the first frame is 16x16 pixels. Other frames in the animation are 18x16 and 13x16.
#include <DMD.h>
byte const run1[] PROGMEM = {
16, 16,
B00000000, B00001100,
B00000000, B00011110,
B00000111, B11111110,
B00001111, B11111110,
B00011100, B11111100,
B00000001, B11111100,
B00000001, B11110000,
B00000011, B11111000,
B00000111, B00011000,
B00001110, B01110000,
B00011100, B01100000,
B00111000, B00000000,
B01110000, B00000000,
B01100000, B00000000,
B01000000, B00000000,
B00000000, B00000000
};
byte const run2[] PROGMEM = {
18, 16,
B00000000, B01110011, B10000000,
B00000000, B11111111, B10000000,
B00000000, B00011111, B10000000,
B00000000, B00111111, B11000000,
B00000000, B01111011, B11000000,
B00000000, B11110011, B10000000,
B00000001, B11100000, B00000000,
B00000011, B11100000, B00000000,
B00000111, B01110000, B00000000,
B01111110, B00111000, B00000000,
B11111100, B00011100, B00000000,
B00000000, B00001110, B00000000,
B00000000, B00000111, B00000000,
B00000000, B00000011, B10000000,
B00000000, B00000001, B00000000,
B00000000, B00000000, B00000000
};
byte const run3[] PROGMEM = {
18, 16,
B00000000, B00110000, B00000000,
B00000000, B01111000, B00000000,
B00000000, B00011111, B00000000,
B00000000, B00011111, B00000000,
B00000000, B00111111, B10000000,
B00000000, B01111111, B11000000,
B00000000, B11100011, B10000000,
B00000001, B11000000, B00000000,
B00000011, B11100000, B00000000,
B11111111, B01110000, B00000000,
B11111110, B00111000, B00000000,
B00000000, B00011000, B00000000,
B00000000, B00011100, B00000000,
B00000000, B00001110, B00000000,
B00000000, B00000100, B00000000,
B00000000, B00000000, B00000000
};
byte const run4[] PROGMEM = {
16, 16,
B00000001, B11100000,
B00000011, B11111100,
B00000000, B00111110,
B00000000, B01111110,
B00000000, B11111100,
B00000001, B10011111,
B00000011, B00001110,
B00000011, B00000000,
B00000011, B10000000,
B11111111, B10000000,
B11111000, B11000000,
B00000001, B11000000,
B00000011, B10000000,
B00000111, B00000000,
B00000110, B00000000,
B00000100, B00000000
};
byte const run5[] PROGMEM = {
13, 16,
B00000000, B00000000,
B00000000, B00110000,
B00000111, B11111000,
B00000111, B11111000,
B00000111, B11110000,
B00001111, B11100000,
B00000111, B00000000,
B00001111, B00000000,
B00001111, B00000000,
B00001111, B10000000,
B00011100, B00000000,
B00111000, B00000000,
B01110000, B00000000,
B11100000, B00000000,
B11000000, B00000000,
B10000000, B00000000
};
byte const run6[] PROGMEM = {
16, 16,
B00000000, B00000000,
B00000000, B00011100,
B00000000, B00111110,
B00000001, B11111110,
B00000000, B11100000,
B00000001, B11100000,
B00000001, B11111000,
B00000011, B00011100,
B00000110, B00111000,
B00000110, B01110000,
B00001100, B00100000,
B00111000, B00000000,
B01100000, B00000000,
B11000000, B00000000,
B10000000, B00000000,
B10000000, B00000000
};
byte const run7[] PROGMEM = {
18, 16,
B00000000, B00000011, B10000000,
B00000000, B01111011, B10000000,
B00000000, B01111111, B10000000,
B00000000, B00001111, B00100000,
B00000000, B00011001, B11000000,
B00000000, B00110000, B11000000,
B00000000, B01110000, B00000000,
B00000001, B11110000, B00000000,
B11111111, B10111000, B00000000,
B11111111, B00011100, B00000000,
B00000000, B00001110, B00000000,
B00000000, B00000111, B00000000,
B00000000, B00000011, B10000000,
B00000000, B00000001, B11000000,
B00000000, B00000000, B01000000,
B00000000, B00000000, B00000000
};
byte const run8[] PROGMEM = {
18, 16,
B00000000, B00000110, B00000000,
B00000001, B11101111, B00000000,
B00000001, B11111111, B00000000,
B00000000, B00111110, B00000000,
B00000000, B01111111, B11000000,
B00000000, B11100011, B10000000,
B00000001, B11000000, B00000000,
B00000011, B11100000, B00000000,
B11111111, B01110000, B00000000,
B11111110, B00111000, B00000000,
B00000000, B00011100, B00000000,
B00000000, B00000110, B00000000,
B00000000, B00000110, B00000000,
B00000000, B00000111, B00000000,
B00000000, B00000011, B00000000,
B00000000, B00000001, B00000000
};
byte const run9[] PROGMEM = {
16, 16,
B00000000, B00000000,
B00000000, B01001110,
B00000001, B11101110,
B00000011, B11111110,
B00000011, B11111110,
B00000001, B10111100,
B00000011, B00000000,
B00000111, B00000000,
B11111111, B10000000,
B11111100, B11000000,
B00000000, B11000000,
B00000000, B11000000,
B00000000, B11000000,
B00000000, B11000000,
B00000000, B11000000,
B00000000, B11000000
};
byte const run10[] PROGMEM = {
13, 16,
B00000000, B00000000,
B00000000, B00110000,
B00000000, B01111000,
B00000111, B11111000,
B00001111, B11111000,
B00000111, B11000000,
B00001110, B00000000,
B00001100, B00000000,
B00001100, B00000000,
B01111100, B00000000,
B11111100, B00000000,
B00011000, B00000000,
B00110000, B00000000,
B01110000, B00000000,
B01100000, B00000000,
B01000000, B00000000
};
run1,
run2,
run3,
run4,
run5,
run6,
run7,
run8,
run9,
run10
};
#define NUM_FRAMES (sizeof(frames) / sizeof(frames[0]))
unsigned int frame = 0;
#define ADVANCE_MS (1000 / NUM_FRAMES)
unsigned long lastFrame;
void setup() {
lastFrame = millis() - ADVANCE_MS;
}
void loop() {
if ((millis() - lastFrame) >= ADVANCE_MS) {
int x = (32 - pgm_read_byte(frames[frame])) / 2;
lastFrame += ADVANCE_MS;
frame = (frame + 1) % NUM_FRAMES;
}
}