PIR-Sensor am Pin D0 hinzugefügt.

ACHTUNG: UNTESTED!
This commit is contained in:
starcalc 2017-11-18 20:43:30 +01:00
parent 2994070e89
commit f76b610021
1 changed files with 18 additions and 0 deletions

View File

@ -5,6 +5,7 @@
#define PIN_LIGHT1 D6 #define PIN_LIGHT1 D6
#define PIN_LIGHT2 D7 #define PIN_LIGHT2 D7
#define PIN_LIGHT3 D8 #define PIN_LIGHT3 D8
#define PIN_SENSOR D0
#define FULL 255 #define FULL 255
#define LOWER 50 #define LOWER 50
@ -22,7 +23,11 @@ int step = 0;
bool disco = false; bool disco = false;
int lastEvent = 0; int lastEvent = 0;
bool lastSensorValue = false;
HomieNode lightNode("strip", "strip"); HomieNode lightNode("strip", "strip");
HomieNode sensorNode("sensor", "sensor");
Bounce debouncer = Bounce();
bool speedHandler(const HomieRange& range, const String& value) { bool speedHandler(const HomieRange& range, const String& value) {
Homie.getLogger() << "speed " << ": " << value << endl; Homie.getLogger() << "speed " << ": " << value << endl;
@ -145,6 +150,12 @@ void loopHandler()
step++; step++;
} }
} }
bool sensorValue = debouncer.read();
if (Homie.isConfigured() && Homie.isConnected() && sensorValue != lastSensorValue) {
sensorNode.setProperty("motion").send(sensorValue ? "true" : "false");
lastSensorValue = sensorValue;
}
} }
void setup() { void setup() {
@ -156,6 +167,10 @@ void setup() {
pinMode(PIN_LIGHT2, OUTPUT); pinMode(PIN_LIGHT2, OUTPUT);
pinMode(PIN_LIGHT3, OUTPUT); pinMode(PIN_LIGHT3, OUTPUT);
debouncer.attach(SENSOR_PIN,INPUT);
debouncer.interval(50);
Homie_setFirmware(FW_NAME, FW_VERSION); Homie_setFirmware(FW_NAME, FW_VERSION);
Homie_setBrand(FW_NAME); Homie_setBrand(FW_NAME);
Homie.setLoopFunction(loopHandler); Homie.setLoopFunction(loopHandler);
@ -168,6 +183,8 @@ void setup() {
lightNode.advertise("light2").settable(light2Handler); lightNode.advertise("light2").settable(light2Handler);
lightNode.advertise("light3").settable(light3Handler); lightNode.advertise("light3").settable(light3Handler);
sensorNode.advertise("motion");
Homie.setup(); Homie.setup();
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId); ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
@ -176,6 +193,7 @@ void setup() {
void loop() { void loop() {
Homie.loop(); Homie.loop();
debouncer.update();
ArduinoOTA.handle(); ArduinoOTA.handle();
} }