#include <RotaryEncoderPCNT.h>
#include "ESP32_WS2812_Lib.h"
// Constructor args are: pinA/Clock, pinB/Data, start position, glitch filter time in ns.
// Start position and filter time are optional. Defaults are 0 and 1000ns respectively.
//
// RotaryEncoderPCNT encoder(25, 12, 0, 1000);
// RotaryEncoderPCNT encoder(25, 12, 0);
RotaryEncoderPCNT encoder(6, 7);
int old_position;
int position;
#define LEDS_COUNT 8
#define LEDS_PIN 15
#define CHANNEL 0
ESP32_WS2812 strip = ESP32_WS2812(LEDS_COUNT, LEDS_PIN, CHANNEL);
void setup() {
Serial.begin(115200);
strip.begin();
// Change position after initialization.
// encoder.setPosition(128);
// Show initial position.
old_position = encoder.position();
Serial.println(old_position);
}
void loop() {
// Show position when it changes.
position = encoder.position();
if(position != old_position){
Serial.println(position);
old_position = position;
}
for (int j = 0; j < 255; j += 2) {
for (int i = 0; i < strip.getLedCount(); i++) {
strip.setLedColorData(i, strip.Wheel((i * 256 / strip.getLedCount() + j) & 255));
}
strip.show();
delay(2);
}
delay(5);
}