Skip to content

Instantly share code, notes, and snippets.

@pral2a
Created March 23, 2014 12:13
Show Gist options
  • Save pral2a/9722280 to your computer and use it in GitHub Desktop.
Save pral2a/9722280 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 && (currentTime - prevTimeChanged > 2000)) {
prevTimeChanged = currentTime;
if (isOn) {
isOn = false;
digitalWrite(13, LOW);
}
else {
isOn = true;
digitalWrite(13, HIGH);
}
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment