Jan Zumwalt
Published © GPL3+

Pinguino tm1638 LED and Buttons

Access 8 LEDs, 8 buttons, and a 8 digit 7-segment led using only 3 IO lines.

IntermediateFull instructions provided2,641
Pinguino tm1638 LED and Buttons

Things used in this project

Hardware components

Pinguino compatible board
×1
tm1638 LED Keyboard
×1

Story

Read more

Code

Code snippet #1

Plain text
/*  +-------------------------------------------------------------------+
    | prog_name.pde           by Jan Zumwalt         rev 2016.01.20     |
    +-------------------------------------------------------------------+
    | Copyright: GNU public license.                                    |
    | Hardware : Olimex Pic32 Micro dev brd, tms1638 led & buttons      | 
    | Compiler : Pinguino.cc IDE (V11)                                  |
    | Purpose  : Example for TM1638 library                             |
    +-------------------------------------------------------------------+  */
//#include <TM16XX.c>
//#include TM16XX.c

//#include "TM16XX.c"
#include "TM1638.c"

void setup() {
    pinMode(10, OUTPUT);
    pinMode(32, OUTPUT);
    // define a module on data pin 5, clock pin 6 and strobe pin 7
    //TM16XX_init(5, 6, 7, 8, 1, 7);
    //TM16XX_setDisplayToError();
    //TM16XX_setDisplayDigit(0, 0, 0,NUMBER_FONT);

    //TM16XX_clearDisplay();
    // define a module on data pin 5, clock pin 6 and strobe pin 7, activate display, intensity
    TM1638_init(5, 6, 7,1 ,0 );  
    
    //Examples
    TM16XX_setDisplayToString("Start", 0, 0,    FONT_DEFAULT);
    //TM16XX_setDisplayToDecNumberAt(1265478, 0, 0, 1, NUMBER_FONT);
    //TM1638_DisplayToDecNumberAt(994478, 0, 0, 1, NUMBER_FONT);
    //TM1638_setDisplayToDecNumber(12654078, 0, 1, NUMBER_FONT);          //ERROR
    //TM1638_setDisplayToSignedDecNumber(-1234, 0, 1, NUMBER_FONT);
    //TM1638_setDisplayToBinNumber(654, 0, NUMBER_FONT);
    //TM1638_setDisplayToHexNumber(0x1234ABCD, 0xF0, 1, NUMBER_FONT);
}

void loop() {
 
  // light the first 4 red LEDs and the last 4 green LEDs as the buttons are pressed
  //TM1638_setLEDs(((keys & 0xF0) << 8) | (keys & 0xF));
  //TM1638_setLED(1,1);
 
  int i;

    int keys = TM1638_getButtons();
    TM16XX_clearDisplay();
    switch (keys){
        case 1:
                TM16XX_setDisplayToString("Button 1", 0, 0,    FONT_DEFAULT);
                TM1638_setLEDs(1);
            break;
        case 2:
                TM16XX_setDisplayToString("Button 2", 0, 0,    FONT_DEFAULT);
                TM1638_setLEDs(3);
            break;
        case 4:
                TM16XX_setDisplayToString("Button 3", 0, 0,    FONT_DEFAULT);
                TM1638_setLEDs(7);
            break;            
        case 8:
                TM16XX_setDisplayToString("Button 4", 0, 0,    FONT_DEFAULT);
                TM1638_setLEDs(15);
            break;
        case 16:
                TM16XX_setDisplayToString("Button 5", 0, 0,    FONT_DEFAULT);
                TM1638_setLEDs(31);
            break;           
        case 32:
                TM16XX_setDisplayToString("Button 6", 0, 0,    FONT_DEFAULT);
                TM1638_setLEDs(63);
            break;
        case 64:
                TM16XX_setDisplayToString("Button 7", 0, 0,    FONT_DEFAULT);
                TM1638_setLEDs(127);
            break;
        case 128:
                TM16XX_setDisplayToString("Button 8", 0, 0,    FONT_DEFAULT);
                TM1638_setLEDs(255);
            break;
        default:
                TM1638_setLEDs(0);
        }
        
       CDC.printf("character = %i \r\n", keys);
       
    // sequence leds  
    // for( i=0; i<=7; i++){    
    //CDC.println("Keys: %c\r\n", keys);
    //  TM1638_setLED(1,i);
    // delay(300);
    // TM1638_setLED(0,i);
   //  delay(300);
   //  }
}

Credits

Jan Zumwalt
9 projects • 14 followers
Retired aerospace engineer, aviation pilot, mechanic
Contact

Comments

Please log in or sign up to comment.