#include <ezButton.h>
#include <TM1637Display.h>
#define CLK_PIN 25
#define DT_PIN 26
#define SW_PIN 27
const int CLK = 33;
const int DIO = 32;
#define DIRECTION_CW 0
#define DIRECTION_CCW 1
const int barPins[] = {2, 0, 4, 16, 17, 5, 18, 19,22, 21};
int counter = 0;
int direction = DIRECTION_CW;
int CLK_state;
int prev_CLK_state;
ezButton button(SW_PIN);
TM1637Display display(CLK, DIO);
void setup() {
Serial.begin(9600);
display.setBrightness(0x0a);
pinMode(CLK_PIN, INPUT);
pinMode(DT_PIN, INPUT);
button.setDebounceTime(50);
for (int i = 0; i < 10; i++) {
pinMode(barPins[i], OUTPUT);
digitalWrite(barPins[i], LOW);
}
prev_CLK_state = digitalRead(CLK_PIN);
}
void loop() {
button.loop();
CLK_state = digitalRead(CLK_PIN);
if (CLK_state != prev_CLK_state && CLK_state == HIGH) {
if (digitalRead(DT_PIN) == HIGH && counter > 0) {
counter--;
direction = DIRECTION_CCW;
digitalWrite(barPins[counter], LOW);
display.showNumberDec(counter);
} else if(digitalRead(DT_PIN) == LOW && counter < 10) {
digitalWrite(barPins[counter], HIGH);
counter++;
direction = DIRECTION_CW;
display.showNumberDec(counter);
}
}
prev_CLK_state = CLK_state;
}