// LED-Animation-Tests:
// https://codepen.io/pedro-torpedo/pen/KKeZZyb?editors=0100
// add Shift Register: https://docs.wokwi.com/parts/wokwi-74hc165
// ------------------------------
// https://pololu.github.io/pushbutton-arduino/class_pushbutton.html#a73d08312ffb3502580485d3d2051e19f
#include <Pushbutton.h>
#define BUTTON_PIN 5
Pushbutton button1(BUTTON_PIN);
// ------------------------------
// https://github.com/Stutchbury/EncoderButton
#include <EncoderButton.h>
#define ENCODER_PIN_CLK 3
#define ENCODER_PIN_DT 2
#define ENCODER_PIN_SW 4
EncoderButton encoder1(ENCODER_PIN_CLK, ENCODER_PIN_DT, ENCODER_PIN_SW);
void onEncoder1Click(EncoderButton& eb) {
Serial.print("encoder1 clickCount: ");
Serial.println(eb.clickCount());
}
void onEncoder1(EncoderButton& eb) {
Serial.print("encoder1 incremented by: ");
Serial.println(eb.increment());
Serial.print("encoder1 position is: ");
Serial.println(eb.position());
}
void setup() {
Serial.begin(9600);
delay(500);
Serial.println("EncoderButton Basic Example");
//Link the event(s) to your function
encoder1.setClickHandler(onEncoder1Click);
encoder1.setEncoderHandler(onEncoder1);
}
void loop() {
encoder1.update();
if (button1.getSingleDebouncedPress()) {
Serial.print("Button1 is pressed");
Serial.println("");
}
if (button1.getSingleDebouncedRelease()) {
Serial.print("Button1 is released");
Serial.println("");
}
}