Sensor entfernt
This commit is contained in:
parent
2571f871d3
commit
4c07244426
|
@ -6,12 +6,10 @@
|
||||||
#include "NeoPatterns.h"
|
#include "NeoPatterns.h"
|
||||||
|
|
||||||
#define PIN D1
|
#define PIN D1
|
||||||
#define SENSOR D0
|
|
||||||
#define NUMPIXELS 80
|
#define NUMPIXELS 80
|
||||||
|
|
||||||
|
#define FW_NAME "esp-schild"
|
||||||
|
#define FW_VERSION "1.0.1"
|
||||||
bool lastSensorValue = false;
|
|
||||||
|
|
||||||
void StripComplete(){
|
void StripComplete(){
|
||||||
return;
|
return;
|
||||||
|
@ -20,9 +18,6 @@ void StripComplete(){
|
||||||
NeoPatterns pixels = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800,&StripComplete);
|
NeoPatterns pixels = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800,&StripComplete);
|
||||||
|
|
||||||
HomieNode stripNode("strip", "strip");
|
HomieNode stripNode("strip", "strip");
|
||||||
HomieNode sensorNode("sensor", "sensor");
|
|
||||||
Bounce debouncer = Bounce();
|
|
||||||
|
|
||||||
|
|
||||||
bool onSetColor(const HomieRange& range, const String& value){
|
bool onSetColor(const HomieRange& range, const String& value){
|
||||||
if (!range.isRange || range.index < 0 || range.index > 1) {
|
if (!range.isRange || range.index < 0 || range.index > 1) {
|
||||||
|
@ -39,9 +34,6 @@ bool onSetColor(const HomieRange& range, const String& value){
|
||||||
stripNode.setProperty("color_" + String(range.index)).send(value);
|
stripNode.setProperty("color_" + String(range.index)).send(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool onSetPixel(const HomieRange& range, const String& value){
|
bool onSetPixel(const HomieRange& range, const String& value){
|
||||||
if(!range.isRange) {
|
if(!range.isRange) {
|
||||||
pixels.None();
|
pixels.None();
|
||||||
|
@ -115,22 +107,13 @@ bool onSetLength(const HomieRange& range, const String& value){
|
||||||
|
|
||||||
void loopHandler() {
|
void loopHandler() {
|
||||||
pixels.Update();
|
pixels.Update();
|
||||||
|
|
||||||
bool sensorValue = debouncer.read();
|
|
||||||
if (Homie.isConfigured() && Homie.isConnected() && sensorValue != lastSensorValue) {
|
|
||||||
sensorNode.setProperty("motion").send(sensorValue ? "true" : "false");
|
|
||||||
lastSensorValue = sensorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
debouncer.attach(SENSOR,INPUT);
|
Homie_setFirmware(FW_NAME, FW_VERSION);
|
||||||
debouncer.interval(50);
|
Homie_setBrand(FW_NAME);
|
||||||
|
|
||||||
Homie_setFirmware("schild", "1.0.0");
|
|
||||||
Homie.setLoopFunction(loopHandler);
|
Homie.setLoopFunction(loopHandler);
|
||||||
|
|
||||||
stripNode.advertiseRange("pixel", 0, NUMPIXELS-1).settable(onSetPixel);
|
stripNode.advertiseRange("pixel", 0, NUMPIXELS-1).settable(onSetPixel);
|
||||||
|
@ -140,8 +123,6 @@ void setup() {
|
||||||
stripNode.advertise("clear").settable(onSetClear);
|
stripNode.advertise("clear").settable(onSetClear);
|
||||||
stripNode.advertise("length").settable(onSetLength);
|
stripNode.advertise("length").settable(onSetLength);
|
||||||
|
|
||||||
sensorNode.advertise("motion");
|
|
||||||
|
|
||||||
pixels.begin();
|
pixels.begin();
|
||||||
pixels.clear();
|
pixels.clear();
|
||||||
pixels.setBrightness(64);
|
pixels.setBrightness(64);
|
||||||
|
@ -150,7 +131,7 @@ void setup() {
|
||||||
Homie.setup();
|
Homie.setup();
|
||||||
|
|
||||||
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
|
ArduinoOTA.setHostname(Homie.getConfiguration().deviceId);
|
||||||
ArduinoOTA.setPassword((const char *)"ctdo2342");
|
// ArduinoOTA.setPassword((const char *)"ctdo2342");
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
pixels.clear();
|
pixels.clear();
|
||||||
});
|
});
|
||||||
|
@ -166,6 +147,5 @@ void setup() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
Homie.loop();
|
Homie.loop();
|
||||||
debouncer.update();
|
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue