![](/media/cache/profiles/b59442085644532ef03417a3e5a76437.jpg.50x50_q85.jpg)
Test program fro TM1637 LEDController Library, Initial release.
See here for more information.
main.cpp@0:672ec7a524fa, 2016-01-30 (annotated)
- Committer:
- wim
- Date:
- Sat Jan 30 20:36:52 2016 +0000
- Revision:
- 0:672ec7a524fa
- Child:
- 1:0dab5786c471
Test program for TM1637 LEDcontroller Library, ; Initial release.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wim | 0:672ec7a524fa | 1 | /* mbed TM1637 Test program, for TM1637 LED controller |
wim | 0:672ec7a524fa | 2 | * Copyright (c) 2016, v01: WH, Initial version |
wim | 0:672ec7a524fa | 3 | * |
wim | 0:672ec7a524fa | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wim | 0:672ec7a524fa | 5 | * of this software and associated documentation files (the "Software"), to deal |
wim | 0:672ec7a524fa | 6 | * in the Software without restriction, including without limitation the rights |
wim | 0:672ec7a524fa | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wim | 0:672ec7a524fa | 8 | * copies of the Software, and to permit persons to whom the Software is |
wim | 0:672ec7a524fa | 9 | * furnished to do so, subject to the following conditions: |
wim | 0:672ec7a524fa | 10 | * |
wim | 0:672ec7a524fa | 11 | * The above copyright notice and this permission notice shall be included in |
wim | 0:672ec7a524fa | 12 | * all copies or substantial portions of the Software. |
wim | 0:672ec7a524fa | 13 | * |
wim | 0:672ec7a524fa | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wim | 0:672ec7a524fa | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wim | 0:672ec7a524fa | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wim | 0:672ec7a524fa | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wim | 0:672ec7a524fa | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wim | 0:672ec7a524fa | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wim | 0:672ec7a524fa | 20 | * THE SOFTWARE. |
wim | 0:672ec7a524fa | 21 | */ |
wim | 0:672ec7a524fa | 22 | #include "mbed.h" |
wim | 0:672ec7a524fa | 23 | #include "TM1637.h" |
wim | 0:672ec7a524fa | 24 | |
wim | 0:672ec7a524fa | 25 | #if (CATALEX_TEST == 1) |
wim | 0:672ec7a524fa | 26 | // CATALEX TM1637 Test |
wim | 0:672ec7a524fa | 27 | #include "Font_7Seg.h" |
wim | 0:672ec7a524fa | 28 | |
wim | 0:672ec7a524fa | 29 | Serial pc(USBTX, USBRX); |
wim | 0:672ec7a524fa | 30 | DigitalOut myled(LED1); |
wim | 0:672ec7a524fa | 31 | |
wim | 0:672ec7a524fa | 32 | // DisplayData_t size is 4 bytes (4 Grids @ 8 Segments) |
wim | 0:672ec7a524fa | 33 | TM1637::DisplayData_t all_str = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
wim | 0:672ec7a524fa | 34 | TM1637::DisplayData_t cls_str = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
wim | 0:672ec7a524fa | 35 | TM1637::DisplayData_t hello_str = {C7_H, C7_I, 0x00, 0x00, 0x00, 0x00}; |
wim | 0:672ec7a524fa | 36 | TM1637::DisplayData_t bye_str = {C7_B, C7_Y, C7_E, 0x00, 0x00, 0x00}; |
wim | 0:672ec7a524fa | 37 | |
wim | 0:672ec7a524fa | 38 | // KeyData_t size is 1 bytes |
wim | 0:672ec7a524fa | 39 | TM1637::KeyData_t keydata; |
wim | 0:672ec7a524fa | 40 | |
wim | 0:672ec7a524fa | 41 | //TM1637_CATALEX declaration |
wim | 0:672ec7a524fa | 42 | TM1637_CATALEX CATALEX(p5, p6, p7); |
wim | 0:672ec7a524fa | 43 | |
wim | 0:672ec7a524fa | 44 | |
wim | 0:672ec7a524fa | 45 | void show_menu() { |
wim | 0:672ec7a524fa | 46 | // pc.printf("0: Exit\n\r"); |
wim | 0:672ec7a524fa | 47 | pc.printf("1: All\n\r"); |
wim | 0:672ec7a524fa | 48 | pc.printf("2: Show all segs\r\n"); |
wim | 0:672ec7a524fa | 49 | pc.printf("3: Show all chars\n\r"); |
wim | 0:672ec7a524fa | 50 | pc.printf("4: Show all digits\n\r"); |
wim | 0:672ec7a524fa | 51 | pc.printf("5: Show all icons\n\r"); |
wim | 0:672ec7a524fa | 52 | pc.printf("6: Counter\n\r"); |
wim | 0:672ec7a524fa | 53 | pc.printf("7: Floats\n\r"); |
wim | 0:672ec7a524fa | 54 | pc.printf("8: Kitt\n\r"); |
wim | 0:672ec7a524fa | 55 | pc.printf("9: Bye\n\r"); |
wim | 0:672ec7a524fa | 56 | } |
wim | 0:672ec7a524fa | 57 | |
wim | 0:672ec7a524fa | 58 | |
wim | 0:672ec7a524fa | 59 | char cmd, bits; |
wim | 0:672ec7a524fa | 60 | int main() { |
wim | 0:672ec7a524fa | 61 | |
wim | 0:672ec7a524fa | 62 | pc.printf("Hello World\r\n"); // |
wim | 0:672ec7a524fa | 63 | |
wim | 0:672ec7a524fa | 64 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 65 | CATALEX.writeData(all_str); |
wim | 0:672ec7a524fa | 66 | wait(2); |
wim | 0:672ec7a524fa | 67 | CATALEX.setBrightness(TM1637_BRT3); |
wim | 0:672ec7a524fa | 68 | wait(1); |
wim | 0:672ec7a524fa | 69 | CATALEX.setBrightness(TM1637_BRT0); |
wim | 0:672ec7a524fa | 70 | wait(1); |
wim | 0:672ec7a524fa | 71 | CATALEX.setBrightness(TM1637_BRT4); |
wim | 0:672ec7a524fa | 72 | |
wim | 0:672ec7a524fa | 73 | wait(1); |
wim | 0:672ec7a524fa | 74 | CATALEX.cls(true); |
wim | 0:672ec7a524fa | 75 | CATALEX.writeData(hello_str); |
wim | 0:672ec7a524fa | 76 | |
wim | 0:672ec7a524fa | 77 | char cmd2 = '0'; |
wim | 0:672ec7a524fa | 78 | while (1) { |
wim | 0:672ec7a524fa | 79 | |
wim | 0:672ec7a524fa | 80 | show_menu(); |
wim | 0:672ec7a524fa | 81 | cmd2 = pc.getc(); |
wim | 0:672ec7a524fa | 82 | |
wim | 0:672ec7a524fa | 83 | switch (cmd2) { |
wim | 0:672ec7a524fa | 84 | case '1' : { |
wim | 0:672ec7a524fa | 85 | pc.printf("all\r\n"); |
wim | 0:672ec7a524fa | 86 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 87 | CATALEX.writeData(all_str); |
wim | 0:672ec7a524fa | 88 | break; |
wim | 0:672ec7a524fa | 89 | } |
wim | 0:672ec7a524fa | 90 | |
wim | 0:672ec7a524fa | 91 | case '2' : { |
wim | 0:672ec7a524fa | 92 | #if(1) |
wim | 0:672ec7a524fa | 93 | //test to show all segs |
wim | 0:672ec7a524fa | 94 | pc.printf("Show all segs\r\n"); |
wim | 0:672ec7a524fa | 95 | wait(1); |
wim | 0:672ec7a524fa | 96 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 97 | |
wim | 0:672ec7a524fa | 98 | for (int i=0; i<TM1637_DISPLAY_MEM; i++) { |
wim | 0:672ec7a524fa | 99 | for (int bit=0; bit<8; bit++) { |
wim | 0:672ec7a524fa | 100 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 101 | |
wim | 0:672ec7a524fa | 102 | bits = 0x01 << bit; |
wim | 0:672ec7a524fa | 103 | CATALEX.writeData(bits, i); |
wim | 0:672ec7a524fa | 104 | |
wim | 0:672ec7a524fa | 105 | pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits); |
wim | 0:672ec7a524fa | 106 | // wait(0.5); |
wim | 0:672ec7a524fa | 107 | cmd = pc.getc(); // wait for key |
wim | 0:672ec7a524fa | 108 | } |
wim | 0:672ec7a524fa | 109 | } |
wim | 0:672ec7a524fa | 110 | pc.printf("\r\nShow all segs done\r\n"); |
wim | 0:672ec7a524fa | 111 | #endif |
wim | 0:672ec7a524fa | 112 | break; |
wim | 0:672ec7a524fa | 113 | } |
wim | 0:672ec7a524fa | 114 | |
wim | 0:672ec7a524fa | 115 | case '3' : { |
wim | 0:672ec7a524fa | 116 | |
wim | 0:672ec7a524fa | 117 | #if(1) |
wim | 0:672ec7a524fa | 118 | //test to show all chars |
wim | 0:672ec7a524fa | 119 | pc.printf("Show all alpha chars\r\n"); |
wim | 0:672ec7a524fa | 120 | wait(1); |
wim | 0:672ec7a524fa | 121 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 122 | |
wim | 0:672ec7a524fa | 123 | for (int i=0; i<26; i++) { |
wim | 0:672ec7a524fa | 124 | CATALEX.printf("%c", char(i + 'A')); |
wim | 0:672ec7a524fa | 125 | // CATALEX.printf("%c", char(i + 'a')); |
wim | 0:672ec7a524fa | 126 | wait(0.25); |
wim | 0:672ec7a524fa | 127 | } |
wim | 0:672ec7a524fa | 128 | pc.printf("Show all alpha chars done\r\n"); |
wim | 0:672ec7a524fa | 129 | #endif |
wim | 0:672ec7a524fa | 130 | |
wim | 0:672ec7a524fa | 131 | #if(0) |
wim | 0:672ec7a524fa | 132 | //test to show all chars |
wim | 0:672ec7a524fa | 133 | pc.printf("Show all chars\r\n"); |
wim | 0:672ec7a524fa | 134 | wait(1); |
wim | 0:672ec7a524fa | 135 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 136 | |
wim | 0:672ec7a524fa | 137 | for (int i=FONT_7S_START; i<FONT_7S_END; i++) { |
wim | 0:672ec7a524fa | 138 | CATALEX.printf("%c", char(i)); |
wim | 0:672ec7a524fa | 139 | // wait(0.25); |
wim | 0:672ec7a524fa | 140 | cmd = pc.getc(); // wait for key |
wim | 0:672ec7a524fa | 141 | } |
wim | 0:672ec7a524fa | 142 | pc.printf("Show all chars done\r\n"); |
wim | 0:672ec7a524fa | 143 | #endif |
wim | 0:672ec7a524fa | 144 | break; |
wim | 0:672ec7a524fa | 145 | } |
wim | 0:672ec7a524fa | 146 | case '4': { |
wim | 0:672ec7a524fa | 147 | #if(0) |
wim | 0:672ec7a524fa | 148 | //test to show all digits (base is 10) |
wim | 0:672ec7a524fa | 149 | pc.printf("Show all digits\r\n"); |
wim | 0:672ec7a524fa | 150 | wait(1); |
wim | 0:672ec7a524fa | 151 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 152 | |
wim | 0:672ec7a524fa | 153 | for (int i=0; i<CATALEX_NR_DIGITS; i++) { |
wim | 0:672ec7a524fa | 154 | |
wim | 0:672ec7a524fa | 155 | for (int cnt=0; cnt<10; cnt++) { |
wim | 0:672ec7a524fa | 156 | CATALEX.locate(i); |
wim | 0:672ec7a524fa | 157 | CATALEX.printf("%0d", cnt); |
wim | 0:672ec7a524fa | 158 | |
wim | 0:672ec7a524fa | 159 | // wait(0.5); |
wim | 0:672ec7a524fa | 160 | cmd = pc.getc(); // wait for key |
wim | 0:672ec7a524fa | 161 | } |
wim | 0:672ec7a524fa | 162 | } |
wim | 0:672ec7a524fa | 163 | pc.printf("\r\nShow all digits done\r\n"); |
wim | 0:672ec7a524fa | 164 | #endif |
wim | 0:672ec7a524fa | 165 | |
wim | 0:672ec7a524fa | 166 | #if(1) |
wim | 0:672ec7a524fa | 167 | //test to show all digits (base is 0x10) |
wim | 0:672ec7a524fa | 168 | pc.printf("Show all hex digits\r\n"); |
wim | 0:672ec7a524fa | 169 | wait(1); |
wim | 0:672ec7a524fa | 170 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 171 | |
wim | 0:672ec7a524fa | 172 | CATALEX.printf("%04x", 0x01AB); |
wim | 0:672ec7a524fa | 173 | cmd = pc.getc(); // wait for key |
wim | 0:672ec7a524fa | 174 | CATALEX.printf("%04x", 0x0); |
wim | 0:672ec7a524fa | 175 | |
wim | 0:672ec7a524fa | 176 | for (int i=0; i<CATALEX_NR_DIGITS; i++) { |
wim | 0:672ec7a524fa | 177 | |
wim | 0:672ec7a524fa | 178 | for (int cnt=0; cnt<0x10; cnt++) { |
wim | 0:672ec7a524fa | 179 | CATALEX.locate(i); |
wim | 0:672ec7a524fa | 180 | CATALEX.printf("%0x", cnt); |
wim | 0:672ec7a524fa | 181 | |
wim | 0:672ec7a524fa | 182 | // wait(0.5); |
wim | 0:672ec7a524fa | 183 | cmd = pc.getc(); // wait for key |
wim | 0:672ec7a524fa | 184 | } |
wim | 0:672ec7a524fa | 185 | } |
wim | 0:672ec7a524fa | 186 | pc.printf("\r\nShow all hex digits done\r\n"); |
wim | 0:672ec7a524fa | 187 | #endif |
wim | 0:672ec7a524fa | 188 | break; |
wim | 0:672ec7a524fa | 189 | } |
wim | 0:672ec7a524fa | 190 | case '5': { |
wim | 0:672ec7a524fa | 191 | #if(1) |
wim | 0:672ec7a524fa | 192 | //test to show all icons |
wim | 0:672ec7a524fa | 193 | pc.printf("Show all icons\r\n"); |
wim | 0:672ec7a524fa | 194 | CATALEX.cls(true); // Also clear all Icons |
wim | 0:672ec7a524fa | 195 | |
wim | 0:672ec7a524fa | 196 | float delay=0.1; |
wim | 0:672ec7a524fa | 197 | // Icons on |
wim | 0:672ec7a524fa | 198 | CATALEX.setIcon(TM1637_CATALEX::COL2); wait(delay); |
wim | 0:672ec7a524fa | 199 | |
wim | 0:672ec7a524fa | 200 | wait(delay); |
wim | 0:672ec7a524fa | 201 | |
wim | 0:672ec7a524fa | 202 | // Icons off |
wim | 0:672ec7a524fa | 203 | CATALEX.clrIcon(TM1637_CATALEX::COL2); wait(delay); |
wim | 0:672ec7a524fa | 204 | |
wim | 0:672ec7a524fa | 205 | // wait(1); |
wim | 0:672ec7a524fa | 206 | // CATALEX.cls(); // clear all, preserve Icons |
wim | 0:672ec7a524fa | 207 | pc.printf("Show all icons done\r\n"); |
wim | 0:672ec7a524fa | 208 | #endif |
wim | 0:672ec7a524fa | 209 | break; |
wim | 0:672ec7a524fa | 210 | } |
wim | 0:672ec7a524fa | 211 | |
wim | 0:672ec7a524fa | 212 | case '6': { |
wim | 0:672ec7a524fa | 213 | CATALEX.cls(); // clear all, preserve Icons |
wim | 0:672ec7a524fa | 214 | |
wim | 0:672ec7a524fa | 215 | #if(1) |
wim | 0:672ec7a524fa | 216 | CATALEX.locate(0); |
wim | 0:672ec7a524fa | 217 | |
wim | 0:672ec7a524fa | 218 | for (int cnt=0; cnt<=0xFF; cnt++) { |
wim | 0:672ec7a524fa | 219 | CATALEX.locate(2); |
wim | 0:672ec7a524fa | 220 | CATALEX.printf("%02x", cnt); |
wim | 0:672ec7a524fa | 221 | wait(0.2); |
wim | 0:672ec7a524fa | 222 | } |
wim | 0:672ec7a524fa | 223 | #endif |
wim | 0:672ec7a524fa | 224 | |
wim | 0:672ec7a524fa | 225 | // CATALEX.writeData(hello_str); |
wim | 0:672ec7a524fa | 226 | // CATALEX.printf("hello"); |
wim | 0:672ec7a524fa | 227 | |
wim | 0:672ec7a524fa | 228 | break; |
wim | 0:672ec7a524fa | 229 | } |
wim | 0:672ec7a524fa | 230 | case '7': { |
wim | 0:672ec7a524fa | 231 | CATALEX.cls(); // clear all, preserve Icons |
wim | 0:672ec7a524fa | 232 | CATALEX.printf("%1.2f", -0.12); // test decimal point display |
wim | 0:672ec7a524fa | 233 | wait(0.5); |
wim | 0:672ec7a524fa | 234 | CATALEX.cls(); // clear all, preserve Icons |
wim | 0:672ec7a524fa | 235 | CATALEX.printf("%2.2f", 12.34); // test decimal point display |
wim | 0:672ec7a524fa | 236 | break; |
wim | 0:672ec7a524fa | 237 | } |
wim | 0:672ec7a524fa | 238 | |
wim | 0:672ec7a524fa | 239 | case '8': { |
wim | 0:672ec7a524fa | 240 | |
wim | 0:672ec7a524fa | 241 | #if(1) |
wim | 0:672ec7a524fa | 242 | //test to show KITT |
wim | 0:672ec7a524fa | 243 | pc.printf("Show KITT scanner\r\n"); |
wim | 0:672ec7a524fa | 244 | |
wim | 0:672ec7a524fa | 245 | |
wim | 0:672ec7a524fa | 246 | // 0123 |
wim | 0:672ec7a524fa | 247 | const char KITT[][5] = {{"8 "}, |
wim | 0:672ec7a524fa | 248 | {"38 "}, |
wim | 0:672ec7a524fa | 249 | {" 38 "}, |
wim | 0:672ec7a524fa | 250 | {" 38"}, |
wim | 0:672ec7a524fa | 251 | {" 3"}, |
wim | 0:672ec7a524fa | 252 | {" "}, |
wim | 0:672ec7a524fa | 253 | {" 8"}, |
wim | 0:672ec7a524fa | 254 | {" 8E"}, |
wim | 0:672ec7a524fa | 255 | {" 8E "}, |
wim | 0:672ec7a524fa | 256 | {"8E "}, |
wim | 0:672ec7a524fa | 257 | {"E "}, |
wim | 0:672ec7a524fa | 258 | {" "} |
wim | 0:672ec7a524fa | 259 | }; |
wim | 0:672ec7a524fa | 260 | |
wim | 0:672ec7a524fa | 261 | CATALEX.cls(); // clear all, preserve Icons |
wim | 0:672ec7a524fa | 262 | |
wim | 0:672ec7a524fa | 263 | while (!pc.readable()) { // wait for key |
wim | 0:672ec7a524fa | 264 | for (int i=0; i < (sizeof(KITT) / 5) ; i++) { |
wim | 0:672ec7a524fa | 265 | CATALEX.locate(0); |
wim | 0:672ec7a524fa | 266 | CATALEX.printf("%s", KITT[i]); |
wim | 0:672ec7a524fa | 267 | wait(0.05); |
wim | 0:672ec7a524fa | 268 | } |
wim | 0:672ec7a524fa | 269 | } |
wim | 0:672ec7a524fa | 270 | cmd = pc.getc(); // read key |
wim | 0:672ec7a524fa | 271 | pc.printf("Show KITT done\r\n"); |
wim | 0:672ec7a524fa | 272 | #endif |
wim | 0:672ec7a524fa | 273 | break; |
wim | 0:672ec7a524fa | 274 | } |
wim | 0:672ec7a524fa | 275 | |
wim | 0:672ec7a524fa | 276 | |
wim | 0:672ec7a524fa | 277 | case '9': { |
wim | 0:672ec7a524fa | 278 | |
wim | 0:672ec7a524fa | 279 | CATALEX.cls(); // clear all, preserve Icons |
wim | 0:672ec7a524fa | 280 | // CATALEX.writeData(bye_str); |
wim | 0:672ec7a524fa | 281 | CATALEX.printf("Bye"); |
wim | 0:672ec7a524fa | 282 | |
wim | 0:672ec7a524fa | 283 | break; |
wim | 0:672ec7a524fa | 284 | } |
wim | 0:672ec7a524fa | 285 | |
wim | 0:672ec7a524fa | 286 | default : { |
wim | 0:672ec7a524fa | 287 | break; |
wim | 0:672ec7a524fa | 288 | } |
wim | 0:672ec7a524fa | 289 | |
wim | 0:672ec7a524fa | 290 | } //switch cmd |
wim | 0:672ec7a524fa | 291 | |
wim | 0:672ec7a524fa | 292 | // Check and read keydata |
wim | 0:672ec7a524fa | 293 | if (CATALEX.getKeys(&keydata)) { |
wim | 0:672ec7a524fa | 294 | pc.printf("Keydata = 0x%02x\r\n", keydata); |
wim | 0:672ec7a524fa | 295 | |
wim | 0:672ec7a524fa | 296 | if (keydata == TM1637_SW9_BIT) { //sw9 |
wim | 0:672ec7a524fa | 297 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 298 | CATALEX.printf("--09"); |
wim | 0:672ec7a524fa | 299 | } |
wim | 0:672ec7a524fa | 300 | |
wim | 0:672ec7a524fa | 301 | if (keydata == TM1637_SW10_BIT) { //sw10 |
wim | 0:672ec7a524fa | 302 | CATALEX.cls(); |
wim | 0:672ec7a524fa | 303 | CATALEX.printf("--10"); |
wim | 0:672ec7a524fa | 304 | } |
wim | 0:672ec7a524fa | 305 | |
wim | 0:672ec7a524fa | 306 | } // Check keydata |
wim | 0:672ec7a524fa | 307 | |
wim | 0:672ec7a524fa | 308 | myled = !myled; |
wim | 0:672ec7a524fa | 309 | wait(0.3); |
wim | 0:672ec7a524fa | 310 | } //while |
wim | 0:672ec7a524fa | 311 | } |
wim | 0:672ec7a524fa | 312 | #endif |
wim | 0:672ec7a524fa | 313 | |
wim | 0:672ec7a524fa | 314 | |
wim | 0:672ec7a524fa | 315 | #if (TM1637_TEST == 1) |
wim | 0:672ec7a524fa | 316 | // Direct TM1637 Test |
wim | 0:672ec7a524fa | 317 | |
wim | 0:672ec7a524fa | 318 | Serial pc(USBTX, USBRX); |
wim | 0:672ec7a524fa | 319 | DigitalOut myled(LED1); |
wim | 0:672ec7a524fa | 320 | |
wim | 0:672ec7a524fa | 321 | // DisplayData_t size is 6 bytes (6 Grids @ 8 Segments) |
wim | 0:672ec7a524fa | 322 | TM1637::DisplayData_t all_str = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
wim | 0:672ec7a524fa | 323 | TM1637::DisplayData_t cls_str = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
wim | 0:672ec7a524fa | 324 | |
wim | 0:672ec7a524fa | 325 | // KeyData_t size is 1 bytes |
wim | 0:672ec7a524fa | 326 | TM1637::KeyData_t keydata; |
wim | 0:672ec7a524fa | 327 | |
wim | 0:672ec7a524fa | 328 | // TM1637 declaration |
wim | 0:672ec7a524fa | 329 | TM1637 TM1637(p5,p6,p7); |
wim | 0:672ec7a524fa | 330 | |
wim | 0:672ec7a524fa | 331 | void show_menu() { |
wim | 0:672ec7a524fa | 332 | // pc.printf("0: Exit\n\r"); |
wim | 0:672ec7a524fa | 333 | pc.printf("1: All\n\r"); |
wim | 0:672ec7a524fa | 334 | pc.printf("2: Cls\n\r"); |
wim | 0:672ec7a524fa | 335 | pc.printf("3: Show all segs\r\n"); |
wim | 0:672ec7a524fa | 336 | } |
wim | 0:672ec7a524fa | 337 | |
wim | 0:672ec7a524fa | 338 | |
wim | 0:672ec7a524fa | 339 | char cmd, bits; |
wim | 0:672ec7a524fa | 340 | int main() { |
wim | 0:672ec7a524fa | 341 | |
wim | 0:672ec7a524fa | 342 | pc.printf("Hello World\r\n"); // |
wim | 0:672ec7a524fa | 343 | |
wim | 0:672ec7a524fa | 344 | TM1637.cls(); |
wim | 0:672ec7a524fa | 345 | TM1637.writeData(all_str); |
wim | 0:672ec7a524fa | 346 | wait(2); |
wim | 0:672ec7a524fa | 347 | TM1637.setBrightness(TM1637_BRT3); |
wim | 0:672ec7a524fa | 348 | wait(1); |
wim | 0:672ec7a524fa | 349 | TM1637.setBrightness(TM1637_BRT0); |
wim | 0:672ec7a524fa | 350 | wait(1); |
wim | 0:672ec7a524fa | 351 | TM1637.setBrightness(TM1637_BRT4); |
wim | 0:672ec7a524fa | 352 | |
wim | 0:672ec7a524fa | 353 | while (1) { |
wim | 0:672ec7a524fa | 354 | |
wim | 0:672ec7a524fa | 355 | cmd = pc.getc(); |
wim | 0:672ec7a524fa | 356 | |
wim | 0:672ec7a524fa | 357 | switch (cmd) { |
wim | 0:672ec7a524fa | 358 | case '1' : |
wim | 0:672ec7a524fa | 359 | TM1637.cls(); |
wim | 0:672ec7a524fa | 360 | TM1637.writeData(all_str); |
wim | 0:672ec7a524fa | 361 | break; |
wim | 0:672ec7a524fa | 362 | |
wim | 0:672ec7a524fa | 363 | case '2' : |
wim | 0:672ec7a524fa | 364 | TM1637.cls(); |
wim | 0:672ec7a524fa | 365 | TM1637.writeData(cls_str); |
wim | 0:672ec7a524fa | 366 | break; |
wim | 0:672ec7a524fa | 367 | |
wim | 0:672ec7a524fa | 368 | case '3' : |
wim | 0:672ec7a524fa | 369 | |
wim | 0:672ec7a524fa | 370 | #if(1) |
wim | 0:672ec7a524fa | 371 | //test to show all segs |
wim | 0:672ec7a524fa | 372 | pc.printf("Show all segs\r\n"); |
wim | 0:672ec7a524fa | 373 | wait(1); |
wim | 0:672ec7a524fa | 374 | TM1637.cls(); |
wim | 0:672ec7a524fa | 375 | |
wim | 0:672ec7a524fa | 376 | for (int i=0; i<TM1637_DISPLAY_MEM; i++) { |
wim | 0:672ec7a524fa | 377 | for (int bit=0; bit<8; bit++) { |
wim | 0:672ec7a524fa | 378 | TM1637.cls(); |
wim | 0:672ec7a524fa | 379 | |
wim | 0:672ec7a524fa | 380 | bits = 0x01 << bit; |
wim | 0:672ec7a524fa | 381 | TM1637.writeData(bits, i); |
wim | 0:672ec7a524fa | 382 | |
wim | 0:672ec7a524fa | 383 | pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits); |
wim | 0:672ec7a524fa | 384 | // wait(0.5); |
wim | 0:672ec7a524fa | 385 | cmd = pc.getc(); // wait for key |
wim | 0:672ec7a524fa | 386 | } |
wim | 0:672ec7a524fa | 387 | } |
wim | 0:672ec7a524fa | 388 | pc.printf("Show all segs done\r\n"); |
wim | 0:672ec7a524fa | 389 | #endif |
wim | 0:672ec7a524fa | 390 | break; |
wim | 0:672ec7a524fa | 391 | |
wim | 0:672ec7a524fa | 392 | default : |
wim | 0:672ec7a524fa | 393 | break; |
wim | 0:672ec7a524fa | 394 | |
wim | 0:672ec7a524fa | 395 | } //switch cmd |
wim | 0:672ec7a524fa | 396 | |
wim | 0:672ec7a524fa | 397 | // Check and read keydata |
wim | 0:672ec7a524fa | 398 | if (TM1637.getKeys(&keydata)) { |
wim | 0:672ec7a524fa | 399 | pc.printf("Keydata = 0x%02x\r\n", keydata); |
wim | 0:672ec7a524fa | 400 | |
wim | 0:672ec7a524fa | 401 | if (keydata == TM1637_SW9_BIT) { //sw9 |
wim | 0:672ec7a524fa | 402 | TM1637.cls(); |
wim | 0:672ec7a524fa | 403 | TM1637.writeData(0xFF, 1); |
wim | 0:672ec7a524fa | 404 | TM1637.writeData(0xFF, 2); |
wim | 0:672ec7a524fa | 405 | } |
wim | 0:672ec7a524fa | 406 | } // Check keydata |
wim | 0:672ec7a524fa | 407 | |
wim | 0:672ec7a524fa | 408 | myled = !myled; |
wim | 0:672ec7a524fa | 409 | wait(0.3); |
wim | 0:672ec7a524fa | 410 | } //while |
wim | 0:672ec7a524fa | 411 | } |
wim | 0:672ec7a524fa | 412 | #endif |