Created
March 20, 2017 09:46
-
-
Save hhayley/53f74d6c2a73082916bd3e25606bfad6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
int ledPin = 5; | |
void setup() | |
{ | |
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example | |
Serial.begin(9600); | |
pinMode(ledPin, OUTPUT); | |
analogWrite(ledPin, 0); | |
} | |
void loop() | |
{ | |
long start = millis(); | |
long total1 = cs_4_2.capacitiveSensor(30); | |
Serial.println(total1); // print sensor output 1 | |
if (total1 > 70) { | |
analogWrite(ledPin, total1 * 3); | |
} else { | |
analogWrite(ledPin, 0); | |
} | |
delay(10); // arbitrary delay to limit data to serial port | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment