Last active
September 11, 2018 09:33
-
-
Save AnandChowdhary/42d67d1d07fc968a684f03e0705c4978 to your computer and use it in GitHub Desktop.
Capacitive Sensor
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> | |
CapacitiveSensor c = CapacitiveSensor(13, 12); | |
float observedRightValue = 1750.0; | |
float observedLeftValue= 5000.0; | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
float capacitorValue = c.capacitiveSensor(30); | |
// How far the finger is from left to right | |
if (capacitorValue > observedLeftValue || capacitorValue < observedRightValue) { | |
// The finger isn't touching the capacitor | |
} else { | |
float valueInCentimeters = (observedLeftValue - capacitorValue) / (observedLeftValue - observedRightValue) * 8; | |
Serial.println(valueInCentimeters); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment