Test program for Princeton PT6961 LED controller library.

Dependencies:   PT6961 mbed

See here for more information.

main.cpp

Committer:
wim
Date:
2015-09-20
Revision:
2:3bc72b8f5481
Parent:
1:59c864633347
Child:
4:bedc75e6561a

File content as of revision 2:3bc72b8f5481:

/* mbed PT6961 Test program, for Princeton PT6961 LED controller
 * Copyright (c) 2015, 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 "PT6961.h"

Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);

// DisplayData_t size is 12 bytes (6 digits @ 12 segments) OR 14 bytes (7 digits @ 11 segments) 
PT6961::DisplayData_t mbed_str = {0xDA,0x00, 0x7C,0x00, 0x3C,0x01, 0xF6,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
PT6961::DisplayData_t all_str  = {0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F, 0xFF,0x0F};  
PT6961::DisplayData_t bye_str = {0x7C,0x00, 0xEC,0x00, 0x3C,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00};  
PT6961::DisplayData_t hello_str = {0xDC,0x00, 0x3C,0x01, 0x38,0x00, 0x38,0x00, 0xF8,0x01, 0x00,0x00, 0x00,0x00};  
PT6961::DisplayData_t tst_str;  

// KeyData_t size is 5 bytes  
PT6961::KeyData_t keydata; 

// PT6191 declaration, Default setting 7 Digits @ 11 Segments
PT6961 pt6961(p5,p6,p7, p8);

int main() {
    
    pc.printf("Hello World\r\n"); //    
    
    pt6961.cls(); 
    pt6961.writeData(all_str);
    wait(4);
    pt6961.setBrightness(PT6961_BRT3);    
    pt6961.writeData(mbed_str);    
    wait(1);
    pt6961.setBrightness(PT6961_BRT0);        
    wait(1);
    pt6961.setBrightness(PT6961_BRT3);            
    
    while (1) {
     
      // Check and read keydata
      if (pt6961.getKeys(&keydata)) {
        pc.printf("Keydata 0..4 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\r\n", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4]);

        if (keydata[0] == 0x10) { //sw2   
          pt6961.cls(); 
          pt6961.writeData(all_str);
        }  

        if (keydata[0] == 0x02) { //sw8   
          pt6961.cls(); 
          pt6961.writeData(hello_str);
        }  

        if (keydata[0] == 0x20) { //sw6   
          pt6961.cls(); 
          pt6961.writeData(mbed_str);
        }       

        if (keydata[1] == 0x02) { //sw4   
          pt6961.cls(); 
          pt6961.writeData(bye_str);
        }       

        if (keydata[0] == 0x04) { //sw11   
          pt6961.cls(); 
          
          for (int idx=0; idx < PT6961_DISPLAY_MEM;idx++){
            tst_str[idx]=0x00;
          }
          tst_str[0]=0x01; //RA
          tst_str[2]=0x01; //M          
          pt6961.writeData(tst_str);
        }       

        if (keydata[0] == 0x08) { //sw10   
          pt6961.cls(); 
          
          for (int idx=0; idx < PT6961_DISPLAY_MEM;idx++){
            tst_str[idx]=0x00;
          }
          tst_str[6]=0x01; //HD
          tst_str[8]=0x01; //D          
          pt6961.writeData(tst_str);
        }       

        if (keydata[1] == 0x01) { //sw9   
          pt6961.cls(); 
          
          for (int idx=0; idx < PT6961_DISPLAY_MEM;idx++){
            tst_str[idx]=0x00;
          }
          tst_str[8]=0x01;  //D
          tst_str[10]=0x01; //VD          
          pt6961.writeData(tst_str);
        }       

        if (keydata[0] == 0x01) { //sw7   
          pt6961.cls(); 
          
          for (int idx=0; idx < PT6961_DISPLAY_MEM;idx++){
            tst_str[idx]=0x00;
          }
          tst_str[12]=0x20; //clock
          pt6961.writeData(tst_str);
        }       
        
      } //if

      myled = !myled;
      wait(0.3);      
    } //while
}