forked from espressif/arduino-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTouchButtonV2.ino
53 lines (42 loc) · 1.13 KB
/
TouchButtonV2.ino
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
This is an example how to use Touch Intrrerupts
The sketh will tell when it is touched and then relesased as like a push-button
This method based on touchInterruptGetLastStatus() is only available for ESP32 S2 and S3
*/
#include "Arduino.h"
int threshold = 1500; // ESP32S2
bool touch1detected = false;
bool touch2detected = false;
void gotTouch1() {
touch1detected = true;
}
void gotTouch2() {
touch2detected = true;
}
void setup() {
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
Serial.println("\n ESP32 Touch Interrupt Test\n");
touchAttachInterrupt(T1, gotTouch1, threshold);
touchAttachInterrupt(T2, gotTouch2, threshold);
}
void loop() {
static uint32_t count = 0;
if (touch1detected) {
touch1detected = false;
if (touchInterruptGetLastStatus(T1)) {
Serial.println(" --- T1 Touched");
} else {
Serial.println(" --- T1 Released");
}
}
if (touch2detected) {
touch2detected = false;
if (touchInterruptGetLastStatus(T2)) {
Serial.println(" --- T2 Touched");
} else {
Serial.println(" --- T2 Released");
}
}
delay(80);
}