This is probably an easy answer for the seasoned people here.. but i need help. I am want to use my Leonardo board to sense capacitance. I am using the capsense library. I have everything set up correctly and I get capacitance readings that spike when my hand is near or touching the sensor. Works perfectly. The part of the code that is killing me is being able to actually make an output pin turn on when the readings pass a set point. An if statement is not working. I am stuck
#include <CapacitiveSensor.h>
CapacitiveSensor cs_8_4 = CapacitiveSensor(8,4); // 10M resistor between pins 8 & 4, pin 4 is sensor pin, add a wire and or foil
int led = 13;
void setup()
{
cs_8_4.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
pinMode (led, OUTPUT);
Serial.begin(9600); // initialize serial communications
}
void loop()
{
long start = millis();
long totalCap = cs_8_4.capacitiveSensor(30);
Serial.print(millis() - start); // check on performance in milliseconds
Serial.print("\t"); // tab character for debug windown spacing
Serial.print(totalCap); // print sensor output 1
if (totalCap > 500){
digitalWrite(led, HIGH);
}
delay(1000); // arbitrary delay to limit data to serial port
}
I can watch the output on the monitor jump from around 12 to 1200 as often as i move my hand near it but the output is not responding. I am using pin 13.. the led pin.. just as an example right now to see if i can turn that pin on.