From 2d842ee221cf63a4159893263c4c924a342aab9b Mon Sep 17 00:00:00 2001 From: Michel Date: Sun, 16 Nov 2014 14:31:21 +0100 Subject: [PATCH] v1.0.0 --- Sketch/Sketch.ino | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Sketch/Sketch.ino diff --git a/Sketch/Sketch.ino b/Sketch/Sketch.ino new file mode 100644 index 0000000..65958f1 --- /dev/null +++ b/Sketch/Sketch.ino @@ -0,0 +1,79 @@ +#include + +// Variabelen +int kakuUnit = 14; + +NewRemoteTransmitter transmitter(10911174, 11, 260, 1); + +int sensorValue; +int pot1Value; // Switch +int pot2Value; // Threshold +int pot3Value; // Dim Level + +int switchValueHigh; +int switchValueLow; + +int dimLevel = 0; +int currentDimLevel = -1; +int currentState = -1; + +// LED pin +const int ledPin = 13; + +void setup() { + Serial.begin(9600); + + pinMode(ledPin, OUTPUT); +} + +void loop() { + sensorValue = analogRead(A0); + pot1Value = analogRead(A1); + pot2Value = analogRead(A2); + pot3Value = analogRead(A3); + + switchValueHigh = pot1Value+(pot2Value/2); + if (switchValueHigh > 1023) { + switchValueHigh = 1023; + } + switchValueLow = pot1Value-(pot2Value/2); + if (switchValueLow < 0) { + switchValueLow = 0; + } + + dimLevel = map(pot3Value, 0, 1023, 0, 15); + + Serial.print("Sensor: "); + Serial.println(sensorValue); + Serial.print("Pot 1: "); + Serial.println(pot1Value); + Serial.print("Pot 2: "); + Serial.println(pot2Value); + Serial.print("Pot 3: "); + Serial.println(pot3Value); + Serial.print("Dim Level: "); + Serial.println(dimLevel); + Serial.println(""); + + if(sensorValue <= switchValueHigh && currentDimLevel != dimLevel){ + digitalWrite(ledPin, HIGH); + //transmitter.sendUnit(10, true); + transmitter.sendDim(kakuUnit, dimLevel); + currentDimLevel = dimLevel; + currentState = 1; + Serial.println("Schakel: aan"); + Serial.println(""); + } + else if(sensorValue >= switchValueLow && currentState == 1) { + digitalWrite(ledPin, LOW); + transmitter.sendUnit(10, false); + currentDimLevel = -1; + currentState = 0; + Serial.println("Schakel: uit"); + Serial.println(""); + } + + //delay(long(1000)*long(60)); + delay(1000); +} +