]> git.piffa.net Git - sketchbook_andrea/blob - libraries/CapacitiveSensor/examples/CapacitiveSensorSketch/CapacitiveSensorSketch.pde
Capacitance fir st commit,
[sketchbook_andrea] / libraries / CapacitiveSensor / examples / CapacitiveSensorSketch / CapacitiveSensorSketch.pde
1 #include <CapacitiveSensor.h>
2
3 /*
4  * CapitiveSense Library Demo Sketch
5  * Paul Badger 2008
6  * Uses a high value resistor e.g. 10M between send pin and receive pin
7  * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.
8  * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
9  */
10
11
12 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
13 CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
14 CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
15
16 void setup()                    
17 {
18    cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
19    Serial.begin(9600);
20 }
21
22 void loop()                    
23 {
24     long start = millis();
25     long total1 =  cs_4_2.capacitiveSensor(30);
26     long total2 =  cs_4_6.capacitiveSensor(30);
27     long total3 =  cs_4_8.capacitiveSensor(30);
28
29     Serial.print(millis() - start);        // check on performance in milliseconds
30     Serial.print("\t");                    // tab character for debug windown spacing
31
32     Serial.print(total1);                  // print sensor output 1
33     Serial.print("\t");
34     Serial.print(total2);                  // print sensor output 2
35     Serial.print("\t");
36     Serial.println(total3);                // print sensor output 3
37
38     delay(10);                             // arbitrary delay to limit data to serial port 
39 }