Shahariar Hossain
/
FRDM-K82F_8x8LED_Matrix_nochip
Quick demo for LED 8x8 Matrix with FRDM-K82F
main.cpp@1:1088a4658fc2, 2018-05-23 (annotated)
- Committer:
- suntopbd
- Date:
- Wed May 23 17:48:41 2018 +0000
- Revision:
- 1:1088a4658fc2
- Parent:
- 0:b16b3c2d882e
- Child:
- 2:4e21ea1275a1
Shows "M" "B" "E" "D" in an inefficient way
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
suntopbd | 0:b16b3c2d882e | 1 | // copyleft by suntopbd 23.5.18 |
suntopbd | 0:b16b3c2d882e | 2 | /* |
suntopbd | 0:b16b3c2d882e | 3 | PINOUT |
suntopbd | 0:b16b3c2d882e | 4 | https://os.mbed.com/platforms/FRDM-K82F/#board-pinout |
suntopbd | 0:b16b3c2d882e | 5 | should work with any other board with 16 I/O available |
suntopbd | 0:b16b3c2d882e | 6 | |
suntopbd | 0:b16b3c2d882e | 7 | C1 C2 C3 C4 C5 C6 C7 C8 |
suntopbd | 0:b16b3c2d882e | 8 | R1 x x x x x x x x |
suntopbd | 0:b16b3c2d882e | 9 | R2 x x x x x x x x |
suntopbd | 0:b16b3c2d882e | 10 | R3 x x x x x x x x |
suntopbd | 0:b16b3c2d882e | 11 | R4 x x x x x x x x |
suntopbd | 0:b16b3c2d882e | 12 | R5 x x x x x x x x |
suntopbd | 0:b16b3c2d882e | 13 | R6 x x x x x x x x |
suntopbd | 0:b16b3c2d882e | 14 | R7 x x x x x x x x |
suntopbd | 0:b16b3c2d882e | 15 | R8 x x x x x x x x |
suntopbd | 0:b16b3c2d882e | 16 | |
suntopbd | 0:b16b3c2d882e | 17 | */ |
suntopbd | 0:b16b3c2d882e | 18 | #include "mbed.h" |
suntopbd | 0:b16b3c2d882e | 19 | |
suntopbd | 0:b16b3c2d882e | 20 | // Row Pins // |
suntopbd | 0:b16b3c2d882e | 21 | DigitalOut R1(PTC9); |
suntopbd | 0:b16b3c2d882e | 22 | DigitalOut R2(PTC8); |
suntopbd | 0:b16b3c2d882e | 23 | DigitalOut R3(PTC10); |
suntopbd | 0:b16b3c2d882e | 24 | DigitalOut R4(PTC11); |
suntopbd | 0:b16b3c2d882e | 25 | DigitalOut R5(PTA14); |
suntopbd | 0:b16b3c2d882e | 26 | DigitalOut R6(PTC7); |
suntopbd | 0:b16b3c2d882e | 27 | DigitalOut R7(PTA16); |
suntopbd | 0:b16b3c2d882e | 28 | DigitalOut R8(PTA15); |
suntopbd | 0:b16b3c2d882e | 29 | |
suntopbd | 0:b16b3c2d882e | 30 | // Col Pins // |
suntopbd | 0:b16b3c2d882e | 31 | DigitalOut C1(PTD0); |
suntopbd | 0:b16b3c2d882e | 32 | DigitalOut C2(PTC12); |
suntopbd | 0:b16b3c2d882e | 33 | DigitalOut C3(PTB17); |
suntopbd | 0:b16b3c2d882e | 34 | DigitalOut C4(PTB16); |
suntopbd | 0:b16b3c2d882e | 35 | DigitalOut C5(PTA5); |
suntopbd | 0:b16b3c2d882e | 36 | DigitalOut C6(PTA13); |
suntopbd | 0:b16b3c2d882e | 37 | DigitalOut C7(PTA12); |
suntopbd | 0:b16b3c2d882e | 38 | DigitalOut C8(PTA17); |
suntopbd | 0:b16b3c2d882e | 39 | |
suntopbd | 0:b16b3c2d882e | 40 | // func declearation // |
suntopbd | 0:b16b3c2d882e | 41 | |
suntopbd | 0:b16b3c2d882e | 42 | void disp_off(void); |
suntopbd | 0:b16b3c2d882e | 43 | void disp_line(int,int,int,int,int,int,int,int,int); |
suntopbd | 0:b16b3c2d882e | 44 | void disp_page(int*); |
suntopbd | 0:b16b3c2d882e | 45 | |
suntopbd | 0:b16b3c2d882e | 46 | |
suntopbd | 0:b16b3c2d882e | 47 | int *dotpointer; |
suntopbd | 0:b16b3c2d882e | 48 | |
suntopbd | 0:b16b3c2d882e | 49 | // 0 will glow LED and 1 will keep off // |
suntopbd | 0:b16b3c2d882e | 50 | // Use it to make Icon, Character, Symble // |
suntopbd | 0:b16b3c2d882e | 51 | int canvas[64] = { |
suntopbd | 0:b16b3c2d882e | 52 | |
suntopbd | 0:b16b3c2d882e | 53 | 1,1,1,0,0,1,1,1, |
suntopbd | 1:1088a4658fc2 | 54 | 1,1,0,0,0,0,1,1, |
suntopbd | 1:1088a4658fc2 | 55 | 1,0,0,0,0,0,0,1, |
suntopbd | 1:1088a4658fc2 | 56 | 0,0,0,0,0,0,0,0, |
suntopbd | 1:1088a4658fc2 | 57 | 1,1,0,0,0,0,1,1, |
suntopbd | 1:1088a4658fc2 | 58 | 1,1,0,0,0,0,1,1, |
suntopbd | 1:1088a4658fc2 | 59 | 1,1,0,0,0,0,1,1, |
suntopbd | 1:1088a4658fc2 | 60 | 1,1,0,0,0,0,1,1, |
suntopbd | 0:b16b3c2d882e | 61 | |
suntopbd | 0:b16b3c2d882e | 62 | }; |
suntopbd | 1:1088a4658fc2 | 63 | int m[64] = { |
suntopbd | 0:b16b3c2d882e | 64 | |
suntopbd | 1:1088a4658fc2 | 65 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 66 | 0,0,1,1,1,0,0,1, |
suntopbd | 1:1088a4658fc2 | 67 | 0,1,0,1,0,1,0,1, |
suntopbd | 1:1088a4658fc2 | 68 | 0,1,1,0,1,1,0,1, |
suntopbd | 1:1088a4658fc2 | 69 | 0,1,1,1,1,1,0,1, |
suntopbd | 1:1088a4658fc2 | 70 | 0,1,1,1,1,1,0,1, |
suntopbd | 1:1088a4658fc2 | 71 | 0,1,1,1,1,1,0,1, |
suntopbd | 1:1088a4658fc2 | 72 | 0,1,1,1,1,1,0,1, |
suntopbd | 1:1088a4658fc2 | 73 | |
suntopbd | 1:1088a4658fc2 | 74 | }; |
suntopbd | 1:1088a4658fc2 | 75 | |
suntopbd | 1:1088a4658fc2 | 76 | int b[64] = { |
suntopbd | 1:1088a4658fc2 | 77 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 78 | 0,0,0,0,0,1,1,1, |
suntopbd | 1:1088a4658fc2 | 79 | 0,1,1,1,1,0,1,1, |
suntopbd | 1:1088a4658fc2 | 80 | 0,1,1,1,1,0,1,1, |
suntopbd | 1:1088a4658fc2 | 81 | 0,0,0,0,0,1,1,1, |
suntopbd | 1:1088a4658fc2 | 82 | 0,1,1,1,1,0,1,1, |
suntopbd | 1:1088a4658fc2 | 83 | 0,1,1,1,1,0,1,1, |
suntopbd | 1:1088a4658fc2 | 84 | 0,0,0,0,0,1,1,1, |
suntopbd | 1:1088a4658fc2 | 85 | |
suntopbd | 1:1088a4658fc2 | 86 | }; |
suntopbd | 0:b16b3c2d882e | 87 | |
suntopbd | 1:1088a4658fc2 | 88 | int e[64] = { |
suntopbd | 1:1088a4658fc2 | 89 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 90 | 0,0,0,0,0,0,1,1, |
suntopbd | 1:1088a4658fc2 | 91 | 0,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 92 | 0,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 93 | 0,0,0,0,0,1,1,1, |
suntopbd | 1:1088a4658fc2 | 94 | 0,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 95 | 0,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 96 | 0,0,0,0,0,0,1,1, |
suntopbd | 1:1088a4658fc2 | 97 | |
suntopbd | 1:1088a4658fc2 | 98 | }; |
suntopbd | 1:1088a4658fc2 | 99 | |
suntopbd | 1:1088a4658fc2 | 100 | int d[64] = { |
suntopbd | 1:1088a4658fc2 | 101 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 102 | 0,0,0,0,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 103 | 0,1,1,1,0,1,1,1, |
suntopbd | 1:1088a4658fc2 | 104 | 0,1,1,1,1,0,1,1, |
suntopbd | 1:1088a4658fc2 | 105 | 0,1,1,1,1,0,1,1, |
suntopbd | 1:1088a4658fc2 | 106 | 0,1,1,1,1,0,1,1, |
suntopbd | 1:1088a4658fc2 | 107 | 0,1,1,1,0,1,1,1, |
suntopbd | 1:1088a4658fc2 | 108 | 0,0,0,0,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 109 | |
suntopbd | 1:1088a4658fc2 | 110 | }; |
suntopbd | 1:1088a4658fc2 | 111 | |
suntopbd | 1:1088a4658fc2 | 112 | int space[64] = { |
suntopbd | 1:1088a4658fc2 | 113 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 114 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 115 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 116 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 117 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 118 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 119 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 120 | 1,1,1,1,1,1,1,1, |
suntopbd | 1:1088a4658fc2 | 121 | |
suntopbd | 1:1088a4658fc2 | 122 | }; |
suntopbd | 1:1088a4658fc2 | 123 | |
suntopbd | 1:1088a4658fc2 | 124 | |
suntopbd | 1:1088a4658fc2 | 125 | |
suntopbd | 1:1088a4658fc2 | 126 | void update_disp_m(); |
suntopbd | 1:1088a4658fc2 | 127 | void update_disp_b(); |
suntopbd | 1:1088a4658fc2 | 128 | void update_disp_e(); |
suntopbd | 1:1088a4658fc2 | 129 | void update_disp_d(); |
suntopbd | 1:1088a4658fc2 | 130 | void update_disp_space(); |
suntopbd | 1:1088a4658fc2 | 131 | |
suntopbd | 1:1088a4658fc2 | 132 | Timer timer; |
suntopbd | 0:b16b3c2d882e | 133 | |
suntopbd | 0:b16b3c2d882e | 134 | int main() { |
suntopbd | 0:b16b3c2d882e | 135 | // SETUP // |
suntopbd | 0:b16b3c2d882e | 136 | disp_off(); |
suntopbd | 1:1088a4658fc2 | 137 | timer.start(); |
suntopbd | 0:b16b3c2d882e | 138 | // END OF SETUP // |
suntopbd | 0:b16b3c2d882e | 139 | |
suntopbd | 0:b16b3c2d882e | 140 | |
suntopbd | 0:b16b3c2d882e | 141 | // LOOP // |
suntopbd | 0:b16b3c2d882e | 142 | while (1) |
suntopbd | 0:b16b3c2d882e | 143 | { |
suntopbd | 1:1088a4658fc2 | 144 | |
suntopbd | 1:1088a4658fc2 | 145 | while (timer.read() < 0.6) {update_disp_m();}timer.reset(); |
suntopbd | 1:1088a4658fc2 | 146 | while (timer.read() < 0.6) {update_disp_b();}timer.reset(); |
suntopbd | 1:1088a4658fc2 | 147 | while (timer.read() < 0.6) {update_disp_e();}timer.reset(); |
suntopbd | 1:1088a4658fc2 | 148 | while (timer.read() < 0.6) {update_disp_d();}timer.reset(); |
suntopbd | 1:1088a4658fc2 | 149 | while (timer.read() < 0.8) {update_disp_space();}timer.reset(); |
suntopbd | 1:1088a4658fc2 | 150 | |
suntopbd | 0:b16b3c2d882e | 151 | } |
suntopbd | 0:b16b3c2d882e | 152 | // END OF LOOP // |
suntopbd | 0:b16b3c2d882e | 153 | } |
suntopbd | 0:b16b3c2d882e | 154 | |
suntopbd | 0:b16b3c2d882e | 155 | //..........................................// |
suntopbd | 0:b16b3c2d882e | 156 | |
suntopbd | 0:b16b3c2d882e | 157 | |
suntopbd | 0:b16b3c2d882e | 158 | // MBED OS Tasks // |
suntopbd | 1:1088a4658fc2 | 159 | void update_disp_m() |
suntopbd | 1:1088a4658fc2 | 160 | { |
suntopbd | 1:1088a4658fc2 | 161 | dotpointer = &m[0]; |
suntopbd | 1:1088a4658fc2 | 162 | disp_page(dotpointer); |
suntopbd | 1:1088a4658fc2 | 163 | disp_off(); |
suntopbd | 1:1088a4658fc2 | 164 | |
suntopbd | 1:1088a4658fc2 | 165 | } |
suntopbd | 1:1088a4658fc2 | 166 | |
suntopbd | 1:1088a4658fc2 | 167 | void update_disp_b() |
suntopbd | 0:b16b3c2d882e | 168 | { |
suntopbd | 1:1088a4658fc2 | 169 | dotpointer = &b[0]; |
suntopbd | 1:1088a4658fc2 | 170 | disp_page(dotpointer); |
suntopbd | 1:1088a4658fc2 | 171 | disp_off(); |
suntopbd | 1:1088a4658fc2 | 172 | |
suntopbd | 1:1088a4658fc2 | 173 | } |
suntopbd | 1:1088a4658fc2 | 174 | void update_disp_e() |
suntopbd | 1:1088a4658fc2 | 175 | { |
suntopbd | 1:1088a4658fc2 | 176 | dotpointer = &e[0]; |
suntopbd | 1:1088a4658fc2 | 177 | disp_page(dotpointer); |
suntopbd | 1:1088a4658fc2 | 178 | disp_off(); |
suntopbd | 1:1088a4658fc2 | 179 | |
suntopbd | 1:1088a4658fc2 | 180 | } |
suntopbd | 1:1088a4658fc2 | 181 | void update_disp_d() |
suntopbd | 1:1088a4658fc2 | 182 | { |
suntopbd | 1:1088a4658fc2 | 183 | dotpointer = &d[0]; |
suntopbd | 1:1088a4658fc2 | 184 | disp_page(dotpointer); |
suntopbd | 1:1088a4658fc2 | 185 | disp_off(); |
suntopbd | 1:1088a4658fc2 | 186 | |
suntopbd | 1:1088a4658fc2 | 187 | } |
suntopbd | 1:1088a4658fc2 | 188 | void update_disp_space() |
suntopbd | 1:1088a4658fc2 | 189 | { |
suntopbd | 1:1088a4658fc2 | 190 | dotpointer = &space[0]; |
suntopbd | 0:b16b3c2d882e | 191 | disp_page(dotpointer); |
suntopbd | 0:b16b3c2d882e | 192 | disp_off(); |
suntopbd | 0:b16b3c2d882e | 193 | |
suntopbd | 0:b16b3c2d882e | 194 | } |
suntopbd | 0:b16b3c2d882e | 195 | |
suntopbd | 0:b16b3c2d882e | 196 | // End of Tasks // |
suntopbd | 0:b16b3c2d882e | 197 | |
suntopbd | 0:b16b3c2d882e | 198 | |
suntopbd | 0:b16b3c2d882e | 199 | // Functions Body // |
suntopbd | 0:b16b3c2d882e | 200 | void disp_off(void) |
suntopbd | 0:b16b3c2d882e | 201 | { |
suntopbd | 0:b16b3c2d882e | 202 | // for CC type |
suntopbd | 0:b16b3c2d882e | 203 | C1 = 1; C2 = 1; C3 = 1; C4 = 1; C5 = 1; C6 = 1; C7 = 1; C8 = 1; |
suntopbd | 0:b16b3c2d882e | 204 | // for CA |
suntopbd | 0:b16b3c2d882e | 205 | //C1 = 0; C2 = 0; C3 = 0; C4 = 0; C5 = 0; C6 = 0; C7 = 0; C8 = 0; |
suntopbd | 0:b16b3c2d882e | 206 | } |
suntopbd | 0:b16b3c2d882e | 207 | |
suntopbd | 0:b16b3c2d882e | 208 | void disp_line(int r,int c1,int c2,int c3,int c4,int c5,int c6,int c7,int c8) |
suntopbd | 0:b16b3c2d882e | 209 | { |
suntopbd | 0:b16b3c2d882e | 210 | disp_off(); |
suntopbd | 0:b16b3c2d882e | 211 | if(r==1) {R1=1;R2=0;R3=0;R4=0;R5=0;R6=0;R7=0;R8=0;} |
suntopbd | 0:b16b3c2d882e | 212 | if(r==2) {R1=0;R2=1;R3=0;R4=0;R5=0;R6=0;R7=0;R8=0;} |
suntopbd | 0:b16b3c2d882e | 213 | if(r==3) {R1=0;R2=0;R3=1;R4=0;R5=0;R6=0;R7=0;R8=0;} |
suntopbd | 0:b16b3c2d882e | 214 | if(r==4) {R1=0;R2=0;R3=0;R4=1;R5=0;R6=0;R7=0;R8=0;} |
suntopbd | 0:b16b3c2d882e | 215 | if(r==5) {R1=0;R2=0;R3=0;R4=0;R5=1;R6=0;R7=0;R8=0;} |
suntopbd | 0:b16b3c2d882e | 216 | if(r==6) {R1=0;R2=0;R3=0;R4=0;R5=0;R6=1;R7=0;R8=0;} |
suntopbd | 0:b16b3c2d882e | 217 | if(r==7) {R1=0;R2=0;R3=0;R4=0;R5=0;R6=0;R7=1;R8=0;} |
suntopbd | 0:b16b3c2d882e | 218 | if(r==8) {R1=0;R2=0;R3=0;R4=0;R5=0;R6=0;R7=0;R8=1;} |
suntopbd | 0:b16b3c2d882e | 219 | C1=c1;C2=c2;C3=c3;C4=c4; C5=c5;C6=c6;C7=c7;C8=c8; |
suntopbd | 0:b16b3c2d882e | 220 | } |
suntopbd | 0:b16b3c2d882e | 221 | |
suntopbd | 0:b16b3c2d882e | 222 | |
suntopbd | 0:b16b3c2d882e | 223 | |
suntopbd | 0:b16b3c2d882e | 224 | void disp_page(int *dot) |
suntopbd | 0:b16b3c2d882e | 225 | { |
suntopbd | 0:b16b3c2d882e | 226 | disp_line(1,*(dot+0) ,*(dot+1) ,*(dot+2) ,*(dot+3) ,*(dot+4) ,*(dot+5) ,*(dot+6) ,*(dot+7) ); |
suntopbd | 0:b16b3c2d882e | 227 | disp_line(2,*(dot+8) ,*(dot+9) ,*(dot+10),*(dot+11),*(dot+12),*(dot+13),*(dot+14),*(dot+15)); |
suntopbd | 0:b16b3c2d882e | 228 | disp_line(3,*(dot+16),*(dot+17),*(dot+18),*(dot+19),*(dot+20),*(dot+21),*(dot+22),*(dot+23)); |
suntopbd | 0:b16b3c2d882e | 229 | disp_line(4,*(dot+24),*(dot+25),*(dot+26),*(dot+27),*(dot+28),*(dot+29),*(dot+30),*(dot+31)); |
suntopbd | 0:b16b3c2d882e | 230 | disp_line(5,*(dot+32),*(dot+33),*(dot+34),*(dot+35),*(dot+36),*(dot+37),*(dot+38),*(dot+39)); |
suntopbd | 0:b16b3c2d882e | 231 | disp_line(6,*(dot+40),*(dot+41),*(dot+42),*(dot+43),*(dot+44),*(dot+45),*(dot+46),*(dot+47)); |
suntopbd | 0:b16b3c2d882e | 232 | disp_line(7,*(dot+48),*(dot+49),*(dot+50),*(dot+51),*(dot+52),*(dot+53),*(dot+54),*(dot+55)); |
suntopbd | 0:b16b3c2d882e | 233 | disp_line(8,*(dot+56),*(dot+57),*(dot+58),*(dot+59),*(dot+60),*(dot+61),*(dot+62),*(dot+63)); |
suntopbd | 0:b16b3c2d882e | 234 | |
suntopbd | 0:b16b3c2d882e | 235 | } |
suntopbd | 0:b16b3c2d882e | 236 | |
suntopbd | 0:b16b3c2d882e | 237 | // End of Functions // |