const int s1Pin = 8; // Pin for the first signal
const int s2Pin = 9; // Pin for the second signal
const int btnPin = 10; // Pin for the button
void IRAM_ATTR handleEncoder() {
// Read the state of the two pins
//int s1State = digitalRead(s1Pin);
int s2State = digitalRead(s2Pin);
if(s2State == LOW){
Serial.println("Rotated Clockwise");
}else{
Serial.println("Rotated Counterclockwise");
}
}
void IRAM_ATTR handleButtonPress() {
Serial.println("Button pressed!");
}
void setup() {
Serial.begin(115200);
pinMode(s1Pin, INPUT_PULLDOWN);
pinMode(s2Pin, INPUT_PULLDOWN);
pinMode(btnPin, INPUT_PULLUP);
// Attach interrupts for the rotary encoder
attachInterrupt(digitalPinToInterrupt(s1Pin), handleEncoder, RISING);
//attachInterrupt(digitalPinToInterrupt(s2Pin), handleEncoder, CHANGE);
// Attach interrupt for the button
attachInterrupt(digitalPinToInterrupt(btnPin), handleButtonPress, FALLING);
}
void loop() {
delay(100000);
}