TM1637 4 digits

This is pretty simple 4 digits (and a colon between 2-digit groups) display. Natural use would be to display time (see here), but I decided to show a sample used for IR Remote codes testing.

1637rdy

Here is the initial state before anything was sent to the receiver.

Label Ready 😉 was obtained by adressing single segments (as described for instance in document on forum.arduino.cc

Later on codes (2 digits are displayed on rightmost positions, while on 2 leftmost, there is previous code visible. it is usefull in particular when a key is hold a bit longer, and code 20 is received.

To divide visualy the two groups, I used semicolon. Unfortunately it was not implemented in a library I used ( Avishay (avishorp) library on github ), so it is “semi manually” added in the code.

1637buttons

#include <IRremote.h>
#include <Arduino.h>
#include <TM1637Display.h>
#define CLK 9
#define DIO 10
#define RECV_PIN 11
unsigned long next_time;
int res, last_res; 
uint8_t segto;

const uint8_t SEG_RDY[] = { 0, //empty first digit
SEG_E | SEG_G, // r
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
SEG_B | SEG_C | SEG_D | SEG_F | SEG_G // y
};

TM1637Display display(CLK, DIO);
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  irrecv.enableIRIn(); // Start the receiver
  display.setBrightness(0x0b); //ca. 75% of "full power"
  display.setSegments(SEG_RDY);
}

void loop() {
  if (irrecv.decode(&results)) {
    res = resultIR(results.value);
    if ((res != 20) || (next_time < millis())) {
      display.showNumberDec(100*last_res + res, true);
      segto = 0x80 | display.encodeDigit(last_res%10);
      display.setSegments(&segto, 1, 1); //add colon to separate values
      last_res = res;
      next_time = millis()+100;
    }
    irrecv.resume(); // Receive the next value
  }
}

And again (as in IR remote simple test via serial interface) decoding function shall be added:

int resultIR(long reading){
 int result;
 switch (reading) {
  case 16738455:
   result = 1 ;
   break;
  case 16750695:
   result = 2 ;
   break;
  case 16756815:
   result = 3 ;
   break;
  case 16724175:
   result = 4 ;
   break;
  case 16718055:
   result = 5 ;
   break;
  case 16743045:
   result = 6 ;
   break;
  case 16716015:
   result = 7 ;
   break;
  case 16726215:
   result = 8 ;
   break;
  case 16734885:
   result = 9 ;
   break;
  case 16730805:
   result = 10 ; //przycisk 0 button 0
   break;
  case 16728765:
   result = 11 ; //gwiazdka asterix
   break;
  case 16732845:
   result = 12 ; //krzyżyk hash
   break;
  case 16736925:
   result = 14 ; //góra up
   break;
  case 16754775:
   result = 15 ; //dół down
   break;
  case 16720605:
   result = 16 ; //lewy left
   break;
  case 16761405:
   result = 17 ; //prawy right
   break;
  case 16712445:
   result = 18 ; //OK
   break;
  case 16753245:
   result = 19 ; //włącznik na pilocie kamery, ON-OFF on dashboard camera
   break;
  case 16769565:
   result = 21 ; //detekcja ruchu - kamera, movement detection on dashboard camera
   break;
  case 4294967295:
   result = 20 ; //przytrzymanie, hold
   break;
  default: 
   result = 13 ; //błąd lub nieznany przycisk, error or not listed above
 }
 return result;  
}

2 thoughts on “TM1637 4 digits”

Leave a Reply