Safer Touch input, mains interference compensation...
Posted: Fri Apr 13, 2018 12:17 pm
The TouchInput of the ESP32 isn't exactly reliable unless you design the touchfields thoroughly with proper shielding.
If you are using -like me- board-pins soldered on a pcb breadboard you might get trouble with mains interference.
It helps to make a second read half a period later (10mS with 50Hz mains frequency, 8mS with a 60Hz mains frequency).
So interference from your mains power will be eliminated.
This way to check the touch inputs helps:
If you are using -like me- board-pins soldered on a pcb breadboard you might get trouble with mains interference.
It helps to make a second read half a period later (10mS with 50Hz mains frequency, 8mS with a 60Hz mains frequency).
So interference from your mains power will be eliminated.
This way to check the touch inputs helps:
Code: Select all
byte mainScreen;
byte subScreen;
byte maxScreens[] = {3, 15, 25, 13}; //3 mainScreens, mainScreen1 has 15 subscreens, mainScreen2 has 25 subscreens ...
...
// part processed in a on second loop
// Menu processing.
if (touchRead(T3) < 15) // increase screen #
{
delay(10); if (touchRead(T3) < 15)
{
if ( mainScreen < maxScreens[0]) mainScreen ++;
subScreen = 0;
}
}
if (touchRead(T5) < 15) // decrease screen #
{
delay(10);
if (touchRead(T5) < 15)
{
if ( mainScreen >= 1) mainScreen --;
subScreen = 0;
}
}
if (touchRead(T6) < 15) // increase subscreen #
{
delay(10);
if (touchRead(T6) < 15)
{
if (subScreen < maxScreens[mainScreen]) subScreen ++;
}
}
if (touchRead(T4) < 15)
{
delay(10);
if (touchRead(T4) < 15) // decrease subscreen #
{
if (subScreen >= 1) subScreen --;
}
}