parent
2994070e89
commit
f76b610021
|
@ -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() {
|
||||
|
@ -156,6 +167,10 @@ void setup() {
|
|||
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);
|
||||
Homie.setLoopFunction(loopHandler);
|
||||
|
@ -168,6 +183,8 @@ void setup() {
|
|||
lightNode.advertise("light2").settable(light2Handler);
|
||||
lightNode.advertise("light3").settable(light3Handler);
|
||||
|
||||
sensorNode.advertise("motion");
|
||||
|
||||
Homie.setup();
|
||||
|
||||
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
|
||||
|
@ -176,6 +193,7 @@ void setup() {
|
|||
|
||||
void loop() {
|
||||
Homie.loop();
|
||||
debouncer.update();
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue