PT6311 example code for VFDEM2 display. Initial release.

Dependencies:   PT6311 mbed

Committer:
wim
Date:
Wed Jan 20 19:08:11 2016 +0000
Revision:
0:03cde02b8371
PT6311 Example code for VFDEM2. Initial release.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:03cde02b8371 1 /* mbed PT6311 Test program, for Princeton PT6311 VFD controller
wim 0:03cde02b8371 2 * Copyright (c) 2016, v01: WH, Initial version, VFDEM2
wim 0:03cde02b8371 3 *
wim 0:03cde02b8371 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
wim 0:03cde02b8371 5 * of this software and associated documentation files (the "Software"), to deal
wim 0:03cde02b8371 6 * in the Software without restriction, including without limitation the rights
wim 0:03cde02b8371 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
wim 0:03cde02b8371 8 * copies of the Software, and to permit persons to whom the Software is
wim 0:03cde02b8371 9 * furnished to do so, subject to the following conditions:
wim 0:03cde02b8371 10 *
wim 0:03cde02b8371 11 * The above copyright notice and this permission notice shall be included in
wim 0:03cde02b8371 12 * all copies or substantial portions of the Software.
wim 0:03cde02b8371 13 *
wim 0:03cde02b8371 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
wim 0:03cde02b8371 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
wim 0:03cde02b8371 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
wim 0:03cde02b8371 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
wim 0:03cde02b8371 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
wim 0:03cde02b8371 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
wim 0:03cde02b8371 20 * THE SOFTWARE.
wim 0:03cde02b8371 21 */
wim 0:03cde02b8371 22 #include "mbed.h"
wim 0:03cde02b8371 23 #include "PT6311.h"
wim 0:03cde02b8371 24
wim 0:03cde02b8371 25 // Select one of the testboards for Princeton PT6311 VFD controller
wim 0:03cde02b8371 26
wim 0:03cde02b8371 27 #if (VFDEM2_TEST == 1)
wim 0:03cde02b8371 28 // VFDEM2 PT6311 Test
wim 0:03cde02b8371 29 #include "mbed.h"
wim 0:03cde02b8371 30 #include "PT6311.h"
wim 0:03cde02b8371 31 #include "Font_16Seg.h"
wim 0:03cde02b8371 32
wim 0:03cde02b8371 33 Serial pc(USBTX, USBRX);
wim 0:03cde02b8371 34 DigitalOut myled(LED1);
wim 0:03cde02b8371 35
wim 0:03cde02b8371 36 // DisplayData_t size is 24 bytes (8 grids @ max 20 segments) ... 48 bytes (16 grids @ max 12 segments)
wim 0:03cde02b8371 37 // DisplayData_t size for VFDEM2 is 36 bytes (12 Grids @ 16 Segments)
wim 0:03cde02b8371 38 PT6311::DisplayData_t all_str = {0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, \
wim 0:03cde02b8371 39 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, \
wim 0:03cde02b8371 40 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00, 0xFF,0xFF,0x00};
wim 0:03cde02b8371 41
wim 0:03cde02b8371 42 PT6311::DisplayData_t cls_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \
wim 0:03cde02b8371 43 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \
wim 0:03cde02b8371 44 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00};
wim 0:03cde02b8371 45
wim 0:03cde02b8371 46 PT6311::DisplayData_t bye_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \
wim 0:03cde02b8371 47 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \
wim 0:03cde02b8371 48 LO(C16_E),MD(C16_E),HI(C16_E), LO(C16_Y),MD(C16_Y),HI(C16_Y), LO(C16_B),MD(C16_B),HI(C16_B), 0x00,0x00,0x00};
wim 0:03cde02b8371 49
wim 0:03cde02b8371 50 PT6311::DisplayData_t hello_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \
wim 0:03cde02b8371 51 0x00,0x00,0x00, 0x00,0x00,0x00, LO(C16_O),MD(C16_O),HI(C16_O), LO(C16_L),MD(C16_L),HI(C16_L), \
wim 0:03cde02b8371 52 LO(C16_L),MD(C16_L),HI(C16_L), LO(C16_E),MD(C16_E),HI(C16_E), LO(C16_H),MD(C16_H),HI(C16_H), 0x00,0x00,0x00};
wim 0:03cde02b8371 53
wim 0:03cde02b8371 54 PT6311::DisplayData_t mbed_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \
wim 0:03cde02b8371 55 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, LO(C16_D),MD(C16_D),HI(C16_D), \
wim 0:03cde02b8371 56 LO(C16_E),MD(C16_E),HI(C16_E), LO(C16_B),MD(C16_B),HI(C16_B), LO(C16_M),MD(C16_M),HI(C16_M), 0x00,0x00,0x00};
wim 0:03cde02b8371 57
wim 0:03cde02b8371 58 // KeyData_t size is 3 bytes
wim 0:03cde02b8371 59 PT6311::KeyData_t keydata;
wim 0:03cde02b8371 60
wim 0:03cde02b8371 61 // Switchdata is 1 byte
wim 0:03cde02b8371 62 char switchdata;
wim 0:03cde02b8371 63
wim 0:03cde02b8371 64 //PT6311_VFDEM2 declaration, Setting 12 Grids @ 16 Segments
wim 0:03cde02b8371 65 PT6311_VFDEM2 VFDEM2(p5,p6,p7, p8);
wim 0:03cde02b8371 66
wim 0:03cde02b8371 67 char cmd, bits;
wim 0:03cde02b8371 68 int main() {
wim 0:03cde02b8371 69
wim 0:03cde02b8371 70 pc.printf("Hello World\r\n"); //
wim 0:03cde02b8371 71
wim 0:03cde02b8371 72 VFDEM2.cls();
wim 0:03cde02b8371 73 VFDEM2.writeData(all_str);
wim 0:03cde02b8371 74 wait(4);
wim 0:03cde02b8371 75 VFDEM2.setBrightness(PT6311_BRT3);
wim 0:03cde02b8371 76 wait(1);
wim 0:03cde02b8371 77 VFDEM2.setBrightness(PT6311_BRT0);
wim 0:03cde02b8371 78 wait(1);
wim 0:03cde02b8371 79 VFDEM2.setBrightness(PT6311_BRT7);
wim 0:03cde02b8371 80
wim 0:03cde02b8371 81 while (1) {
wim 0:03cde02b8371 82
wim 0:03cde02b8371 83 // Check and read keydata
wim 0:03cde02b8371 84 if (VFDEM2.getKeys(&keydata)) {
wim 0:03cde02b8371 85 pc.printf("Keydata 0..5 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4], keydata[5]);
wim 0:03cde02b8371 86
wim 0:03cde02b8371 87 if (keydata[0] == 0x01) { //K1
wim 0:03cde02b8371 88 VFDEM2.cls();
wim 0:03cde02b8371 89 VFDEM2.writeData(all_str);
wim 0:03cde02b8371 90 }
wim 0:03cde02b8371 91
wim 0:03cde02b8371 92 if (keydata[0] == 0x02) { //K2
wim 0:03cde02b8371 93 VFDEM2.cls();
wim 0:03cde02b8371 94
wim 0:03cde02b8371 95 #if(1)
wim 0:03cde02b8371 96 //test to show all segs
wim 0:03cde02b8371 97 pc.printf("Show all segs\r\n");
wim 0:03cde02b8371 98 wait(1);
wim 0:03cde02b8371 99 VFDEM2.cls();
wim 0:03cde02b8371 100
wim 0:03cde02b8371 101 for (int i=0; i<PT6311_DISPLAY_MEM; i++) {
wim 0:03cde02b8371 102 for (int bit=0; bit<8; bit++) {
wim 0:03cde02b8371 103 VFDEM2.cls();
wim 0:03cde02b8371 104
wim 0:03cde02b8371 105 bits = 0x01 << bit;
wim 0:03cde02b8371 106 VFDEM2.writeData(i, bits);
wim 0:03cde02b8371 107
wim 0:03cde02b8371 108 pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits);
wim 0:03cde02b8371 109 // wait(0.5);
wim 0:03cde02b8371 110 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 111 }
wim 0:03cde02b8371 112 }
wim 0:03cde02b8371 113 pc.printf("Show all segs done\r\n");
wim 0:03cde02b8371 114 #endif
wim 0:03cde02b8371 115 }
wim 0:03cde02b8371 116
wim 0:03cde02b8371 117
wim 0:03cde02b8371 118 if (keydata[0] == 0x04) { //K3
wim 0:03cde02b8371 119
wim 0:03cde02b8371 120 #if(0)
wim 0:03cde02b8371 121 //test to show all digits (base is 10)
wim 0:03cde02b8371 122 pc.printf("Show all digits\r\n");
wim 0:03cde02b8371 123 wait(1);
wim 0:03cde02b8371 124 VFDEM2.cls();
wim 0:03cde02b8371 125
wim 0:03cde02b8371 126 long long int val = 1;
wim 0:03cde02b8371 127 for (int i=0; i<VFDEM2_NR_DIGITS; i++) {
wim 0:03cde02b8371 128
wim 0:03cde02b8371 129 for (long long int cnt=0; cnt<10; cnt++) {
wim 0:03cde02b8371 130 VFDEM2.locate(0);
wim 0:03cde02b8371 131 VFDEM2.printf("%010lld", (val * cnt));
wim 0:03cde02b8371 132
wim 0:03cde02b8371 133 // wait(0.5);
wim 0:03cde02b8371 134 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 135 }
wim 0:03cde02b8371 136 val = val * 10;
wim 0:03cde02b8371 137 }
wim 0:03cde02b8371 138 pc.printf("Show all digits done\r\n");
wim 0:03cde02b8371 139 #endif
wim 0:03cde02b8371 140
wim 0:03cde02b8371 141 #if(1)
wim 0:03cde02b8371 142 //test to show all digits (base is 0x10)
wim 0:03cde02b8371 143 pc.printf("Show all digits\r\n");
wim 0:03cde02b8371 144 wait(1);
wim 0:03cde02b8371 145
wim 0:03cde02b8371 146 VFDEM2.cls();
wim 0:03cde02b8371 147 VFDEM2.printf("%d", 0);
wim 0:03cde02b8371 148 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 149
wim 0:03cde02b8371 150 VFDEM2.cls();
wim 0:03cde02b8371 151 VFDEM2.printf("%3.4f", 12.3456);
wim 0:03cde02b8371 152 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 153
wim 0:03cde02b8371 154 VFDEM2.cls();
wim 0:03cde02b8371 155 VFDEM2.printf("%d", 123456);
wim 0:03cde02b8371 156 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 157
wim 0:03cde02b8371 158 VFDEM2.cls();
wim 0:03cde02b8371 159 VFDEM2.printf("%010llx", 0x0123456ABCl); //Note this value needs 64bits
wim 0:03cde02b8371 160 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 161
wim 0:03cde02b8371 162 long long int val = 1;
wim 0:03cde02b8371 163 for (int i=0; i<VFDEM2_NR_DIGITS; i++) {
wim 0:03cde02b8371 164
wim 0:03cde02b8371 165 for (long long int cnt=0; cnt<0x10; cnt++) {
wim 0:03cde02b8371 166 VFDEM2.locate(0);
wim 0:03cde02b8371 167 VFDEM2.printf("%010llx", (val * cnt));
wim 0:03cde02b8371 168 // wait(0.5);
wim 0:03cde02b8371 169 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 170 }
wim 0:03cde02b8371 171 val = val * 0x10;
wim 0:03cde02b8371 172 }
wim 0:03cde02b8371 173 pc.printf("Show all digits done\r\n");
wim 0:03cde02b8371 174 #endif
wim 0:03cde02b8371 175
wim 0:03cde02b8371 176 }
wim 0:03cde02b8371 177
wim 0:03cde02b8371 178 if (keydata[0] == 0x08) { //K4
wim 0:03cde02b8371 179
wim 0:03cde02b8371 180 #if(1)
wim 0:03cde02b8371 181 //test to show all alpha chars
wim 0:03cde02b8371 182 pc.printf("Show all alpha chars\r\n");
wim 0:03cde02b8371 183 wait(1);
wim 0:03cde02b8371 184 VFDEM2.cls();
wim 0:03cde02b8371 185
wim 0:03cde02b8371 186 for (int i=0; i<26; i++) {
wim 0:03cde02b8371 187 VFDEM2.printf("%c", char(i + 'A'));
wim 0:03cde02b8371 188 // VFDEM2.printf("%c", char(i + 'a'));
wim 0:03cde02b8371 189 wait(0.25);
wim 0:03cde02b8371 190 }
wim 0:03cde02b8371 191 pc.printf("Show all alpha chars done\r\n");
wim 0:03cde02b8371 192 #endif
wim 0:03cde02b8371 193
wim 0:03cde02b8371 194 #if(0)
wim 0:03cde02b8371 195 //test to show all chars
wim 0:03cde02b8371 196 pc.printf("Show all chars\r\n");
wim 0:03cde02b8371 197 wait(1);
wim 0:03cde02b8371 198 VFDEM2.cls();
wim 0:03cde02b8371 199
wim 0:03cde02b8371 200 for (int i=FONT_16S_START; i<FONT_16S_END; i++) {
wim 0:03cde02b8371 201 VFDEM2.printf("%c", char(i));
wim 0:03cde02b8371 202 // wait(0.25);
wim 0:03cde02b8371 203 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 204 }
wim 0:03cde02b8371 205 pc.printf("Show all chars done\r\n");
wim 0:03cde02b8371 206 #endif
wim 0:03cde02b8371 207
wim 0:03cde02b8371 208 #if(1)
wim 0:03cde02b8371 209 //wheel
wim 0:03cde02b8371 210 for(int cnt=0;cnt<10;cnt++) {
wim 0:03cde02b8371 211 for(int idx=0;idx<8;idx++) {
wim 0:03cde02b8371 212 VFDEM2.setUDC(0, WHEEL_ANI[idx]);
wim 0:03cde02b8371 213 VFDEM2.locate(0);
wim 0:03cde02b8371 214 VFDEM2.printf("%c%c%c%c%c%c%c%c%c%c",(char)0,(char)0, (char)0,(char)0, (char)0,(char)0, (char)0,(char)0, (char)0,(char)0);
wim 0:03cde02b8371 215
wim 0:03cde02b8371 216 wait(0.1);
wim 0:03cde02b8371 217 }
wim 0:03cde02b8371 218 }
wim 0:03cde02b8371 219 #endif
wim 0:03cde02b8371 220
wim 0:03cde02b8371 221
wim 0:03cde02b8371 222 #if(1)
wim 0:03cde02b8371 223 float delay=0.1;
wim 0:03cde02b8371 224 // Piechart Icons on
wim 0:03cde02b8371 225 VFDEM2.setIcon(PT6311_VFDEM2::CIR); wait(delay);
wim 0:03cde02b8371 226
wim 0:03cde02b8371 227 for(int cnt=0; cnt<10; cnt++) {
wim 0:03cde02b8371 228 VFDEM2.setIcon(PT6311_VFDEM2::PIE_R);
wim 0:03cde02b8371 229 VFDEM2.clrIcon(PT6311_VFDEM2::PIE_B); wait(delay);
wim 0:03cde02b8371 230
wim 0:03cde02b8371 231 VFDEM2.setIcon(PT6311_VFDEM2::PIE_G);
wim 0:03cde02b8371 232 VFDEM2.clrIcon(PT6311_VFDEM2::PIE_R); wait(delay);
wim 0:03cde02b8371 233
wim 0:03cde02b8371 234 VFDEM2.setIcon(PT6311_VFDEM2::PIE_B);
wim 0:03cde02b8371 235 VFDEM2.clrIcon(PT6311_VFDEM2::PIE_G); wait(delay);
wim 0:03cde02b8371 236 }
wim 0:03cde02b8371 237
wim 0:03cde02b8371 238 VFDEM2.clrIcon(PT6311_VFDEM2::PIE_B); wait(delay);
wim 0:03cde02b8371 239
wim 0:03cde02b8371 240 VFDEM2.clrIcon(PT6311_VFDEM2::CIR); wait(delay);
wim 0:03cde02b8371 241
wim 0:03cde02b8371 242 wait(delay);
wim 0:03cde02b8371 243 #endif
wim 0:03cde02b8371 244
wim 0:03cde02b8371 245 VFDEM2.cls();
wim 0:03cde02b8371 246 // 0123456789
wim 0:03cde02b8371 247 VFDEM2.printf("Hello mbed");
wim 0:03cde02b8371 248 }
wim 0:03cde02b8371 249
wim 0:03cde02b8371 250 if (keydata[0] == 0x10) { //K5
wim 0:03cde02b8371 251
wim 0:03cde02b8371 252 #if(1)
wim 0:03cde02b8371 253 //test to show all icons
wim 0:03cde02b8371 254 pc.printf("Show all icons\r\n");
wim 0:03cde02b8371 255 wait(1);
wim 0:03cde02b8371 256 VFDEM2.cls(true); // Also clear all Icons
wim 0:03cde02b8371 257 wait(1);
wim 0:03cde02b8371 258
wim 0:03cde02b8371 259 float delay=0.1;
wim 0:03cde02b8371 260 VFDEM2.setIcon(PT6311_VFDEM2::STP); wait(delay);
wim 0:03cde02b8371 261 VFDEM2.setIcon(PT6311_VFDEM2::PSE); wait(delay);
wim 0:03cde02b8371 262 VFDEM2.setIcon(PT6311_VFDEM2::PLY); wait(delay);
wim 0:03cde02b8371 263 VFDEM2.setIcon(PT6311_VFDEM2::RR); wait(delay);
wim 0:03cde02b8371 264 VFDEM2.setIcon(PT6311_VFDEM2::LL); wait(delay);
wim 0:03cde02b8371 265 VFDEM2.setIcon(PT6311_VFDEM2::PCM); wait(delay);
wim 0:03cde02b8371 266 VFDEM2.setIcon(PT6311_VFDEM2::DTS); wait(delay);
wim 0:03cde02b8371 267 VFDEM2.setIcon(PT6311_VFDEM2::MIC); wait(delay);
wim 0:03cde02b8371 268 VFDEM2.setIcon(PT6311_VFDEM2::DLB); wait(delay);
wim 0:03cde02b8371 269 VFDEM2.setIcon(PT6311_VFDEM2::REC); wait(delay);
wim 0:03cde02b8371 270 VFDEM2.setIcon(PT6311_VFDEM2::PRG); wait(delay);
wim 0:03cde02b8371 271 VFDEM2.setIcon(PT6311_VFDEM2::RND); wait(delay);
wim 0:03cde02b8371 272 VFDEM2.setIcon(PT6311_VFDEM2::DP8); wait(delay);
wim 0:03cde02b8371 273 VFDEM2.setIcon(PT6311_VFDEM2::COL8); wait(delay);
wim 0:03cde02b8371 274 VFDEM2.setIcon(PT6311_VFDEM2::ANG); wait(delay);
wim 0:03cde02b8371 275 VFDEM2.setIcon(PT6311_VFDEM2::ZM); wait(delay);
wim 0:03cde02b8371 276 VFDEM2.setIcon(PT6311_VFDEM2::PBC); wait(delay);
wim 0:03cde02b8371 277 VFDEM2.setIcon(PT6311_VFDEM2::COL6); wait(delay);
wim 0:03cde02b8371 278 VFDEM2.setIcon(PT6311_VFDEM2::MP3); wait(delay);
wim 0:03cde02b8371 279 VFDEM2.setIcon(PT6311_VFDEM2::CDDA); wait(delay);
wim 0:03cde02b8371 280 VFDEM2.setIcon(PT6311_VFDEM2::SS); wait(delay);
wim 0:03cde02b8371 281 VFDEM2.setIcon(PT6311_VFDEM2::VCD); wait(delay);
wim 0:03cde02b8371 282 VFDEM2.setIcon(PT6311_VFDEM2::DVD); wait(delay);
wim 0:03cde02b8371 283 VFDEM2.setIcon(PT6311_VFDEM2::ARW); wait(delay);
wim 0:03cde02b8371 284 VFDEM2.setIcon(PT6311_VFDEM2::ONE); wait(delay);
wim 0:03cde02b8371 285 VFDEM2.setIcon(PT6311_VFDEM2::ALL); wait(delay);
wim 0:03cde02b8371 286 VFDEM2.setIcon(PT6311_VFDEM2::AA); wait(delay);
wim 0:03cde02b8371 287 VFDEM2.setIcon(PT6311_VFDEM2::BB); wait(delay);
wim 0:03cde02b8371 288 VFDEM2.setIcon(PT6311_VFDEM2::TTL); wait(delay);
wim 0:03cde02b8371 289 VFDEM2.setIcon(PT6311_VFDEM2::CHP); wait(delay);
wim 0:03cde02b8371 290 wait(delay);
wim 0:03cde02b8371 291 VFDEM2.clrIcon(PT6311_VFDEM2::STP); wait(delay);
wim 0:03cde02b8371 292 VFDEM2.clrIcon(PT6311_VFDEM2::PSE); wait(delay);
wim 0:03cde02b8371 293 VFDEM2.clrIcon(PT6311_VFDEM2::PLY); wait(delay);
wim 0:03cde02b8371 294 VFDEM2.clrIcon(PT6311_VFDEM2::RR); wait(delay);
wim 0:03cde02b8371 295 VFDEM2.clrIcon(PT6311_VFDEM2::LL); wait(delay);
wim 0:03cde02b8371 296 VFDEM2.clrIcon(PT6311_VFDEM2::PCM); wait(delay);
wim 0:03cde02b8371 297 VFDEM2.clrIcon(PT6311_VFDEM2::DTS); wait(delay);
wim 0:03cde02b8371 298 VFDEM2.clrIcon(PT6311_VFDEM2::MIC); wait(delay);
wim 0:03cde02b8371 299 VFDEM2.clrIcon(PT6311_VFDEM2::DLB); wait(delay);
wim 0:03cde02b8371 300 VFDEM2.clrIcon(PT6311_VFDEM2::REC); wait(delay);
wim 0:03cde02b8371 301 VFDEM2.clrIcon(PT6311_VFDEM2::PRG); wait(delay);
wim 0:03cde02b8371 302 VFDEM2.clrIcon(PT6311_VFDEM2::RND); wait(delay);
wim 0:03cde02b8371 303 VFDEM2.clrIcon(PT6311_VFDEM2::DP8); wait(delay);
wim 0:03cde02b8371 304 VFDEM2.clrIcon(PT6311_VFDEM2::COL8); wait(delay);
wim 0:03cde02b8371 305 VFDEM2.clrIcon(PT6311_VFDEM2::ANG); wait(delay);
wim 0:03cde02b8371 306 VFDEM2.clrIcon(PT6311_VFDEM2::ZM); wait(delay);
wim 0:03cde02b8371 307 VFDEM2.clrIcon(PT6311_VFDEM2::PBC); wait(delay);
wim 0:03cde02b8371 308 VFDEM2.clrIcon(PT6311_VFDEM2::COL6); wait(delay);
wim 0:03cde02b8371 309 VFDEM2.clrIcon(PT6311_VFDEM2::MP3); wait(delay);
wim 0:03cde02b8371 310 VFDEM2.clrIcon(PT6311_VFDEM2::CDDA); wait(delay);
wim 0:03cde02b8371 311 VFDEM2.clrIcon(PT6311_VFDEM2::SS); wait(delay);
wim 0:03cde02b8371 312 VFDEM2.clrIcon(PT6311_VFDEM2::VCD); wait(delay);
wim 0:03cde02b8371 313 VFDEM2.clrIcon(PT6311_VFDEM2::DVD); wait(delay);
wim 0:03cde02b8371 314 VFDEM2.clrIcon(PT6311_VFDEM2::ARW); wait(delay);
wim 0:03cde02b8371 315 VFDEM2.clrIcon(PT6311_VFDEM2::ONE); wait(delay);
wim 0:03cde02b8371 316 VFDEM2.clrIcon(PT6311_VFDEM2::ALL); wait(delay);
wim 0:03cde02b8371 317 VFDEM2.clrIcon(PT6311_VFDEM2::AA); wait(delay);
wim 0:03cde02b8371 318 VFDEM2.clrIcon(PT6311_VFDEM2::BB); wait(delay);
wim 0:03cde02b8371 319 VFDEM2.clrIcon(PT6311_VFDEM2::TTL); wait(delay);
wim 0:03cde02b8371 320 VFDEM2.clrIcon(PT6311_VFDEM2::CHP); wait(delay);
wim 0:03cde02b8371 321
wim 0:03cde02b8371 322 wait(1);
wim 0:03cde02b8371 323 VFDEM2.cls(); // clear all, preserve Icons
wim 0:03cde02b8371 324 pc.printf("Show all icons done\r\n");
wim 0:03cde02b8371 325 #endif
wim 0:03cde02b8371 326 }
wim 0:03cde02b8371 327
wim 0:03cde02b8371 328 if (keydata[0] == 0x20) { //K6
wim 0:03cde02b8371 329 //write LEDs off
wim 0:03cde02b8371 330 VFDEM2.setLED(0x01);
wim 0:03cde02b8371 331 }
wim 0:03cde02b8371 332
wim 0:03cde02b8371 333 if (keydata[0] == 0x40) { //K7
wim 0:03cde02b8371 334 //write LEDs on
wim 0:03cde02b8371 335 VFDEM2.setLED(0x00);
wim 0:03cde02b8371 336 }
wim 0:03cde02b8371 337
wim 0:03cde02b8371 338 } //if Key
wim 0:03cde02b8371 339
wim 0:03cde02b8371 340
wim 0:03cde02b8371 341 // Check and read switch data (not supported on VFDEM2)
wim 0:03cde02b8371 342 switchdata = VFDEM2.getSwitches();
wim 0:03cde02b8371 343
wim 0:03cde02b8371 344 if (switchdata != 0) {
wim 0:03cde02b8371 345 pc.printf("Switchdata = 0x%02x\r\n", switchdata);
wim 0:03cde02b8371 346
wim 0:03cde02b8371 347 if (switchdata == PT6311_SW1) { //S1
wim 0:03cde02b8371 348 VFDEM2.cls();
wim 0:03cde02b8371 349 VFDEM2.writeData(hello_str);
wim 0:03cde02b8371 350 }
wim 0:03cde02b8371 351
wim 0:03cde02b8371 352 if (switchdata == PT6311_SW2) { //S2
wim 0:03cde02b8371 353 VFDEM2.cls();
wim 0:03cde02b8371 354 VFDEM2.writeData(bye_str);
wim 0:03cde02b8371 355 }
wim 0:03cde02b8371 356
wim 0:03cde02b8371 357 if (switchdata == PT6311_SW3) { //S3
wim 0:03cde02b8371 358 VFDEM2.cls();
wim 0:03cde02b8371 359 VFDEM2.writeData(mbed_str);
wim 0:03cde02b8371 360 }
wim 0:03cde02b8371 361
wim 0:03cde02b8371 362 VFDEM2.setLED(switchdata); //write LEDs in same pattern
wim 0:03cde02b8371 363 } //if Switch
wim 0:03cde02b8371 364
wim 0:03cde02b8371 365
wim 0:03cde02b8371 366 myled = !myled;
wim 0:03cde02b8371 367 wait(0.3);
wim 0:03cde02b8371 368 } //while
wim 0:03cde02b8371 369 }
wim 0:03cde02b8371 370 #endif
wim 0:03cde02b8371 371
wim 0:03cde02b8371 372
wim 0:03cde02b8371 373 #if(PT6311_TEST == 1)
wim 0:03cde02b8371 374 // Direct PT6311 Test
wim 0:03cde02b8371 375 #include "mbed.h"
wim 0:03cde02b8371 376 #include "PT6311.h"
wim 0:03cde02b8371 377
wim 0:03cde02b8371 378 Serial pc(USBTX, USBRX);
wim 0:03cde02b8371 379 DigitalOut myled(LED1);
wim 0:03cde02b8371 380
wim 0:03cde02b8371 381 // DisplayData_t size is 24 bytes (8 digits @ max 20 segments) ... 48 bytes (16 digits @ max 12 segments)
wim 0:03cde02b8371 382 // DisplayData_t size default is 48 bytes (16 Grids @ 12 Segments)
wim 0:03cde02b8371 383 PT6311::DisplayData_t all_str = {0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, \
wim 0:03cde02b8371 384 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, \
wim 0:03cde02b8371 385 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, \
wim 0:03cde02b8371 386 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00, 0xFF,0x0F,0x00};
wim 0:03cde02b8371 387
wim 0:03cde02b8371 388 PT6311::DisplayData_t cls_str = {0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \
wim 0:03cde02b8371 389 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, \
wim 0:03cde02b8371 390 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x00};
wim 0:03cde02b8371 391
wim 0:03cde02b8371 392 // KeyData_t size is 6 bytes
wim 0:03cde02b8371 393 PT6311::KeyData_t keydata;
wim 0:03cde02b8371 394
wim 0:03cde02b8371 395 // Switchdata is 1 byte
wim 0:03cde02b8371 396 char switchdata;
wim 0:03cde02b8371 397
wim 0:03cde02b8371 398 PT6311 PT6311(p5,p6,p7, p8);
wim 0:03cde02b8371 399 //PT6311 PT6311(p5,p6,p7, p8, PT6311::Grid16_Seg12);
wim 0:03cde02b8371 400
wim 0:03cde02b8371 401 char cmd, bits;
wim 0:03cde02b8371 402 int main() {
wim 0:03cde02b8371 403
wim 0:03cde02b8371 404 pc.printf("Hello World\r\n"); //
wim 0:03cde02b8371 405
wim 0:03cde02b8371 406 PT6311.cls();
wim 0:03cde02b8371 407 PT6311.writeData(all_str);
wim 0:03cde02b8371 408 wait(4);
wim 0:03cde02b8371 409 PT6311.setBrightness(PT6311_BRT3);
wim 0:03cde02b8371 410 wait(1);
wim 0:03cde02b8371 411 PT6311.setBrightness(PT6311_BRT0);
wim 0:03cde02b8371 412 wait(1);
wim 0:03cde02b8371 413 PT6311.setBrightness(PT6311_BRT7);
wim 0:03cde02b8371 414
wim 0:03cde02b8371 415 while (1) {
wim 0:03cde02b8371 416
wim 0:03cde02b8371 417 // Check and read keydata
wim 0:03cde02b8371 418 if (PT6311.getKeys(&keydata)) {
wim 0:03cde02b8371 419 pc.printf("Keydata 0..5 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4], keydata[5]);
wim 0:03cde02b8371 420
wim 0:03cde02b8371 421 if (keydata[0] == 0x01) { //play
wim 0:03cde02b8371 422 PT6311.cls();
wim 0:03cde02b8371 423 PT6311.writeData(all_str);
wim 0:03cde02b8371 424 }
wim 0:03cde02b8371 425
wim 0:03cde02b8371 426 if (keydata[0] == 0x02) { //stop
wim 0:03cde02b8371 427 PT6311.cls();
wim 0:03cde02b8371 428 PT6311.writeData(cls_str);
wim 0:03cde02b8371 429 }
wim 0:03cde02b8371 430
wim 0:03cde02b8371 431 if (keydata[0] == 0x04) { //open/close
wim 0:03cde02b8371 432 PT6311.cls();
wim 0:03cde02b8371 433 PT6311.writeData(all_str);
wim 0:03cde02b8371 434
wim 0:03cde02b8371 435 #if(1)
wim 0:03cde02b8371 436 //test to show all segs
wim 0:03cde02b8371 437 pc.printf("Show all segs\r\n");
wim 0:03cde02b8371 438 wait(1);
wim 0:03cde02b8371 439 PT6311.cls();
wim 0:03cde02b8371 440
wim 0:03cde02b8371 441 for (int i=0; i<PT6311_DISPLAY_MEM; i++) {
wim 0:03cde02b8371 442 for (int bit=0; bit<8; bit++) {
wim 0:03cde02b8371 443 PT6311.cls();
wim 0:03cde02b8371 444
wim 0:03cde02b8371 445 bits = 0x01 << bit;
wim 0:03cde02b8371 446 PT6311.writeData(i, bits);
wim 0:03cde02b8371 447
wim 0:03cde02b8371 448 pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits);
wim 0:03cde02b8371 449 // wait(0.5);
wim 0:03cde02b8371 450 cmd = pc.getc(); // wait for key
wim 0:03cde02b8371 451 }
wim 0:03cde02b8371 452 }
wim 0:03cde02b8371 453 pc.printf("Show all segs done\r\n");
wim 0:03cde02b8371 454 #endif
wim 0:03cde02b8371 455
wim 0:03cde02b8371 456 }
wim 0:03cde02b8371 457
wim 0:03cde02b8371 458 } //if Key
wim 0:03cde02b8371 459
wim 0:03cde02b8371 460
wim 0:03cde02b8371 461 // Check and read switch data
wim 0:03cde02b8371 462 switchdata = PT6311.getSwitches();
wim 0:03cde02b8371 463
wim 0:03cde02b8371 464 if (switchdata != 0) {
wim 0:03cde02b8371 465 pc.printf("Switchdata = 0x%02x\r\n", switchdata);
wim 0:03cde02b8371 466
wim 0:03cde02b8371 467 if (switchdata == PT6311_SW1) { //S1
wim 0:03cde02b8371 468 PT6311.cls();
wim 0:03cde02b8371 469 PT6311.writeData(all_str);
wim 0:03cde02b8371 470 }
wim 0:03cde02b8371 471
wim 0:03cde02b8371 472 if (switchdata == PT6311_SW2) { //S2
wim 0:03cde02b8371 473 PT6311.cls();
wim 0:03cde02b8371 474 PT6311.writeData(cls_str);
wim 0:03cde02b8371 475 }
wim 0:03cde02b8371 476
wim 0:03cde02b8371 477 if (switchdata == PT6311_SW3) { //S3
wim 0:03cde02b8371 478 PT6311.cls();
wim 0:03cde02b8371 479 PT6311.writeData(all_str);
wim 0:03cde02b8371 480 }
wim 0:03cde02b8371 481
wim 0:03cde02b8371 482 PT6311.setLED(switchdata); //write LEDs in same pattern
wim 0:03cde02b8371 483 } //if Switch
wim 0:03cde02b8371 484
wim 0:03cde02b8371 485
wim 0:03cde02b8371 486 myled = !myled;
wim 0:03cde02b8371 487 wait(0.3);
wim 0:03cde02b8371 488 } //while
wim 0:03cde02b8371 489 }
wim 0:03cde02b8371 490 #endif