Test program fro TM1637 LEDController Library, Initial release.

Dependencies:   TM1637 mbed

See here for more information.

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Sat Jan 30 20:36:52 2016 +0000
Child:
1:0dab5786c471
Commit message:
Test program for TM1637 LEDcontroller Library, ; Initial release.

Changed in this revision

TM1637.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TM1637.lib	Sat Jan 30 20:36:52 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/wim/code/TM1637/#dc8789a6e21f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 30 20:36:52 2016 +0000
@@ -0,0 +1,412 @@
+/* mbed TM1637 Test program, for TM1637 LED controller
+ * Copyright (c) 2016, v01: WH, Initial version
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "mbed.h"
+#include "TM1637.h"
+
+#if (CATALEX_TEST == 1)
+// CATALEX TM1637 Test
+#include "Font_7Seg.h"
+
+Serial pc(USBTX, USBRX);
+DigitalOut myled(LED1);
+
+// DisplayData_t size is 4 bytes (4 Grids @ 8 Segments) 
+TM1637::DisplayData_t all_str   = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};  
+TM1637::DisplayData_t cls_str   = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};  
+TM1637::DisplayData_t hello_str = {C7_H, C7_I, 0x00, 0x00, 0x00, 0x00};
+TM1637::DisplayData_t bye_str   = {C7_B, C7_Y, C7_E, 0x00, 0x00, 0x00};
+
+// KeyData_t size is 1 bytes  
+TM1637::KeyData_t keydata; 
+
+//TM1637_CATALEX declaration
+TM1637_CATALEX CATALEX(p5, p6, p7);
+
+
+void show_menu() {
+//    pc.printf("0:   Exit\n\r");
+    pc.printf("1:   All\n\r");    
+    pc.printf("2:   Show all segs\r\n");
+    pc.printf("3:   Show all chars\n\r");
+    pc.printf("4:   Show all digits\n\r");
+    pc.printf("5:   Show all icons\n\r");
+    pc.printf("6:   Counter\n\r");
+    pc.printf("7:   Floats\n\r");
+    pc.printf("8:   Kitt\n\r");
+    pc.printf("9:   Bye\n\r");    
+}
+
+
+char cmd, bits;
+int main() {
+    
+    pc.printf("Hello World\r\n"); //    
+    
+    CATALEX.cls(); 
+    CATALEX.writeData(all_str);
+    wait(2);
+    CATALEX.setBrightness(TM1637_BRT3);    
+    wait(1);
+    CATALEX.setBrightness(TM1637_BRT0);        
+    wait(1);
+    CATALEX.setBrightness(TM1637_BRT4);            
+
+    wait(1);
+    CATALEX.cls(true); 
+    CATALEX.writeData(hello_str); 
+    
+    char cmd2 = '0';
+    while (1) {
+      
+      show_menu();
+      cmd2 = pc.getc();
+
+      switch (cmd2) {
+        case '1' : {
+                      pc.printf("all\r\n");
+                      CATALEX.cls(); 
+                      CATALEX.writeData(all_str);
+                      break;
+        }
+
+        case '2' : {
+#if(1)
+//test to show all segs
+          pc.printf("Show all segs\r\n");
+          wait(1);          
+          CATALEX.cls(); 
+         
+          for (int i=0; i<TM1637_DISPLAY_MEM; i++) {            
+            for (int bit=0; bit<8; bit++) {
+              CATALEX.cls(); 
+
+              bits = 0x01 << bit;              
+              CATALEX.writeData(bits, i);
+
+              pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits);              
+//              wait(0.5);
+              cmd = pc.getc(); // wait for key
+            }  
+          }
+          pc.printf("\r\nShow all segs done\r\n");                    
+#endif 
+          break;          
+        }
+
+        case '3' : {
+
+#if(1)
+//test to show all chars
+          pc.printf("Show all alpha chars\r\n");
+          wait(1);          
+          CATALEX.cls(); 
+         
+          for (int i=0; i<26; i++) {
+            CATALEX.printf("%c", char(i + 'A'));
+//            CATALEX.printf("%c", char(i + 'a'));            
+            wait(0.25);                      
+          }
+          pc.printf("Show all alpha chars done\r\n");                    
+#endif            
+
+#if(0)
+//test to show all chars
+          pc.printf("Show all chars\r\n");
+          wait(1);          
+          CATALEX.cls(); 
+
+          for (int i=FONT_7S_START; i<FONT_7S_END; i++) {
+            CATALEX.printf("%c", char(i));
+//            wait(0.25);
+            cmd = pc.getc(); // wait for key            
+          }
+          pc.printf("Show all chars done\r\n");                    
+#endif            
+          break;          
+        }
+        case '4': {
+#if(0)
+//test to show all digits (base is 10)
+          pc.printf("Show all digits\r\n");
+          wait(1);          
+          CATALEX.cls(); 
+
+          for (int i=0; i<CATALEX_NR_DIGITS; i++) {
+
+            for (int cnt=0; cnt<10; cnt++) {
+              CATALEX.locate(i);
+              CATALEX.printf("%0d", cnt);
+
+//              wait(0.5);
+              cmd = pc.getc(); // wait for key
+            }  
+          }
+          pc.printf("\r\nShow all digits done\r\n");                    
+#endif                
+
+#if(1)
+//test to show all digits (base is 0x10)
+          pc.printf("Show all hex digits\r\n");
+          wait(1);          
+          CATALEX.cls(); 
+
+          CATALEX.printf("%04x", 0x01AB);
+          cmd = pc.getc(); // wait for key                                     
+          CATALEX.printf("%04x", 0x0);
+                    
+          for (int i=0; i<CATALEX_NR_DIGITS; i++) {
+
+            for (int cnt=0; cnt<0x10; cnt++) {
+              CATALEX.locate(i);
+              CATALEX.printf("%0x", cnt);
+
+//              wait(0.5);
+              cmd = pc.getc(); // wait for key
+            }  
+          }
+          pc.printf("\r\nShow all hex digits done\r\n");          
+#endif                
+          break;          
+        }
+        case '5':  { 
+#if(1)
+//test to show all icons
+          pc.printf("Show all icons\r\n");
+          CATALEX.cls(true); // Also clear all Icons
+          
+          float delay=0.1;
+          // Icons on             
+          CATALEX.setIcon(TM1637_CATALEX::COL2); wait(delay);
+
+          wait(delay);
+ 
+          // Icons off      
+          CATALEX.clrIcon(TM1637_CATALEX::COL2); wait(delay);
+
+//          wait(1);          
+//          CATALEX.cls(); // clear all, preserve Icons
+          pc.printf("Show all icons done\r\n");                    
+#endif           
+          break;
+        }                          
+
+        case '6': {
+          CATALEX.cls(); // clear all, preserve Icons
+
+#if(1)
+          CATALEX.locate(0);
+         
+          for (int cnt=0; cnt<=0xFF; cnt++) {
+            CATALEX.locate(2);
+            CATALEX.printf("%02x", cnt);           
+            wait(0.2);
+          }  
+#endif
+
+//          CATALEX.writeData(hello_str);
+//          CATALEX.printf("hello");                  
+
+          break;          
+        }
+        case '7': {
+          CATALEX.cls(); // clear all, preserve Icons
+          CATALEX.printf("%1.2f", -0.12);  // test decimal point display                    
+          wait(0.5);
+          CATALEX.cls(); // clear all, preserve Icons          
+          CATALEX.printf("%2.2f", 12.34);  // test decimal point display
+          break;          
+        }
+
+        case '8': {
+
+#if(1)
+//test to show KITT
+          pc.printf("Show KITT scanner\r\n");
+
+          
+//                          0123
+const char KITT[][5]   = {{"8   "},
+                          {"38  "},
+                          {" 38 "},
+                          {"  38"},
+                          {"   3"},
+                          {"    "},
+                          {"   8"},
+                          {"  8E"},
+                          {" 8E "},
+                          {"8E  "},
+                          {"E   "},
+                          {"    "}
+                        };     
+         
+          CATALEX.cls(); // clear all, preserve Icons
+          
+          while (!pc.readable()) { // wait for key            
+            for (int i=0; i < (sizeof(KITT) / 5) ; i++) {
+              CATALEX.locate(0);
+              CATALEX.printf("%s", KITT[i]);
+              wait(0.05);
+            }
+          }
+          cmd = pc.getc(); // read key           
+          pc.printf("Show KITT done\r\n");
+#endif
+          break;
+        }  
+
+
+        case '9': {
+
+          CATALEX.cls(); // clear all, preserve Icons
+//          CATALEX.writeData(bye_str);
+          CATALEX.printf("Bye");          
+       
+          break;
+        }  
+
+        default : {
+          break;
+        }         
+     
+      } //switch cmd
+
+      // Check and read keydata
+      if (CATALEX.getKeys(&keydata)) {
+        pc.printf("Keydata = 0x%02x\r\n", keydata);
+
+        if (keydata == TM1637_SW9_BIT) { //sw9  
+          CATALEX.cls(); 
+          CATALEX.printf("--09");
+        }  
+
+        if (keydata == TM1637_SW10_BIT) { //sw10  
+          CATALEX.cls(); 
+          CATALEX.printf("--10");          
+        }  
+
+      } // Check keydata
+
+      myled = !myled;
+      wait(0.3);      
+    } //while
+}
+#endif
+
+
+#if (TM1637_TEST == 1)
+// Direct TM1637 Test
+
+Serial pc(USBTX, USBRX);
+DigitalOut myled(LED1);
+
+// DisplayData_t size is 6 bytes (6 Grids @ 8 Segments) 
+TM1637::DisplayData_t all_str   = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};  
+TM1637::DisplayData_t cls_str   = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};  
+
+// KeyData_t size is 1 bytes  
+TM1637::KeyData_t keydata; 
+
+// TM1637 declaration
+TM1637 TM1637(p5,p6,p7);
+
+void show_menu() {
+//    pc.printf("0:   Exit\n\r");
+    pc.printf("1:   All\n\r");    
+    pc.printf("2:   Cls\n\r");        
+    pc.printf("3:   Show all segs\r\n");
+}
+
+
+char cmd, bits;
+int main() {
+    
+    pc.printf("Hello World\r\n"); //    
+    
+    TM1637.cls(); 
+    TM1637.writeData(all_str);
+    wait(2);
+    TM1637.setBrightness(TM1637_BRT3);    
+    wait(1);
+    TM1637.setBrightness(TM1637_BRT0);        
+    wait(1);
+    TM1637.setBrightness(TM1637_BRT4);            
+    
+    while (1) {
+     
+      cmd = pc.getc();
+
+      switch (cmd) {
+        case '1' : 
+          TM1637.cls(); 
+          TM1637.writeData(all_str);
+         break;    
+               
+        case '2' :       
+          TM1637.cls(); 
+          TM1637.writeData(cls_str);
+         break;    
+               
+        case '3' :
+
+#if(1)
+//test to show all segs
+          pc.printf("Show all segs\r\n");
+          wait(1);          
+          TM1637.cls(); 
+         
+          for (int i=0; i<TM1637_DISPLAY_MEM; i++) {            
+            for (int bit=0; bit<8; bit++) {
+              TM1637.cls(); 
+
+              bits = 0x01 << bit;              
+              TM1637.writeData(bits, i);
+
+              pc.printf("Idx = %d, Bits = 0x%02x\r\n", i, bits);              
+//              wait(0.5);
+              cmd = pc.getc(); // wait for key
+            }  
+          }
+          pc.printf("Show all segs done\r\n");                    
+#endif 
+         break;    
+                       
+        default : 
+          break;          
+     
+      } //switch cmd
+
+      // Check and read keydata
+      if (TM1637.getKeys(&keydata)) {
+        pc.printf("Keydata = 0x%02x\r\n", keydata);
+ 
+        if (keydata == TM1637_SW9_BIT) { //sw9  
+          TM1637.cls(); 
+          TM1637.writeData(0xFF, 1);
+          TM1637.writeData(0xFF, 2);          
+        }  
+      } // Check keydata
+
+      myled = !myled;
+      wait(0.3);      
+    } //while
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Jan 30 20:36:52 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file