Hey guys,
For an assignment on my university i have to make a creative instrument. I want to make a capsense instrument with 3 wires but i have a problem with it. Everytime i touch one of the wires, a tone should be played. But when i touch a wire the tone keeps playing, even when i am not touching it anymore. Can someone help me??
here is my code:
#include <CapSense.h>
CapSense cs_4_2 = CapSense(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapSense cs_4_6 = CapSense(4,6); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapSense cs_4_8 = CapSense(4,8); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
int tone1 = 120;
int tone2 = 140;
int tone3 = 160;
void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(9600);
pinMode(11, OUTPUT);
}
void loop()
{
long start = millis();
long total1 = cs_4_2.capSense(30);
long total2 = cs_4_6.capSense(30);
long total3 = cs_4_8.capSense(30);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing
Serial.print(total1); // print sensor output 1
Serial.print("\t");
Serial.print(total2); // print sensor output 2
Serial.print("\t");
Serial.println(total3); // print sensor output 3
delay(10); // arbitrary delay to limit data to serial port
if(total1>300) analogWrite(11,tone1); else digitalWrite(tone1, LOW);
if(total2>300) analogWrite(11,tone2); else digitalWrite(tone2, LOW);
if(total3>300) analogWrite(11,tone3); else digitalWrite(tone3, LOW);
}
capsense_attempt_2.ino (1.86 KB)