Simple ESP32 touch calibration for changing environment
Posted: Thu Sep 23, 2021 6:37 am
We can calculate the threshold value and different capacitance value due to changing environment. For example if you place 3 mm plastic plate onto the touch pad and restart the calibrate code esp32 recalculate the environment capacitance value.
- //touch pad defs
- #define TOUCHPIN T8
- #define REPEAT 32
- #define DELAYTOUCHREPEAT 5
- void calibrateTouch(){
- int touch = 0,totalValue = 0;
- //calculate the avarage value
- for(int counter = 0;counter < REPEAT ;counter++){
- //noise delay
- delay(DELAYTOUCHREPEAT);
- touch = touchRead(T8);
- totalValue += touch;
- //debugging purposes
- Serial.println(touch);
- }
- touchTehreshold = totalValue/REPEAT;
- Serial.println(touchTehreshold);
- }