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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
| #include <LedControl.h>
const int DIN = D7; const int CS = D6; const int CLK = D5;
LedControl lc = LedControl(DIN, CLK, CS, 4);
unsigned char templatedata[10][8] = { {0x0, 0xE0, 0xA0, 0xA0, 0xA0, 0xE0, 0x0, 0x0}, {0x0, 0x40, 0xC0, 0x40, 0x40, 0xE0, 0x0, 0x0}, {0x0, 0xE0, 0x20, 0xE0, 0x80, 0xE0, 0x0, 0x0}, {0x0, 0xE0, 0x20, 0xE0, 0x20, 0xE0, 0x0, 0x0}, {0x0, 0xA0, 0xA0, 0xE0, 0x20, 0x20, 0x0, 0x0}, {0x0, 0xE0, 0x80, 0xE0, 0x20, 0xE0, 0x0, 0x0}, {0x0, 0xE0, 0x80, 0xE0, 0xA0, 0xE0, 0x0, 0x0}, {0x0, 0xE0, 0x20, 0x20, 0x20, 0x20, 0x0, 0x0}, {0x0, 0xE0, 0xA0, 0xE0, 0xA0, 0xE0, 0x0, 0x0}, {0x0, 0xE0, 0xA0, 0xE0, 0x20, 0xE0, 0x0, 0x0} };
unsigned char writedata[4][8];
unsigned char * getshownum(uint8_t nums) { unsigned char *ten = templatedata[(nums / 10)], *one = templatedata[nums % 10]; unsigned char *arr = new uint8_t [8]; for (int i = 0; i < 8; i++) { arr[i] = *ten + ((*one & 0xE0) >> 4); ten++; one++; } return arr; }
void shownum(int nums, int index) { unsigned char *xs = getshownum(nums); for (uint8_t i = 0; i < 8; i++) { writedata[index][i] = *xs; xs++; } }
void inits() { for (int i = 0; i < 4; i++) { for (int j = 0; j < 8; j++) { writedata[i][j] = 0x0; } } }
void rightMove() { for (int i = 0; i < 8; i++) { unsigned char first = writedata[0][i] & 0x80; first >>= 7; for (int j = 1; j < 4; j++) { unsigned char temp = writedata[j][i] & 0x80; temp >>= 7; writedata[j][i] &= 0x7F; writedata[j][i] <<= 1; writedata[j][i] += first; first = temp; if (j == (4 - 1)) { writedata[0][i] &= 0x7F; writedata[0][i] <<= 1; writedata[0][i] += first; } } } }
void Move1() { for (int8_t i = 0; i < 4; i++) { bool isbreadk = false; for (int8_t j = 0; j < 8; j++) { if (writedata[i][j] == 0xff) { continue; } if (writedata[i][j] == 0x00) { writedata[i][j] = 0x01; isbreadk = true; break; } writedata[i][j] += ((writedata[i][j] ^ (writedata[i][j] >> 1)) << 1); } if (isbreadk) { break; } } }
void sliderNum(uint8_t index, uint8_t nums) { unsigned char *xs = getshownum(nums); bool ten = false, one = false; for (uint8_t j = 0; j < 8; j++) { if ((writedata[index][j] & 0xf0) != (xs[j] & 0xf0)) { ten = true; } if ((writedata[index][j] & 0xf) != (xs[j] & 0xf)) { one = true; } } for (uint8_t i = 0; i < 8; i++) { if (one) { slideDown(index, xs[abs(i - 7)], true); } if (ten) { slideDown(index, xs[abs(i - 7)], false); } showLed(); delay(80); } }
void slideDown(uint8_t index, unsigned char first, bool isright) { unsigned char f = isright ? 0xf : 0xf << 4, f1 = isright ? 0xf0 : 0xf0 >> 4; for (uint8_t k = 7; k > 0; k--) { writedata[index][k] = (((writedata[index][k] & f1) + (writedata[index][k - 1] & f)) & f) + (writedata[index][k] & f1); } writedata[index][0] = ((first & f) & f) + (writedata[index][0] & f1); }
void showLed() { for (int j = 0; j < 8; j++) { for (int i = 0; i < 4; i++) { lc.setRow(i, j, writedata[i][j]); } } }
void setup() { lc.shutdown(0, false); lc.shutdown(1, false); lc.shutdown(2, false); lc.shutdown(3, false); lc.setIntensity(0, 0); lc.setIntensity(1, 0); lc.setIntensity(2, 0); lc.setIntensity(3, 0); inits(); shownum(12, 2); shownum(34, 1); shownum(56, 0); }
void loop() { for (int j = 0; j < 8; j++) { for (int i = 0; i < 4; i++) { lc.setRow(i, j, writedata[i][j]); } } rightMove(); delay(150);
}
|