diff options
author | jakobst1n <jakob.stendahl@outlook.com> | 2018-07-19 12:58:36 +0200 |
---|---|---|
committer | jakobst1n <jakob.stendahl@outlook.com> | 2018-07-19 12:58:36 +0200 |
commit | 8afb6934e01d3560203f53cc0fb4e0b975801467 (patch) | |
tree | 46c045c6ade28f2ce73a66b747f7f3d05f20f37d | |
parent | 724a4b85c0240bc11c04d8e3967528ff5efc3e6c (diff) | |
download | Luxcena-cs-8afb6934e01d3560203f53cc0fb4e0b975801467.tar.gz Luxcena-cs-8afb6934e01d3560203f53cc0fb4e0b975801467.zip |
Renamed file, added clapping thing
-rw-r--r-- | Luxcena-cs.ino (renamed from IOT-clapSensor.ino) | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/IOT-clapSensor.ino b/Luxcena-cs.ino index cba7e01..41bef63 100644 --- a/IOT-clapSensor.ino +++ b/Luxcena-cs.ino @@ -153,6 +153,11 @@ void setup ( void ) { Serial.println ( "HTTP server started" ); } + +int sensorValue = 0; +int eventStatus = 0; +int sensorThresholdHigh = 870; +int sensorthresholdLow = 500; void loop ( void ) { server.handleClient(); @@ -171,6 +176,41 @@ void loop ( void ) { if (!sensorActive) { return; } // We can return to the beginning if the sensor is inactive + eventStatus = 0; + sensorValue = analogRead(A0); + delay(1); + + if (eventStatus == 0) { + if (sensorValue > sensorThresholdHigh) { + eventStatus = 1; + } + } + if (eventStatus == 0) { + for (int i = 0; i > 10; i++) { + sensorValue = analogRead(A0); + if(sensorValue < sensorthresholdLow) { + eventStatus = 2; + break; + } + } + } + if (eventStatus == 2) { + for (int i = 0; i < 500; i++) { + sensorValue = analogRead(A0); + delay(1); + if (sensorValue > sensorThresholdHigh) { + eventStatus = 3; + break; + } + } + } + if (eventStatus == 3) { + setLamp("TOGGLE"); + } + + + + /* currentMillis = millis(); if (currentMillis > lastSampleTime + sampleRate) { sample(); @@ -181,6 +221,7 @@ void loop ( void ) { bufferAlgo(); dumpBuffer(); } + */ } void sample() { |