-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTouchButton.h
More file actions
31 lines (25 loc) · 1.01 KB
/
Copy pathTouchButton.h
File metadata and controls
31 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef TouchButton_h
#define TouchButton_h
#include <Arduino.h>
// ============================================================
// TouchButton — a capacitive touch pad used as a single button.
//
// The pad fires an interrupt that only sets a flag; pressed() is polled from
// the main loop and returns true once per genuine, debounced press. It re-reads
// the pad to reject brief electrical noise. On ESP32-S3, a real press keeps the
// reading above TOUCH_THRESHOLD; a noise spike has decayed below it by then.
// ============================================================
class TouchButton {
public:
void begin(int pin, int threshold, unsigned long debounceMs);
// Returns true exactly once per real, debounced press.
bool pressed();
private:
static void IRAM_ATTR _isr();
static volatile bool _flag; // set by the ISR (one button → static is fine)
int _pin = 0;
int _threshold = 0;
unsigned long _debounceMs = 0;
unsigned long _lastMs = 0;
};
#endif