I am attempting to integrate some touch pins into a project. I made up some 1/4 inch square copper pads, soldered a wire to each, and plugged them int T5, T6, T7. I find that if I just set up a loop reading T6 every quarter second, I usually get value around 70, but now and then I get excursions to very low values, even as low as 3.
It seems to me that these pins can't be much good if they are in effect "self touching". Is there some method to stabilize these pins?
Thanks in advance for any help.
Jrdoner
I've just solved the problem of making the touch function reliable, as follows.
void setup()
{
Serial.begin(115200);
}
void loop()
{
if(checkTouchKey(T6, 30)) Serial.println("Key pressed");
}
//checks touch pin, requires four consecutive low readings to declare key touched
boolean checkTouchKey(int touchPin, int threshold)
{
unsigned long startTime;
int count;
boolean pressed;
pressed = false;
startTime = millis();
count = 0;
do
{
if(touchRead(touchPin) < threshold) count++;
else count = 0;
if(count == 3) pressed = true;
delay(200);
}
while((count < 4) && (millis() < startTime + 1000));
return pressed;
}