Hi,
I'm making a thing that produces a different color light depending on which touch sensor I touch (and if possible a combination of touch sensors). I don't know how to code in more than one touch sensor, as I tried just adding another if/else statement, but the serial monitor kept giving back negative values.
Could anyone please teach me to code in more than one sensor???
Here is my code for one:
#include <CapacitiveSensor.h>
CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2);
// threshold for turning the LED on
int threshold = 200;
// states the led is connected to 13
const int blue = 13;
const int green = 12;
void setup() {
// put your setup code here, to run once:
// open a serial connection
Serial.begin(9600);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// store the value reported by the sesnor as a number
long sensorValue = cs_4_2.capacitiveSensor(30);
// print out sensor value
Serial.println(sensorValue);
// if the value is greater than the threshold
if (sensorValue > threshold) {
// turn the LED on
digitalWrite(blue, HIGH);
digitalWrite(green,LOW);
}
else {
digitalWrite(blue, LOW);
digitalWrite(green,HIGH);
}
delay(10);
}