X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=advanced_projects%2Fcapacitance%2Fled_binary%2Fled_binary.ino;fp=advanced_projects%2Fcapacitance%2Fled_binary%2Fled_binary.ino;h=0cd3cb1e5271139cc21b9105f575d1287245464d;hb=fbdb4b8b83bbf79d73770f4d8a3e4170511ba6e7;hp=0000000000000000000000000000000000000000;hpb=22e41500749cb15583e70d04aa6088196d77da06;p=sketchbook_andrea diff --git a/advanced_projects/capacitance/led_binary/led_binary.ino b/advanced_projects/capacitance/led_binary/led_binary.ino new file mode 100644 index 0000000..0cd3cb1 --- /dev/null +++ b/advanced_projects/capacitance/led_binary/led_binary.ino @@ -0,0 +1,44 @@ +#include + +/* + * CapitiveSense Library Demo Sketch + * Paul Badger 2008 + * Uses a high value resistor e.g. 10M between send pin and receive pin + * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values. + * Receive pin is the sensor pin - try different amounts of foil/metal on this pin + */ + + +CapacitiveSensor cs_4_2 = CapacitiveSensor(4, 2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired +// pin 8 is sensor pin, add a wire and or foil +const int led = 13; // pin that the Piezo is attached to +int sensorMin = 50; // minimum sensor value +int sensorMax = 3200; // maximum sensor value +void setup() +{ + cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example + Serial.begin(9600); + pinMode(led, OUTPUT); +} + +void loop() +{ + long start = millis(); + long total1 = cs_4_2.capacitiveSensor(30); + + if (total1 > (sensorMax / 2 - sensorMin)) { + digitalWrite(led, HIGH); + delay(100); + } + else { + digitalWrite(led, LOW); + delay(100); + } + + Serial.print(millis() - start); // check on performance in milliseconds + Serial.print("\t Capacitance: "); // tab character for debug windown spacing + + Serial.println(total1); // print sensor output 1 + delay(1); // arbitrary delay to limit data to serial port + +}