Test program for TM1638 LED controller. Supports LED&KEY, QYF-TM1638 and JY-LKM1638 module.

Dependencies:   TM1638 mbed

See here for more information.

Files at this revision

API Documentation at this revision

Comitter:
wim
Date:
Sat Jan 09 14:34:16 2016 +0000
Parent:
0:e7bc81df3e38
Child:
2:d6720abfe574
Commit message:
Test program for TM1638 LED controller. Supports LED&KEY module

Changed in this revision

TM1638.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
--- a/TM1638.lib	Mon Dec 21 22:39:38 2015 +0000
+++ b/TM1638.lib	Sat Jan 09 14:34:16 2016 +0000
@@ -1,1 +1,1 @@
-TM1638#201dfacbe0e5
+https://developer.mbed.org/users/wim/code/TM1638/#1f2453ed85d7
--- a/main.cpp	Mon Dec 21 22:39:38 2015 +0000
+++ b/main.cpp	Sat Jan 09 14:34:16 2016 +0000
@@ -1,4 +1,4 @@
-/* mbed TM1638 Test program, for TM1628 LED controller
+/* mbed TM1638 Test program, for TM1638 LED controller
  * Copyright (c) 2015, v01: WH, Initial version
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -33,6 +33,7 @@
 TM1638::DisplayData_t all_str   = {0xFF,0x03, 0xFF,0x03, 0xFF,0x03, 0xFF,0x03, 0xFF,0x03, 0xFF,0x03, 0xFF,0x03, 0xFF,0x03};  
 TM1638::DisplayData_t cls_str   = {0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
 TM1638::DisplayData_t hello_str = {C7_H,0x00, C7_E,0x00, C7_L,0x00, C7_L,0x00, C7_O,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};
+TM1638::DisplayData_t bye_str   = {C7_B,0x00, C7_Y,0x00, C7_E,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};
 
 // KeyData_t size is 3 bytes  
 TM1638::KeyData_t keydata; 
@@ -67,12 +68,12 @@
       if (LEDKEY8.getKeys(&keydata)) {
         pc.printf("Keydata 0..3 = 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3]);
 
-        if (keydata[0] == 0x01) { //sw1  
+        if (keydata[LEDKEY8_SW1_IDX] == LEDKEY8_SW1_BIT) { //sw1  
           LEDKEY8.cls(); 
           LEDKEY8.writeData(all_str);
         }  
 
-        if (keydata[1] == 0x01) { //sw2  
+        if (keydata[LEDKEY8_SW2_IDX] == LEDKEY8_SW2_BIT) { //sw2  
           LEDKEY8.cls(); 
 //          LEDKEY8.writeData(hello_str);
 #if(1)
@@ -93,13 +94,12 @@
               cmd = pc.getc(); // wait for key
             }  
           }
-          pc.printf("Show all segs done\r\n");                    
+          pc.printf("\r\nShow all segs done\r\n");                    
 #endif 
           
         }  
 
-
-        if (keydata[2] == 0x01) { //sw3   
+        if (keydata[LEDKEY8_SW3_IDX] == LEDKEY8_SW3_BIT) { //sw3  
 //          LEDKEY8.cls(); 
 //          LEDKEY8.writeData(mbed_str);
 
@@ -136,7 +136,7 @@
             }  
             val = val * 10;
           }
-          pc.printf("Show all digits done\r\n");                    
+          pc.printf("\r\nShow all digits done\r\n");                    
 #endif                
 
 #if(1)
@@ -160,19 +160,17 @@
             }  
             val = val * 0x10;
           }
-          pc.printf("Show all hex digits done\r\n");          
+          pc.printf("\r\nShow all hex digits done\r\n");          
 #endif                
         }
-        
-        if (keydata[3] == 0x01) { //sw4   
+
+        if (keydata[LEDKEY8_SW4_IDX] == LEDKEY8_SW4_BIT) { //sw4          
 //          LEDKEY8.cls(); 
 //          LEDKEY8.writeData(mbed_str); 
 #if(1)
 //test to show all icons
           pc.printf("Show all icons\r\n");
-          wait(1);          
           LEDKEY8.cls(true); // Also clear all Icons
-          wait(1);          
           
           float delay=0.1;
           // Icons on             
@@ -198,21 +196,52 @@
           LEDKEY8.clrIcon(TM1638_LEDKEY8::LD8); wait(delay);
                  
 //          wait(1);          
-//          LEDKEY8.cls(); // clear all, preserve Icons         
+//          LEDKEY8.cls(); // clear all, preserve Icons
           pc.printf("Show all icons done\r\n");                    
 #endif           
         }       
 
-        if (keydata[0] == 0x10) { //sw5   
+        if (keydata[LEDKEY8_SW5_IDX] == LEDKEY8_SW5_BIT) { //sw5  
+          LEDKEY8.cls(); // clear all, preserve Icons
+          LEDKEY8.writeData(hello_str);           
         }
 
-        if (keydata[1] == 0x10) { //sw6   
+        if (keydata[LEDKEY8_SW6_IDX] == LEDKEY8_SW6_BIT) { //sw6  
+          LEDKEY8.cls(); // clear all, preserve Icons
+          LEDKEY8.writeData(bye_str);                   
+        }
+        
+        if (keydata[LEDKEY8_SW7_IDX] == LEDKEY8_SW7_BIT) { //sw7  
+          LEDKEY8.cls(); // clear all, preserve Icons
+          LEDKEY8.printf("%2.3f", -0.1234);  // test decimal point display                    
+          wait(0.5);
+          LEDKEY8.cls(); // clear all, preserve Icons          
+          LEDKEY8.printf("%2.3f", -012.345);  // test decimal point display
         }
         
-        if (keydata[2] == 0x10) { //sw7   
-        }
-        
-        if (keydata[3] == 0x10) { //sw8   
+        if (keydata[LEDKEY8_SW8_IDX] == LEDKEY8_SW8_BIT) { //sw8  
+          float delay=0.1;
+          // Icons on             
+          LEDKEY8.setIcon(TM1638_LEDKEY8::DP1); wait(delay);
+          LEDKEY8.setIcon(TM1638_LEDKEY8::DP2); wait(delay);
+          LEDKEY8.setIcon(TM1638_LEDKEY8::DP3); wait(delay);
+          LEDKEY8.setIcon(TM1638_LEDKEY8::DP4); wait(delay);
+          LEDKEY8.setIcon(TM1638_LEDKEY8::DP5); wait(delay);
+          LEDKEY8.setIcon(TM1638_LEDKEY8::DP6); wait(delay);
+          LEDKEY8.setIcon(TM1638_LEDKEY8::DP7); wait(delay);
+          LEDKEY8.setIcon(TM1638_LEDKEY8::DP8); wait(delay);
+
+          wait(delay);
+ 
+          // Icons off      
+          LEDKEY8.clrIcon(TM1638_LEDKEY8::DP8); wait(delay);
+          LEDKEY8.clrIcon(TM1638_LEDKEY8::DP7); wait(delay);
+          LEDKEY8.clrIcon(TM1638_LEDKEY8::DP6); wait(delay);
+          LEDKEY8.clrIcon(TM1638_LEDKEY8::DP5); wait(delay);
+          LEDKEY8.clrIcon(TM1638_LEDKEY8::DP4); wait(delay);
+          LEDKEY8.clrIcon(TM1638_LEDKEY8::DP3); wait(delay);
+          LEDKEY8.clrIcon(TM1638_LEDKEY8::DP2); wait(delay);
+          LEDKEY8.clrIcon(TM1638_LEDKEY8::DP1); wait(delay);          
         }
      
       } //if Key