need help with touch GPIO
Posted: Sun May 12, 2019 11:12 am
I write a code for two touch GPIO T0 and T3 to turn on leds at GPIO 22,23
this is my code
and it works but I need another thing :-
1. when touch T0 it turns led at GPIO22 on
2. when touch T0 again it turns led at GPIO22 off
3. when touch T3 it turns led at GPIO23 on
4. when touch T3 again it turns led at GPIO23 off
and so on loop
please help
this is my code
Code: Select all
int threshold = 50;
bool touch1detected = false;
bool touch2detected = false;
void gotTouch(){
touch1detected = true;
}
void gotTouch1(){
touch2detected = true;
}
void setup() {
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
printf("\n ESP32 Touch Interrupt Test\n");
touchAttachInterrupt(T0, gotTouch, threshold);
touchAttachInterrupt(T3, gotTouch1, threshold);
pinMode (22, OUTPUT);
pinMode (23, OUTPUT);
}
void loop(){
if(touch1detected){
touch1detected = false;
Serial.println("Touch 0 ON");
digitalWrite(22, HIGH);
delay(1000);
}
else{
touch1detected = true;
digitalWrite(22, LOW);
Serial.println("Touch 0 OFF");
}
if(touch2detected){
touch2detected = false;
Serial.println("Touch 3 ON");
digitalWrite(23, HIGH);
delay(1000);
}
else{
digitalWrite(23, LOW);
Serial.println("Touch 3 OFF");
}
}
1. when touch T0 it turns led at GPIO22 on
2. when touch T0 again it turns led at GPIO22 off
3. when touch T3 it turns led at GPIO23 on
4. when touch T3 again it turns led at GPIO23 off
and so on loop
please help