Touch Pins reacts even when not touched

johnymalina
Posts: 1
Joined: Tue Jun 16, 2020 6:35 pm

Touch Pins reacts even when not touched

Postby johnymalina » Tue Jun 16, 2020 7:08 pm

Hi,

i am having problem with touch pins. Trying to build simple control panel. Arrows, OK and Cancel buttons. Wired it on breadboard checked values to set sensitivity. To try if everything is working together i tried to code using if statements touching of a button and serial print what i touched but i get multiple values even when not touched so i try to find where is the problem and printing tha values of touchRead as follows and it prints even the values that are higher than specified with sensitivity (80 and more). If i let in the code only one if statement removing others everything works as i expected but. I tried to look and could not find any reason why could be these multiple if statements problem. What am i doing wrong?

Code: Select all

#include <Arduino.h>

int pinOK=13;
int pinCancel=12;
int pinUp=14;
int pinDown=33;
int pinLeft=32;
int pinRight=27;
int sensitivity=40;
int dt=100;
// String ok="OK";
// String cancel="Cancel";
// String Up="Up";
// String Down="Down";
// String left="Left";
// String right="Right";

void setup() {
  Serial.begin(115200);
  
}

void loop() {

  if (touchRead(pinOK) <= sensitivity)
  {
    Serial.println(touchRead(pinOK));
    delay(dt);
  }

  if (touchRead(pinCancel) <= sensitivity){
    Serial.println(touchRead(pinCancel));
    delay(dt);
    
  }

  if (touchRead(pinLeft) <= sensitivity)
  {
    Serial.println(touchRead(pinLeft));
    delay(dt);
  }

  if (touchRead(pinLeft) <= sensitivity)
  {
    Serial.println(touchRead(pinLeft));
    delay(dt);
  }

  if (touchRead(pinDown) <= sensitivity)
  {
    Serial.println(touchRead(pinDown));
    delay(dt);
  }
  if (touchRead(pinUp) <= sensitivity)
  {
    Serial.println(touchRead(pinUp));
    delay(dt);
  }
  

}

Who is online

Users browsing this forum: No registered users and 111 guests