#include <TM1637Display.h>
// Define the connections pins
#define CLK1 18
#define DIO1 19
#define CLK2 17
#define DIO2 16
#define CLK3 15
#define DIO3 14
// Create display objects of TM1637Display class
TM1637Display display1(CLK1, DIO1);
TM1637Display display2(CLK2, DIO2);
TM1637Display display3(CLK3, DIO3);
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
display1.setBrightness(0x0f); // full brightness
// Second display
display2.setBrightness(0x0f); // full brightness
// Third display
// display3.setBrightness(0x0f); // full brightness
// display3.showString(buffer); // 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
display1.showNumberDecEx(clockMinutes * 100 + clockSeconds, 0b01000000, true); // display the numbers with colon
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
display2.showNumberDec(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
}
// display3.showString(buffer); // display the new text
}
}