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
| #include <LedControl.h>
const int DIN = D7; const int CS = D6; const int CLK = D5;
LedControl lc = LedControl(DIN, CLK, CS, 1);
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[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(uint8_t nums) { unsigned char *xs = getshownum(nums); for (uint8_t i = 0; i < 8; i++) { writedata[i] = *xs; xs++; } showLed(); }
void inits() { for (uint8_t j = 0; j < 8; j++) { writedata[j] = 0x0; } }
void showLed() { for (uint8_t i = 0; i < 8; i++) { lc.setRow(0, i, writedata[i]); } }
void downMove() { unsigned char temp = writedata[7]; for (uint8_t k = 7; k > 0; k--) { writedata[k] = writedata[k - 1]; } writedata[0] = temp; showLed(); }
void sliderNum(uint8_t nums) { unsigned char *xs = getshownum(nums); bool ten = false, one = false; for (uint8_t j = 0; j < 8; j++) { if ((writedata[j] & 0xf0) != (xs[j] & 0xf0)) { ten = true; } if ((writedata[j] & 0xf) != (xs[j] & 0xf)) { one = true; } } for (uint8_t i = 0; i < 8; i++) { if (one) { slideDown(xs[abs(i - 7)], true); } if (ten) { slideDown(xs[abs(i - 7)], false); } showLed(); delay(80); } }
void slideDown(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[k] = (((writedata[k] & f1) + (writedata[k - 1] & f)) & f) + (writedata[k] & f1); } writedata[0] = ((first & f) & f) + (writedata[0] & f1); }
void setup() { Serial.begin(115200); lc.shutdown(0, false); lc.setIntensity(0, 1); inits(); shownum(00); }
void loop() { for (uint8_t j = 0; j <= 99; j++) { sliderNum(j); delay(1000); } }
|