Last active
November 17, 2020 03:44
-
-
Save shfitz/4a7607a407333446e8b9870f2e3c8226 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> | |
// create an instance of the library. pin 2 is the sensor | |
CapacitiveSensor capsense = CapacitiveSensor(4, 2); | |
void setup() { | |
// start serial | |
Serial.begin(9600); | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop() { | |
// store the sense value - argument is number of samples to take | |
long val = capsense.capacitiveSensor(30); | |
// if the sensor val is greater than 30, turn the LED on | |
if(val > 30){ | |
digitalWrite(LED_BUILTIN, HIGH); | |
}else{ // otherwise turn it off | |
digitalWrite(LED_BUILTIN, LOW); | |
} | |
// print the info to the serial monitor | |
Serial.print("capacitive sense value: "); | |
Serial.println(val); // print sensor output | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment