#include <Arduino.h>
#include <TM1637Display.h>
#define CLK1 2
#define DIO1 3
#define CLK2 4
#define DIO2 5
#define R_CLK 6
#define R_DT 7
#define R_SW 10
int b1 = 9;
int b2 = 8;
// int t1 = 1000;
// int t2 = 1000;
TM1637Display display1(CLK1, DIO1);
TM1637Display display2(CLK2, DIO2);
int counter = 1000;
int currentStateCLK;
int lastStateCLK;
int stateDT;
unsigned long lastButtonPress = 0;
void setup() {
// put your setup code here, to run once:
pinMode(b1,INPUT_PULLUP);
pinMode(b2,INPUT_PULLUP);
pinMode(R_CLK, INPUT);
pinMode(R_DT, INPUT);
pinMode(R_SW, INPUT_PULLUP);
lastStateCLK = digitalRead(R_CLK);
display1.setBrightness(0x0f);
display2.setBrightness(0x0f);
}
void loop() {
// put your main code here, to run repeatedly: && currentStateCLK == 1
int t1 = 1000;
int t2 = 1000;
display2.showNumberDecEx(t2,0b01000000);
display1.showNumberDecEx(t1,0b01000000);
while (true) {
currentStateCLK = digitalRead(R_CLK);
stateDT = digitalRead(R_DT);
if (currentStateCLK != lastStateCLK && currentStateCLK == 1) {
// If the DT state is different than the CLK state then
// the encoder is rotating CCW so decrement
if (digitalRead(R_DT) == 0) {
t1 -= 50;
t2 -= 50;
} else {
// Encoder is rotating CW so increment
t1 += 50;
t2 += 50;
}
display2.showNumberDecEx(t2,0b01000000);
display1.showNumberDecEx(t1,0b01000000);
}
lastStateCLK = currentStateCLK;
if (digitalRead(R_SW) == 0) {
break;
}
}
// display2.showNumberDecEx(t2,0b01000000);
while (t1 != 0 & t2 != 0) {
while (t1 > 0) {
display1.showNumberDecEx(t1,0b01000000);
delay(1000);
t1 -= 1;
if (digitalRead(b1) == 0) {
break;
}
}
while (t2 > 0) {
display2.showNumberDecEx(t2,0b01000000);
delay(1000);
t2 -= 1;
if (digitalRead(b2) == 0) {
break;
}
}
}
delay(5000);
}