Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <CapacitiveSensor.h>
- /*
- * 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(9,8); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
- CapacitiveSensor cs_4_6 = CapacitiveSensor(9,7); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
- CapacitiveSensor cs_4_8 = CapacitiveSensor(9,10); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
- long nonloop = 0;
- void setup()
- {
- Serial.begin(9600);
- }
- void loop()
- {
- long start = millis();
- long total1 = cs_4_2.capacitiveSensor(3);
- long total2 = cs_4_6.capacitiveSensor(10);
- long total3 = cs_4_8.capacitiveSensor(3);
- //Serial.print(millis() - start); // check on performance in milliseconds
- //Serial.print("\t"); // tab character for debug windown spacing
- if(total1>1000){
- if(nonloop!=1){
- Serial.print("A");
- // Serial.print(total1); // print sensor output 1
- Serial.print("\n");
- delay(3);
- // print sensor output 1
- nonloop = 1;
- }}
- if(total2>500){
- if(nonloop!=2){
- Serial.print("B");
- // Serial.print(total2); // print sensor output 1
- Serial.print("\n");
- delay(3);
- nonloop = 2;
- }}
- if(total3>1000){
- if(nonloop!=3){
- Serial.print("C");
- // Serial.print(nonloop);
- // Serial.print(total3); // print sensor output 1
- Serial.print("\n");
- delay(3);
- // print sensor output 1
- nonloop = 3;
- }}
- //Serial.print("\t");
- // print sensor output 2
- // Serial.print("\t");
- // Serial.println(total3); // print sensor output 3
- delay(3); // arbitrary delay to limit data to serial port
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement