ESP32 WROOM 32 crashes when exiting function
Posted: Sat Dec 23, 2023 6:29 pm
Hi there.
I have an ESP32 WROOM 32 devkit 1 and I am trying to use the Capacitive Touch sensors built into the ESP
I have some code which waits for touch to be detected, and once it is detected, it should return that the pad has been touched, instead it crashes and reboots.
Does anyone know why and what might be causing this behavior?
Code below
I have an ESP32 WROOM 32 devkit 1 and I am trying to use the Capacitive Touch sensors built into the ESP
I have some code which waits for touch to be detected, and once it is detected, it should return that the pad has been touched, instead it crashes and reboots.
Does anyone know why and what might be causing this behavior?
Code below
Code: Select all
#define Threshold 40
int touchPad;
bool touchDetected = false;
int flag = 0;
int i = 0;
void setup() {
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
Serial.println("Booting");
touchAttachInterrupt(T0, gotTouch0, Threshold);
touchAttachInterrupt(T3, gotTouch3, Threshold);
touchAttachInterrupt(T4, gotTouch4, Threshold);
touchAttachInterrupt(T5, gotTouch5, Threshold);
touchAttachInterrupt(T6, gotTouch6, Threshold);
touchAttachInterrupt(T7, gotTouch7, Threshold);
touchAttachInterrupt(T8, gotTouch8, Threshold);
touchAttachInterrupt(T9, gotTouch9, Threshold);
}
void loop(){
if(touchDetected){ //Check continuously if any touch is detected
switch(touchPad){
case 0 : Serial.println("Case 0 Selected"); delay(1000); break;
case 3 : Serial.println("Case 3 Selected"); break;
case 4 : Serial.println("Case 4 Selected"); break;
case 5 : Serial.println("Case 5 Selected"); break;
case 6 : Serial.println("Case 6 Selected"); break;
case 7 : Serial.println("Case 7 Selected"); break;
case 8 : Serial.println("Case 8 Selected"); break;
case 9 : Serial.println("Case 9 Selected"); break;
default : break;
delay(1000);
}
}
}
void gotTouch0(){
Serial.println("Got 0");
touchDetected = true;
Serial.println("Changed TouchDetected to True");
touchPad = 0;
Serial.println("Set TouchPad to True");
delay(5000);
Serial.println("Going Back");
}
void gotTouch3(){
Serial.println("Got 3");
touchDetected = true;
touchPad = 3;
delay(500);
}
void gotTouch4(){
Serial.println("Got 4");
touchDetected = true;
touchPad = 4;
delay(500);
}
void gotTouch5(){
Serial.println("Got 5");
touchDetected = true;
touchPad = 5;
delay(500);
}
void gotTouch6(){
Serial.println("Got 6");
touchDetected = true;
touchPad = 6;
delay(500);
}
void gotTouch7(){
Serial.println("Got 7");
touchDetected = true;
touchPad = 7;
delay(500);
}
void gotTouch8(){
Serial.println("Got 8");
touchDetected = true;
touchPad = 8;
delay(500);
}
void gotTouch9(){
Serial.println("Got 9");
touchDetected = true;
touchPad = 9;
delay(500);
}