1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| #include <LedControl.h>
#include <MD_MAX72xx.h>
//There will be 3 states, ONE, TWO, THREE, (+ one default called ZERO), each state is a sprite animation on the 8x8 LedMatrix,
//with the push of a button the states will go from one to an other
//Using a MAX7219
// pin 12 is connected to the DataIn
//pin 11 is connected to the CLK
//pin 10 is connected to LOAD
//pin 2 is connected to switch
#define button 2
LedControl display = LedControl(12, 11, 10, 1);
int state = 0; //integrer to hold current state
int old = 0; //integrer to hold last state
int buttonPoll = 0; //integrer to hold button state
const uint64_t ZERO[] PROGMEM = {
0x3c4281818181423c,
0x003c424242423c00,
0x0000182424180000,
0x0000001818000000,
0x0000182424180000,
0x0018244242241800,
0x003c424242423c00,
0x3c4281818181423c,
0x6681810000818166,
0x8100000000000081,
0x4281000000008142
};
const int ZERO_LEN = sizeof(ZERO) / 8;
const uint64_t ONE[] PROGMEM = {
0x3c4201010101023c,
0x3c0201010101423c,
0x1c0201010181423c,
0x0c0201018181423c,
0x040201818181423c,
0x000281818181423c,
0x004081818181423c,
0x204080818181423c,
0x304080808181423c,
0x384080808081423c,
0x3c4080808080423c,
0x3c4280808080403c,
0x3c42818080804038,
0x3c42818180804030,
0x3c42818181804020,
0x3c42818181814000,
0x3c42818181810200,
0x3c42818181010204,
0x3c4281810101020c,
0x3c4281010101021c
};
const int ONE_LEN = sizeof(ZERO) / 8;
const uint64_t TWO[] PROGMEM = {
0x0c0e0c0800000000,
0x0002070f00000000,
0x000000000f070200,
0x00000000080c0e0c,
0x0000000010307030,
0x00000000f0e04000,
0x0040e0f000000000,
0x3070301000000000
};
const int TWO_LEN = sizeof(ZERO) / 8;
const uint64_t THREE[] PROGMEM = {
0x3c4e8d9999b1723c,
0x3c46879db9e1623c,
0x3c4287bffde1423c,
0x3c4281ffff81423c,
0x3c42e1f99f87423c,
0x3c62f1b99d8f463c,
0x3c72b199998d4e3c,
0x3c5a999999995a3c
};
const int THREE_LEN = sizeof(ZERO) / 8;
void setup() {
pinMode (button, INPUT); //button set as input
display.shutdown(0, false);
/* Set the brightness to a medium values */
display.setIntensity(0, 7);
/* and clear the display */
display.clearDisplay(0);
}
void displayImage(uint64_t image) {
for (int i = 0; i < 8; i++) {
byte row = (image >> i * 8) & 0xFF;
for (int j = 0; j < 8; j++) {
display.setLed(0, i, j, bitRead(row, j));
}
}
}
int i = 0;
void loop() {
//debouncing routine to read button
buttonPoll = digitalRead(button); //poll the state of button
if (buttonPoll == 1) { //check if it has been pressed
delay(10); //wait 50ms
buttonPoll = digitalRead(button); //poll button again
if (buttonPoll == 0) { //if it is 0 considered one press
state = old + 1; //increase state by 1
}
}
else { //if button has not been pressed
delay(10); //wait 50ms
}
switch (state) { //react to button press & state
case 1: // if state is 1
//insert ONE
/*wheel pattern */
uint64_t one;
memcpy_P(&one, &ONE[i], 8);
displayImage(one);
if (++i >= ONE_LEN ) {
i = 0;
}
delay(100);
old = state;
break;
case 2:
uint64_t two;
memcpy_P(&two, &TWO[i], 8);
displayImage(two);
if (++i >= TWO_LEN ) {
i = 0;
}
delay(100);
old = state;
break;
case 3:
//insert THREE
uint64_t three;
memcpy_P(&three, &THREE[i], 8);
displayImage(three);
if (++i >= THREE_LEN ) {
i = 0;
}
delay(100);
old = state;
break;
default:
//insert ZERO
//if state is not 1,2,3
uint64_t zero;
memcpy_P(&zero, &ZERO[i], 8);
displayImage(zero);
if (++i >= ZERO_LEN ) {
i = 0;
}
delay(100);
old = 0;
break;
}
} |
Partager