Simple ESP32 touch calibration for changing environment

reddomon
Posts: 1
Joined: Thu Sep 23, 2021 6:30 am

Simple ESP32 touch calibration for changing environment

Postby reddomon » 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.
  1.  
  2. //touch pad defs
  3. #define TOUCHPIN T8
  4. #define REPEAT 32
  5. #define DELAYTOUCHREPEAT 5
  6.  
  7. void calibrateTouch(){
  8.  
  9.     int  touch = 0,totalValue = 0;
  10.    //calculate the avarage value
  11.     for(int counter = 0;counter < REPEAT ;counter++){
  12.       //noise delay
  13.       delay(DELAYTOUCHREPEAT);
  14.       touch = touchRead(T8);
  15.       totalValue += touch;
  16.      //debugging purposes
  17.       Serial.println(touch);
  18.       }
  19.  
  20.     touchTehreshold = totalValue/REPEAT;
  21.     Serial.println(touchTehreshold);
  22.      
  23.  
  24.  
  25. }

Who is online

Users browsing this forum: No registered users and 72 guests