#include <Encoder.h>
// Create an Encoder object and specify the pin numbers for the two encoder signals
Encoder encoder(2, 3);
int val = 0;
int lastVal = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
val = encoder.read();
// Check if the encoder value has changed
if (val != lastVal) {
// Keep the encoder value within the range of 128 values and wrap around when it goes out of range
val = (val + 128) % 128;
Serial.println(val);
lastVal = val;
}
}