// based on library https://github.com/samopal-pro/SLib/
#include "SButton.h"
#define PIN_LED 26 // The ESP32 pin GPIO16 connected to WS2812B
#define PIN_BUTTON 34 // The number of LEDs (pixels) on WS2812B LED strip
SButton my_button( PIN_BUTTON );
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(PIN_LED, OUTPUT);
my_button.SetLongClick(2000);
// my_button.SetMultiClick(500);
my_button.SetAutoClick(5000,500);
}
void loop() {
switch(my_button.Loop()){
case SB_CLICK:
Serial.println("On Click");
digitalWrite(PIN_LED, HIGH); // turn the LED on
// delay(500); // wait for 500 milliseconds
// digitalWrite(18, LOW); // turn the LED off
break;
case SB_LONG_CLICK:
Serial.println("On Long Click");
digitalWrite(PIN_LED, LOW); // turn the LED on
break;
case SB_AUTO_CLICK:
Serial.println("On Auto Click");
break;
case SB_MULTI_CLICK:
Serial.print("On Multi Click: ");
Serial.println(my_button.Count);
break;
}
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1