From 9526051766e7b6a2dede5d53b8322d0d6e9c3693 Mon Sep 17 00:00:00 2001 From: ohminy <46082430+ohminy@users.noreply.github.com> Date: Thu, 12 Dec 2019 23:01:13 +0900 Subject: [PATCH] Create wled06_usermod.ino Using rotary encoder, control effect or brightness --- .../wled06_usermod.ino | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 usermods/rotary_encoder_change_effect/wled06_usermod.ino diff --git a/usermods/rotary_encoder_change_effect/wled06_usermod.ino b/usermods/rotary_encoder_change_effect/wled06_usermod.ino new file mode 100644 index 00000000..dbde9560 --- /dev/null +++ b/usermods/rotary_encoder_change_effect/wled06_usermod.ino @@ -0,0 +1,45 @@ +//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t) + +long lastTime = 0; +int delayMs = 10; +const int pinA = D6; //data +const int pinB = D7; //clk +int oldA = LOW; + +//gets called once at boot. Do all initialization that doesn't depend on network here +void userSetup() { + pinMode(pinA, INPUT_PULLUP); + pinMode(pinB, INPUT_PULLUP); +} + +//gets called every time WiFi is (re-)connected. Initialize own network interfaces here +void userConnected() { +} + +//loop. You can use "if (WLED_CONNECTED)" to check for successful connection +void userLoop() { + if (millis()-lastTime > delayMs) { + int A = digitalRead(pinA); + int B = digitalRead(pinB); + + if (oldA == LOW && A == HIGH) { + if (oldB == HIGH) { + // bri += 10; + // if (bri > 250) bri = 10; + effectCurrent += 1; + if (effectCurrent >= MODE_COUNT) effectCurrent = 0; + } + else { + // bri -= 10; + // if (bri < 10) bri = 250; + effectCurrent -= 1; + if (effectCurrent < 0) effectCurrent = (MODE_COUNT-1); + } + oldA = A; + + //call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (No notification) + // 6: fx changed 7: hue 8: preset cycle 9: blynk 10: alexa + colorUpdated(6); + lastTime = millis(); + } +}