I written a code for esp32s3 for reading touch values i am unable to fix one threshold value for all the touch pins i am getting a touch values like 19587,25534,38654 how can i set one threshould for all the values
int touchpin = 1; // Replace with the desired touch pin
int touchpin1=2;
int touchpin2=3;
int touchpin3=4;
int touchpin4=5;
int touchpin5=6;
int touchpin6=7;
int touchpin7=8;
int touchpin8=9;
int touchpin9=10;
int touchpin10=11;
int ledPin = 42;
int ledPin1 = 41;
int ledPin2 = 40;
int ledPin3= 39;
int ledPin4= 38;
int ledPin5= 37;
int ledPin6= 36;
int ledPin7= 35;
int ledPin8= 34;
int ledPin9= 26;
int ledPin10= 33;
int threshold = 30000;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
pinMode(ledPin1, OUTPUT);
digitalWrite(ledPin1, LOW);
pinMode(ledPin2, OUTPUT);
digitalWrite(ledPin2, LOW);
pinMode(ledPin3, OUTPUT);
digitalWrite(ledPin3, LOW);
pinMode(ledPin4, OUTPUT);
digitalWrite(ledPin4, LOW);
pinMode(ledPin5, OUTPUT);
digitalWrite(ledPin5, LOW);
pinMode(ledPin6, OUTPUT);
digitalWrite(ledPin6, LOW);
pinMode(ledPin7, OUTPUT);
digitalWrite(ledPin7, LOW);
pinMode(ledPin8, OUTPUT);
digitalWrite(ledPin8, LOW);
}
void loop() {
int touchValue = touchRead(touchpin);
int touchValue1 = touchRead(touchpin1);
int touchValue2 = touchRead(touchpin2);
int touchValue3 = touchRead(touchpin3);
int touchValue4 = touchRead(touchpin4);
int touchValue5 = touchRead(touchpin5);
int touchValue6 = touchRead(touchpin6);
int touchValue7 = touchRead(touchpin7);
int touchValue8 = touchRead(touchpin8);
Serial.println("TV:");
Serial.println(touchValue);
Serial.println("TV1:");
Serial.println(touchValue1);
Serial.println("TV2:");
Serial.println(touchValue2);
Serial.println("TV3:");
Serial.println(touchValue3);
Serial.println("TV4:");
Serial.println(touchValue4);
Serial.println("TV5:");
Serial.println(touchValue5);
Serial.println("TV6:");
Serial.println(touchValue6);
Serial.println("TV7:");
Serial.println(touchValue7);
Serial.println("TV8:");
Serial.println(touchValue8);
if (touchValue < threshold) {
digitalWrite(ledPin, HIGH); // Turn LED on
} else {
digitalWrite(ledPin, LOW); // Turn LED off
}
if (touchValue1 < threshold) {
digitalWrite(ledPin1, HIGH); // Turn LED on
} else {
digitalWrite(ledPin1, LOW); // Turn LED off
}
if (touchValue2 < threshold) {
digitalWrite(ledPin2, HIGH); // Turn LED on
} else {
digitalWrite(ledPin2, LOW); // Turn LED off
}
if (touchValue3 < threshold) {
digitalWrite(ledPin3, HIGH); // Turn LED on
} else {
digitalWrite(ledPin3, LOW); // Turn LED off
}
if (touchValue4 < threshold) {
digitalWrite(ledPin4, HIGH); // Turn LED on
} else {
digitalWrite(ledPin4, LOW); // Turn LED off
}
if (touchValue5 < threshold) {
digitalWrite(ledPin5, HIGH); // Turn LED on
} else {
digitalWrite(ledPin5, LOW); // Turn LED off
}
if (touchValue6 < threshold) {
digitalWrite(ledPin6, HIGH); // Turn LED on
} else {
digitalWrite(ledPin6, LOW); // Turn LED off
}
if (touchValue < threshold) {
digitalWrite(ledPin7, HIGH); // Turn LED on
} else {
digitalWrite(ledPin7, LOW); // Turn LED off
}
if (touchValue8 < threshold) {
digitalWrite(ledPin8, HIGH); // Turn LED on
} else {
digitalWrite(ledPin8, LOW); // Turn LED off
}
delay(100);
}