// Example for the TM1637 display with TM1637_RT library.
// By Koepel, 28 February 2023.
//
// Library: "TM1637_RT", https://github.com/RobTillaart/TM1637_RT
#include <TM1637.h>
TM1637 TM1, TM2, TM3; // Each display needs its own object
unsigned long previousMillisClock; // for the millis timer of the first display
const unsigned long intervalClock = 1000;
bool colon = false; // for a toggling of the colon in the middle.
unsigned long previousMillisCountDown; // for a millis timer of second display
const unsigned long intervalCountDown = 100;
int clockSeconds; // the seconds counter for the first display
int clockMinutes; // the minute counter for the first display
int countDown = 9999; // start value of down counter for second display
char buffer[5]; // buffer for third display
void setup()
{
Serial.begin(115200);
Serial.println("Type your text for the third display.");
Serial.println("Now displaying \"----\".");
// -----------------------------------------
// First display
// -----------------------------------------
TM1.begin(8, 9, 4); // clockpin, datapin, #digits
TM1.displayClear();
TM1.setBrightness(7); // full brightness, default is 3
// -----------------------------------------
// Second display
// -----------------------------------------
TM2.begin(6, 7, 4); // clockpin, datapin, #digits
TM2.displayClear();
TM2.setBrightness(7); // full brightness, default is 3
// -----------------------------------------
// Third display
// -----------------------------------------
TM3.begin(4, 5, 4); // clockpin, datapin, #digits
TM3.displayClear();
TM3.setBrightness(7); // full brightness, default is 3
TM3.displayPChar("----"); // Initial text on third display
}
void loop()
{
unsigned long currentMillis = millis();
// -----------------------------------------
// First display
// -----------------------------------------
if( currentMillis - previousMillisClock >= intervalClock)
{
previousMillisClock += intervalClock; // for a clock-accurate millis timer
TM1.displayTime(clockMinutes,clockSeconds, colon); // display the numbers
colon = !colon; // toggle colon
// increment time
clockSeconds++;
if (clockSeconds >= 60)
{
clockSeconds = 0;
clockMinutes++;
if (clockMinutes >= 60)
{
clockMinutes = 0;
}
}
}
// -----------------------------------------
// Second display
// -----------------------------------------
if( currentMillis - previousMillisCountDown >= intervalCountDown)
{
previousMillisCountDown += intervalCountDown; // for a clock-accurate millis timer
// decrement second display
TM2.displayInt(countDown); // display the count down value
countDown--; // count down
if (countDown < 0)
{
countDown = 9999;
}
}
// -----------------------------------------
// Third display
// -----------------------------------------
if (Serial.available() > 0)
{
int inChar = Serial.read();
if (isprint(inChar))
{
for( int i=0; i<3; i++) // shift buffer to the left
buffer[i] = buffer[i+1];
buffer[3] = (char) inChar; // add new character
buffer[4] = '\0'; // add zero-terminator
}
TM3.displayPChar(buffer); // display the new text
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
sevseg1:CLK
sevseg1:DIO
sevseg1:VCC
sevseg1:GND
sevseg2:CLK
sevseg2:DIO
sevseg2:VCC
sevseg2:GND
sevseg3:CLK
sevseg3:DIO
sevseg3:VCC
sevseg3:GND