// 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, TM4; // Each display needs its own object
int display1 = 21;
int display2 = 22;
int display3 = 23;
int display4 = 24;
const int buttonPin1up = 34;
const int buttonPin1down = 35;
const int buttonPin2up = 32;
const int buttonPin2down = 33;
const int buttonPin3up = 5;
const int buttonPin3down = 17;
const int buttonPin4up = 16;
const int buttonPin4down = 4;
int oldValue1up = LOW;
int oldValue1down = LOW;
int oldValue2up = LOW;
int oldValue2down = LOW;
int oldValue3up = LOW;
int oldValue3down = LOW;
int oldValue4up = LOW;
int oldValue4down = LOW;
char buffer[5]; // buffer for third display
void setup()
{
Serial.begin(115200);
// -----------------------------------------
// First display
// -----------------------------------------
TM1.begin(14, 12, 4); // clockpin, datapin, #digits
TM1.displayClear();
TM1.setBrightness(7); // full brightness, default is 3
TM1.displayInt(display1, 0); // Initial text on third display
// -----------------------------------------
// Second display
// -----------------------------------------
TM2.begin(26, 27, 4); // clockpin, datapin, #digits
TM2.displayClear();
TM2.setBrightness(7); // full brightness, default is 3
TM2.displayInt(display2, 0); // Initial text on third display
// -----------------------------------------
// Third display
// -----------------------------------------
TM3.begin(22, 23, 4); // clockpin, datapin, #digits
TM3.displayClear();
TM3.setBrightness(7); // full brightness, default is 3
TM3.displayInt(display3, 0); // Initial text on third display
// -----------------------------------------
// Fourth display
// -----------------------------------------
TM4.begin(18, 19, 4); // clockpin, datapin, #digits
TM4.displayClear();
TM4.setBrightness(7); // full brightness, default is 3
TM4.displayInt(display4, 0); // Initial text on third display
// displays OK
pinMode(buttonPin1up, INPUT_PULLUP);
pinMode(buttonPin1down, INPUT_PULLUP);
pinMode(buttonPin2up, INPUT_PULLUP);
pinMode(buttonPin2down, INPUT_PULLUP);
pinMode(buttonPin3up, INPUT_PULLUP);
pinMode(buttonPin3down, INPUT_PULLUP);
pinMode(buttonPin4up, INPUT_PULLUP);
pinMode(buttonPin4down, INPUT_PULLUP);
}
void loop()
{
//TM2.displayClear();
//TM3.displayClear();
//TM4.displayClear();
int newValue1up = digitalRead(buttonPin1up);
int newValue1down = digitalRead(buttonPin1down);
int newValue2up = digitalRead(buttonPin2up);
int newValue2down = digitalRead(buttonPin2down);
int newValue3up = digitalRead(buttonPin3up);
int newValue3down = digitalRead(buttonPin3down);
int newValue4up = digitalRead(buttonPin4up);
int newValue4down = digitalRead(buttonPin4down);
if(newValue1up == HIGH && oldValue1up == LOW)
{
TM1.displayClear();
display1++;
TM1.displayInt(display1, 0);
while (digitalRead(buttonPin1up) == HIGH);
delay(50);
}
if(newValue1down == HIGH && oldValue1down == LOW)
{
TM1.displayClear();
display1--;
TM1.displayInt(display1, 0);
while (digitalRead(buttonPin1down) == HIGH);
delay(50);
}
if(newValue2up == HIGH && oldValue2up == LOW)
{
TM2.displayClear();
display2++;
TM2.displayInt(display2, 0);
while (digitalRead(buttonPin1up) == HIGH);
delay(50);
}
if(newValue2down == HIGH && oldValue2down == LOW)
{
TM2.displayClear();
display2--;
TM2.displayInt(display2, 0);
while (digitalRead(buttonPin1down) == HIGH);
delay(50);
}
if(newValue3up == HIGH && oldValue3up == LOW)
{
TM3.displayClear();
display3++;
TM3.displayInt(display3, 0);
while (digitalRead(buttonPin3up) == HIGH);
delay(50);
}
if(newValue3down == HIGH && oldValue3down == LOW)
{
TM3.displayClear();
display3--;
TM3.displayInt(display3, 0);
while (digitalRead(buttonPin3down) == HIGH);
delay(50);
}
if(newValue4up == HIGH && oldValue4up == LOW)
{
TM4.displayClear();
display4++;
TM4.displayInt(display4, 0);
while (digitalRead(buttonPin4up) == HIGH);
delay(50);
}
if(newValue4down == HIGH && oldValue4down == LOW)
{
TM4.displayClear();
display4--;
TM4.displayInt(display4, 0);
while (digitalRead(buttonPin4down) == HIGH);
delay(50);
}
}