#include <TM1637TinyDisplay.h>
#include <RotaryEncoder.h>
TM1637TinyDisplay display(PB1, PB0);
RotaryEncoder *encoder = nullptr;
int level = 0;
void checkPosition()
{
encoder->tick(); // just call tick() to check the state.
}
void setup() {
display.begin();
encoder = new RotaryEncoder(PB3, PB4, RotaryEncoder::LatchMode::TWO03);
attachInterrupt(PB3, checkPosition, CHANGE);
attachInterrupt(PB4, checkPosition, CHANGE);
}
void loop() {
encoder->tick(); // just call tick() to check the state.
int newPos = encoder->getPosition();
level = level + (int)(encoder->getDirection());
display.showNumber(level);
if(level > 255) {level = 0;}
}