#include <Arduino.h>
#include <TM1637Display.h>
#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>
int encodeA = 5;
int encodeB = 6;
int numLock = 4;
int lastStateCLK;
int currentStateCLK;
int dispCLK = 3;
int dispDIO = 2;
int servoNum = 1;
TM1637Display display(dispCLK, dispDIO);
Encoder myEnc(5, 6);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(200);
pinMode(encodeA, INPUT_PULLUP);
pinMode(encodeB, INPUT_PULLUP);
pinMode(numLock, INPUT_PULLUP);
lastStateCLK = myEnc.read();
Serial.println("Initial Encoder State Read");
display.setBrightness(5); // Sets the brightness level to 5
uint8_t data[] = {0xff, 0xff, 0xff, 0xff}; // Turns on the display
Serial.println("Display On");
}
void loop() {
// put your main code here, to run repeatedly:
currentStateCLK = myEnc.read();
if (currentStateCLK > lastStateCLK) {
servoNum ++;
}
else if (currentStateCLK < lastStateCLK && currentStateCLK != 0) {
servoNum --;
}
if (currentStateCLK != lastStateCLK) {
lastStateCLK = currentStateCLK;
}
display.showNumberDec(servoNum, true);
Serial.println(servoNum);
}