#include <Adafruit_NeoPixel.h>
#define PIN 8
#define NUMPIXELS 16
#define datapin 4
#define clockpin 5
#define latchpin 6
#define ec11_left 3
#define ec11_right 2
#define ec11_sw 1
int input_num = 16;
void init_165(){
pinMode(datapin, INPUT);
pinMode(clockpin, OUTPUT);
pinMode(latchpin, OUTPUT);
}
void scan_165(){
digitalWrite(latchpin, LOW);
digitalWrite(latchpin, HIGH);
for (int i = 0; i < input_num; i++) {
int bit = digitalRead(datapin);
if (bit == HIGH) {
Serial.print("1");
} else {
Serial.print("0");
}
digitalWrite(clockpin, HIGH); // Shift out the next bit
digitalWrite(clockpin, LOW);
}
}
void ec11_init(){
pinMode(ec11_left, INPUT);
pinMode(ec11_right, INPUT);
pinMode(ec11_sw, INPUT);
attachInterrupt(digitalPinToInterrupt(ec11_right),ec11_ISR,FALLING);
}
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void WS2812_init(){
strip.begin();
strip.show();
}
void WS2812_show(){
for(int i=0;i<NUMPIXELS;i++){
strip.setPixelColor(i, strip.Color(255, 0, 0));
strip.show();
delay(100);
strip.setPixelColor(i, strip.Color(0, 0, 0));
strip.show();
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-C3!");
init_165();
ec11_init();
WS2812_init();
}
void loop() {
scan_165();
WS2812_show();
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
void ec11_ISR(){
int dtValue = digitalRead(ec11_left);
if (dtValue == HIGH) {
Serial.println("Rotated clockwise ⏩");
}
if (dtValue == LOW) {
Serial.println("Rotated counterclockwise ⏪");
}
}