You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.3 KiB
C++
60 lines
2.3 KiB
C++
#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(4,2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
|
|
CapacitiveSensor cs_4_3 = CapacitiveSensor(4,3); // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
|
|
CapacitiveSensor cs_4_5 = CapacitiveSensor(4,5); // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
|
|
|
|
void setup()
|
|
{
|
|
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
|
|
Serial.begin(9600);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
long start = millis();
|
|
long total1 = cs_4_2.capacitiveSensor(30);
|
|
long valCons1 = constrain(total1, 10000, 225000);
|
|
long mappedVal1 = map(valCons1, 10000, 225000, 0, 1024);
|
|
|
|
long total2 = cs_4_3.capacitiveSensor(30);
|
|
long valCons2 = constrain(total2, 10000, 225000);
|
|
long mappedVal2 = map(valCons2, 10000, 225000, 0, 1024);
|
|
|
|
long total3 = cs_4_5.capacitiveSensor(30);
|
|
long valCons3 = constrain(total3, 10000, 225000);
|
|
long mappedVal3 = map(valCons3, 10000, 225000, 0, 1024);
|
|
|
|
Serial.print(millis() - start); // check on performance in milliseconds
|
|
Serial.print("\t"); // tab character for debug windown spacing
|
|
|
|
Serial.print(total1); // print sensor output 1
|
|
Serial.print("\t");
|
|
Serial.print(total2); // print sensor output 2
|
|
Serial.print("\t");
|
|
Serial.println(total3); // print sensor output 3
|
|
|
|
Serial.print(valCons1);
|
|
Serial.print("\t");
|
|
Serial.print(valCons2);
|
|
Serial.print("\t");
|
|
Serial.println(valCons3);
|
|
|
|
Serial.print(mappedVal1);
|
|
Serial.print("\t");
|
|
Serial.print(mappedVal2);
|
|
Serial.print("\t");
|
|
Serial.println(mappedVal3);
|
|
|
|
delay(300); // arbitrary delay to limit data to serial port
|
|
}
|