Wim Huiskamp / Mbed 2 deprecated mbed_CU209SCPB_T20

Dependencies:   CU209SCPB mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed CU209SCPB Test program for Noritake Itron CU209SCPB VFD module
00002  *
00003  * Copyright (c) 2017, v01: WH, Initial version
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy
00006  * of this software and associated documentation files (the "Software"), to deal
00007  * in the Software without restriction, including without limitation the rights
00008  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009  * copies of the Software, and to permit persons to whom the Software is
00010  * furnished to do so, subject to the following conditions:
00011  *
00012  * The above copyright notice and this permission notice shall be included in
00013  * all copies or substantial portions of the Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021  * THE SOFTWARE.
00022  */
00023 #include "mbed.h"
00024 #include "CU209SCPB.h"
00025 
00026 DigitalOut myled(LED1);
00027 Serial pc(USBTX, USBRX);
00028 
00029 CU209SCPB CU209SCPB(p9);
00030 //CU209SCPB CU209SCPB(p13);
00031 
00032 void show_menu() {
00033 //    pc.printf("0:   Exit\n\r");
00034     pc.printf("1:   All\n\r");    
00035     pc.printf("2:   Show UDC chars\n\r");    
00036     pc.printf("3:   Show all chars\n\r");
00037     pc.printf("4:   Show all digits\n\r");    
00038     pc.printf("6:   Counter\n\r");
00039     pc.printf("7:   Floats\n\r");
00040     pc.printf("8:   Kitt\n\r");
00041     pc.printf("9:   Cls\n\r");
00042     pc.printf("A/B: Cursor On/Off\n\r");
00043     pc.printf("C:   Bye\n\r");
00044 }
00045 
00046 
00047 int main() {
00048   pc.printf("Hello World: CU209SCPB test\n\r");
00049 
00050   CU209SCPB.locate(0);    
00051   CU209SCPB.printf("Hello mbed");    
00052 
00053   CU209SCPB.setBrightness(CU209SCPB_BRT_3);
00054   wait(1);  
00055   CU209SCPB.setBrightness(CU209SCPB_BRT_0);
00056   wait(1);  
00057   CU209SCPB.setBrightness(CU209SCPB_BRT_DEF);
00058   wait(1);
00059 
00060     char cmd, cmd2 = '0';
00061     while (1) {
00062       
00063       show_menu();
00064       cmd2 = pc.getc();
00065 
00066       switch (cmd2) {
00067         case '1' : {
00068                       pc.printf("all\r\n");
00069                       CU209SCPB.cls(); 
00070                       CU209SCPB.printf("Hello mbed");
00071                       break;
00072         }
00073 
00074 
00075         case '2' : {
00076                       pc.printf("UDC\r\n");
00077                       CU209SCPB.cls();
00078                      
00079                       // Store UDC_idx=0, 1 
00080                       CU209SCPB.setUDC(0, (char *) udc_LAR); // Left Arrow
00081                       CU209SCPB.setUDC(1, (char *) udc_RAR); // Right Arrow                      
00082 
00083                       // Show UDC_idx=0, 1 
00084                       CU209SCPB.locate(0);
00085                       CU209SCPB.putc((char) 0);
00086                       CU209SCPB.putc((char) 1);                      
00087                     
00088                       break;
00089         }
00090 
00091         case '3' : {
00092 #if(1)
00093 //test to show all chars
00094           pc.printf("Show all alpha chars\r\n");
00095           wait(1);          
00096           CU209SCPB.cls(); 
00097          
00098           for (int i=0; i<26; i++) {
00099             CU209SCPB.printf("%c", char(i + 'A'));
00100             CU209SCPB.printf("%c", char(i + 'a'));            
00101             wait(0.25);                      
00102           }
00103           pc.printf("Show all alpha chars done\r\n");                    
00104 #endif            
00105           break;          
00106         }
00107 
00108         case '4': {
00109 #if(0)
00110 //test to show all digits (base is 10)
00111           pc.printf("Show all digits\r\n");
00112           wait(1);          
00113           CU209SCPB.cls(); 
00114 
00115           for (int i=0; i<CU209SCPB_NR_COLS; i++) {
00116 
00117             for (int cnt=0; cnt<10; cnt++) {
00118               CU209SCPB.locate(i);
00119               CU209SCPB.printf("%0d", cnt);
00120 
00121 //              wait(0.5);
00122               cmd = pc.getc(); // wait for key
00123             }  
00124           }
00125           pc.printf("\r\nShow all digits done\r\n");                    
00126 #endif                
00127 
00128 #if(1)
00129 //test to show all digits (base is 0x10)
00130           pc.printf("Show all hex digits\r\n");
00131           wait(1);          
00132           CU209SCPB.cls(); 
00133 
00134           CU209SCPB.printf("%010X", 0x0123ABCDEF);
00135           cmd = pc.getc(); // wait for key
00136           CU209SCPB.locate(0);          
00137           CU209SCPB.printf("%020X", 0x0);
00138                     
00139           for (int i=0; i<CU209SCPB_NR_COLS; i++) {
00140 //          for (int i=0; i<1; i++) {
00141 
00142             for (int cnt=0; cnt<0x10; cnt++) {
00143               CU209SCPB.locate(i);
00144               CU209SCPB.printf("%0X", cnt);
00145 //              pc.printf("%0X", cnt);              
00146 //              wait(0.5);
00147               cmd = pc.getc(); // wait for key
00148             }  
00149           }
00150           pc.printf("\r\nShow all hex digits done\r\n");          
00151 #endif                
00152           break;          
00153         }
00154         
00155         case '5':  { 
00156           break;
00157         }                          
00158 
00159         case '6': {
00160           pc.printf("Show counter\r\n");          
00161           CU209SCPB.cls(); // clear all, preserve Icons
00162 
00163 #if(1)
00164           CU209SCPB.locate(0);
00165           CU209SCPB.printf("Cnt=");
00166           for (int cnt=0; cnt<=0xFF; cnt++) {
00167             CU209SCPB.locate(8);
00168             CU209SCPB.printf("%02X", cnt);           
00169             wait(0.2);
00170           }  
00171 #endif
00172           break;          
00173         }
00174 
00175         case '7': {
00176           pc.printf("Show floats\r\n");
00177           
00178           CU209SCPB.cls(); // clear all, preserve Icons
00179           CU209SCPB.printf("%1.7f", -0.1234567);  // test decimal point display
00180           wait(0.5);
00181           CU209SCPB.cls(); // clear all, preserve Icons          
00182           CU209SCPB.printf("%3.6f", 123.456789);  // test decimal point display
00183           break;          
00184         }
00185 
00186         case '8': {
00187 
00188 #if(1)
00189 //test to show KITT
00190           pc.printf("Show KITT scanner\r\n");
00191           
00192 //                          0123456789
00193 const char KITT[][11]  = {{"8         "},
00194                           {"38        "},
00195                           {" 38       "},
00196                           {"  38      "},
00197                           {"   38     "},
00198                           {"    38    "},
00199                           {"     38   "},
00200                           {"      38  "},
00201                           {"       38 "},
00202                           {"        38"},
00203                           {"         3"},
00204                           {"          "},
00205                           {"         8"},
00206                           {"        8E"},
00207                           {"       8E "},
00208                           {"      8E  "},
00209                           {"     8E   "},
00210                           {"    8E    "},                                                                              
00211                           {"   8E     "},
00212                           {"  8E      "},
00213                           {" 8E       "},
00214                           {"8E        "},
00215                           {"E         "},
00216                           {"          "}
00217                         };     
00218          
00219           CU209SCPB.cls(); // clear all, preserve Icons
00220           
00221           while (!pc.readable()) { // wait for key            
00222             for (int i=0; i < (sizeof(KITT) / 11) ; i++) {
00223               CU209SCPB.locate(0);
00224               CU209SCPB.printf("%s", KITT[i]);
00225               wait(0.1);
00226             }
00227           }
00228           cmd = pc.getc(); // read key           
00229           pc.printf("Show KITT done\r\n");
00230 #endif
00231           break;
00232         }  
00233 
00234         case '9': {
00235           CU209SCPB.cls(); // clear all
00236           break;
00237         }  
00238 
00239         case 'A': {
00240           pc.printf("Cursor On\r\n");
00241           CU209SCPB.setCursor(true);          
00242           break;
00243         } 
00244 
00245         case 'B': {
00246           pc.printf("Cursor Off\r\n");
00247           CU209SCPB.setCursor(false);          
00248           break;
00249         } 
00250 
00251         case 'C': {
00252           CU209SCPB.cls(); // clear all
00253           CU209SCPB.printf("Bye");          
00254        
00255           break;
00256         } 
00257 
00258         default : {
00259           break;
00260         }         
00261      
00262       } //switch cmd
00263 
00264     myled = !myled;
00265     wait(0.3);
00266   }
00267 }
00268