mirror of
https://github.com/jaksatomovic/esp32-clickwheel.git
synced 2025-07-05 03:07:14 -04:00
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
/////////////////////////////////////////////////////////////////
|
|
|
|
#if !defined(ESP32)
|
|
#error This sketch needs an ESP32
|
|
#else
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
#include "Button2.h"
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
Button2 button;
|
|
byte pin = 4;
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
byte capStateHandler() {
|
|
int capa = touchRead(pin);
|
|
return capa < button.getDebounceTime() ? LOW : HIGH;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
delay(50);
|
|
Serial.println("\n\nCapacitive Touch Demo");
|
|
|
|
button.setDebounceTime(35);
|
|
button.setButtonStateFunction(capStateHandler);
|
|
button.setClickHandler(click);
|
|
button.begin(VIRTUAL_PIN);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
void loop() {
|
|
button.loop();
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
void click(Button2& btn) {
|
|
Serial.println("click\n");
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
#endif
|
|
/////////////////////////////////////////////////////////////////
|