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