Skip to content

Instantly share code, notes, and snippets.

@pral2a
Created March 23, 2014 17:52
Show Gist options
  • Save pral2a/9726829 to your computer and use it in GitHub Desktop.
Save pral2a/9726829 to your computer and use it in GitHub Desktop.
#include <CapacitiveSensor.h>
CapacitiveSensor capSensor = CapacitiveSensor(4,2);
boolean isOn = false;
long prevTimeChanged = 0;
void setup() {
// open a serial connection
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
long sensorValue = capSensor.capacitiveSensor(300);
Serial.println(sensorValue);
long currentTime = millis();
if(sensorValue > 50.0) {
if (currentTime - prevTimeChanged > 2000) {
if (isOn) {
isOn = false;
digitalWrite(13, LOW);
}
else {
isOn = true;
digitalWrite(13, HIGH);
}
}
}
else {
prevTimeChanged = currentTime;
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment