Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <CapacitiveSensor.h>
- #include "RunningMedian.h"
- /*
- * CapitiveSense Library Demo Sketch
- * Paul Badger 2008
- * Uses a high value resistor e.g. 10 megohm between send pin and receive pin
- * Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values.
- * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
- * Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
- */
- RunningMedian samples = RunningMedian(100);
- RunningMedian samples2 = RunningMedian(100);
- long count = 0;
- int i = 0;
- CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
- CapacitiveSensor cs_8_7 = CapacitiveSensor(8,7); // 10 megohm resistor between pins 4 & 6, pin 6 is sensor pin, add wire, foil
- //CapacitiveSensor cs_4_8 = CapacitiveSensor(4,8); // 10 megohm resistor between pins 4 & 8, pin 8 is sensor pin, add wire, foil
- void setup()
- {
- pinMode(A0, INPUT);
- //digitalWrite(A0, LOW);
- cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
- Serial.begin(115200);
- }
- void loop()
- {
- long start = millis();
- unsigned long int total1 = cs_4_2.capacitiveSensor(30);
- unsigned long int total2 = cs_8_7.capacitiveSensor(30);
- //Serial.print("A0 : ");
- //Serial.print(analogRead(A0));
- Serial.print(" Total 1 : ");
- Serial.print(total1);
- Serial.print(" Total 2 : ");
- Serial.println(total2);
- delay(100);
- while ((total1 >= 200) && (i <101))
- {
- long total1 = cs_4_2.capacitiveSensor(30);
- long total2 = cs_8_7.capacitiveSensor(30);
- Serial.print("A0 : ");
- Serial.print(analogRead(A0));
- Serial.print("Total 1 : ");
- Serial.print(total1);
- Serial.print(" Total2 : ");
- Serial.println(total2);
- samples.add(total1);
- samples2.add(total2);
- i++;
- delay(100);
- if (total1 <= 200)
- break;
- }
- float m = samples.getMedian();
- float n = samples2.getMedian();
- Serial.print("m : ");
- Serial.print(m);
- Serial.print(" n : ");
- Serial.println(n);
- }
Add Comment
Please, Sign In to add comment