From 862c2179c004dcbae1fee4538d0c10d1be0f34df Mon Sep 17 00:00:00 2001 From: starcalc Date: Sat, 25 Nov 2017 13:43:59 +0100 Subject: [PATCH] =?UTF-8?q?Beat-Handler=20eingebaut,=20Vorbereitung=20f?= =?UTF-8?q?=C3=BCr=20Strobo-Effekt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp-deckenlicht.ino | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/esp-deckenlicht.ino b/esp-deckenlicht.ino index 3e207d1..5fcfee1 100644 --- a/esp-deckenlicht.ino +++ b/esp-deckenlicht.ino @@ -20,6 +20,7 @@ int w1; int w2; int w3; int step = 0; +int strobo = 1; bool disco = false; int lastEvent = 0; @@ -36,6 +37,62 @@ bool speedHandler(const HomieRange& range, const String& value) { return true; } +bool stroboToggleHandler(const HomieRange& range, const String& value) { + Homie.getLogger() << "stroboToggle " << ": " << value << endl; + lightNode.setProperty("stroboToggle").send(value); + strobo *= -1; + if (strobo == 1) + { + w0 = w1 = w2 = w3 = FULL; + } + else + { + w0 = w1 = w2 = w3 = OFF; + } + output(); +} + +bool beatHandler(const HomieRange& range, const String& value) { + Homie.getLogger() << "beat " << ": " << value << endl; + lightNode.setProperty("beat").send(value); + if (step >= 4) { + step = 0; + } + // Cycle each light from 255 to 50 to 1 to off + switch (step) + { + case 0: + w0 = FULL; + w1 = OFF; + w2 = MINIMUM; + w3 = LOWER; + break; + case 1: + w1 = FULL; + w2 = OFF; + w3 = MINIMUM; + w0 = LOWER; + break; + case 2: + w2 = FULL; + w3 = OFF; + w0 = MINIMUM; + w1 = LOWER; + break; + case 3: + w3 = FULL; + w0 = OFF; + w1 = MINIMUM; + w2 = LOWER; + break; + default: + w0 = w1 = w2 = w3 = 0; + break; + } + output(); + step++; +} + bool discoHandler(const HomieRange& range, const String& value) { Homie.getLogger() << "disco " << ": " << value << endl; lightNode.setProperty("disco").send(value); @@ -177,6 +234,7 @@ void setup() { lightNode.advertise("speed").settable(speedHandler); lightNode.advertise("disco").settable(discoHandler); + lightNode.advertise("beat").settable(beatHandler); lightNode.advertise("light").settable(lightHandler); lightNode.advertise("light0").settable(light0Handler); lightNode.advertise("light1").settable(light1Handler);