Input Sensor for motion
This commit is contained in:
parent
7e308b3f07
commit
0a4eda713d
|
@ -6,12 +6,12 @@
|
|||
#include "NeoPatterns.h"
|
||||
|
||||
#define PIN D1
|
||||
#define SENSOR D3
|
||||
#define NUMPIXELS 144
|
||||
|
||||
|
||||
|
||||
byte wPos = 0;
|
||||
uint8_t state = 0;
|
||||
bool lastSensorValue = false;
|
||||
|
||||
void StripComplete(){
|
||||
return;
|
||||
|
@ -20,6 +20,8 @@ void StripComplete(){
|
|||
NeoPatterns pixels = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800,&StripComplete);
|
||||
|
||||
HomieNode stripNode("strip", "strip");
|
||||
HomieNode sensorNode("sensor", "sensor");
|
||||
Bounce debouncer = Bounce();
|
||||
|
||||
bool onSetPixel(const HomieRange& range, const String& value){
|
||||
if(!range.isRange) {
|
||||
|
@ -60,12 +62,11 @@ bool onSetEffect(const HomieRange& range, const String& value){
|
|||
pixels.TheaterChase(pixels.Color(0,0,255), pixels.Color(255,0,00), 100);
|
||||
}
|
||||
else if(effect == "fade") {
|
||||
pixels.Fade(pixels.Wheel(255),pixels.Wheel(0),255,25);
|
||||
pixels.Fade(pixels.Wheel(0),pixels.Wheel(255),pixels.Color(255,255,255),25);
|
||||
}
|
||||
else {
|
||||
pixels.None();
|
||||
}
|
||||
|
||||
stripNode.setProperty("effect").send(value);
|
||||
}
|
||||
|
||||
|
@ -89,19 +90,33 @@ bool onSetLength(const HomieRange& range, const String& value){
|
|||
|
||||
void loopHandler() {
|
||||
pixels.Update();
|
||||
|
||||
int sensorValue = debouncer.read();
|
||||
if (Homie.isConfigured() && Homie.isConnected() && sensorValue != lastSensorValue) {
|
||||
sensorNode.setProperty("motion").send(sensorValue ? "true" : "false");
|
||||
lastSensorValue = sensorValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
debouncer.attach(SENSOR,INPUT);
|
||||
debouncer.interval(50);
|
||||
|
||||
Homie_setFirmware("schild", "1.0.0");
|
||||
Homie.setLoopFunction(loopHandler);
|
||||
|
||||
|
||||
stripNode.advertiseRange("pixel", 0, NUMPIXELS-1).settable(onSetPixel);
|
||||
stripNode.advertise("brightness").settable(onSetBrightness);
|
||||
stripNode.advertise("effect").settable(onSetEffect);
|
||||
stripNode.advertise("clear").settable(onSetClear);
|
||||
stripNode.advertise("length").settable(onSetLength);
|
||||
|
||||
sensorNode.advertise("motion");
|
||||
|
||||
pixels.begin();
|
||||
pixels.clear();
|
||||
pixels.setBrightness(64);
|
||||
|
@ -116,5 +131,6 @@ void setup() {
|
|||
|
||||
void loop() {
|
||||
Homie.loop();
|
||||
debouncer.update();
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ platform=espressif8266
|
|||
board=d1_mini
|
||||
framework=arduino
|
||||
|
||||
;upload_port = /dev/tty.wchusbserial640
|
||||
;upload_port = /dev/tty.wchusbserial410
|
||||
;upload_speed = 921600
|
||||
|
||||
;upload_port = 5ccf7f1db369.local
|
||||
|
|
Loading…
Reference in New Issue