Spesifikasi modul elektronika ini:
  • Menggunakan IC pengarah-kendali tampilan TM1638 berteknologi CMOS
  • Tegangan operasional: 5 Volt DC
  • Konsumsi arus: 240 mA
  • Moda tampilan: 8-digit 7-segment LED dengan digit/period segment plus 8 LED status
  • Moda masukan: 8 tombol tactile switch buttons dengan pemindai tersandikan (encoding scanner) 8 x 3-bit
  • Antarmuka serial tersinkronisasi (CLK, STB, DIO)
  • Moda osilasi: RC oscillator, 450 kHz ±5%
  • Pengendalian hanya menggunakan 3-pin I/O dari mikrokontroler (STB, CLK, DIO) selain VCC dan GND.
  • Built-in power-on reset circuit
Berikut ini adalah diagram tata letak komponen dari modul ini:
Berikut ini adalah skematik rangkaian dari modul ini:
// Contoh program / Arduino Sketch untuk modul LED&KEY TM1638
// http://www.Vcc2GND.com/MDLKTM1638

#define	DATA_COMMAND	0X40
#define	DISP_COMMAND	0x80
#define	ADDR_COMMAND	0XC0

// PinOut, sesuaikan dengan pemetaan pin Anda
int DIO = 5;  // Module.DIO -- Arduino.D5
int CLK = 6;  // Module.CLK -- Arduino.D6
int STB = 7;  // Module.STB -- Arduino.D7

// Bitmask untuk 7-Segment display (0-9,A-F)
unsigned char tab[]={
  0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
  0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71
};

// Array untuk menyimpan nilai masing2 digit                      
unsigned char num[8];

void TM1638_Write(unsigned char	DATA) {
  unsigned char i;
  pinMode(DIO,OUTPUT);
  for(i=0; i<8; i++) {
    digitalWrite(CLK,LOW);
    DATA & 1 ? digitalWrite(DIO,HIGH) : digitalWrite(DIO,LOW);
    DATA >>= 1;
    digitalWrite(CLK,HIGH);
  }
}

unsigned char TM1638_Read(void)	{
  unsigned char i;
  unsigned char temp=0;;
  pinMode(DIO,INPUT);
  for(i=0; i<8; i++) {
    temp>>=1;
    digitalWrite(CLK,LOW);
    if(digitalRead(DIO)==HIGH) temp|=0x80;
    digitalWrite(CLK,HIGH);
  }
  return temp;
}

void Write_COM(unsigned char cmd) { // Kirim perintah
  digitalWrite(STB,LOW);
  TM1638_Write(cmd);
  digitalWrite(STB,HIGH);
}

unsigned char Read_key(void) {
  unsigned char c[4],i,key_value=0;
  digitalWrite(STB,LOW);
  TM1638_Write(0x42);  // Perintah untuk memindai tombol
  for(i=0;i<4;i++) c[i]=TM1638_Read();
  digitalWrite(STB,HIGH);
  for(i=0;i<4;i++) key_value|=c[i]<<i;
  for(i=0;i<8;i++) if((0x01<<i)==key_value)break;
  return i;
}

void Write_DATA(unsigned char add,unsigned char DATA) {
  Write_COM(0x44);
  digitalWrite(STB,LOW);
  TM1638_Write(0xc0|add);
  TM1638_Write(DATA);
  digitalWrite(STB,HIGH);
}

void Write_all_LED(unsigned char LED_flag) {
  unsigned char i;
  for(i=0;i<8;i++) {
    if(LED_flag&(1<<i)) Write_DATA(2*i+1,1);
    else Write_DATA(2*i+1,0);
  }
}

void init_TM1638(void) {
  unsigned char i;
  Write_COM(0x8b);       // 8 level brigtness: 0x88~0x8F
  Write_COM(0x40);       // Automatic address increment
  digitalWrite(STB,LOW);
  TM1638_Write(0xc0);    // Set starting address
  for(i=0;i<16;i++) TM1638_Write(0x00); // write 16-bytes data
  digitalWrite(STB,HIGH);
}

void setup () {
  pinMode(STB,OUTPUT);
  pinMode(CLK,OUTPUT);
  pinMode(DIO,OUTPUT);
}

void loop() {
  unsigned char i;
  init_TM1638();  // Inisialisasi IC TM1638
  for(i=0;i<8;i++) Write_DATA(i<<1, tab[0]);	// Update display
  while(true) {
    i = Read_key(); // Baca input
    if(i < 8) {
      num[i]++;
      while(i == Read_key());  // Tunggu sampai tombol dilepas
      if(num[i] > 15) {
        num[i] = 0;
        Write_DATA(i*2, tab[num[i]]);
        Write_all_LED(1<<i);
      }
    }
  }
}