Created
March 23, 2014 12:13
-
-
Save pral2a/9722280 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> | |
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