ESP32触摸按键检测
/*
T0 ----- G4
T1 ----- G0
T2 ----- G2
T3 ----- G15
T4 ----- G13
T5 ----- G12
T6 ----- G14
T7 ----- G27
T8 ----- G33
T9 ----- G32
*/
typedef unsigned char u8;
u8 key=0;
#include <WiFi.h>
#define KEY0 touchRead(T0)
#define KEY1 touchRead(T8)
#define KEY2 touchRead(T9)
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Starting Touch work!");
}
u8 Key_sacan(void){
if(KEY0<2){
delay(20);
if(KEY0<2){
return 1;
}
}
if(KEY1<2){
delay(20);
if(KEY1<2){
return 2;
}
}
if(KEY2<2){
delay(20);
if(KEY2<2){
return 3;
}
}
}
void loop() {
key=Key_sacan();
if(key==1){
Serial.println("key0 touch!");
}
if(key==2){
Serial.println("key1 touch!");
}
if(key==3){
Serial.println("key2 touch!");
}
delay(30);
}