Create wled06_usermod.ino

Using rotary encoder, control effect or brightness
This commit is contained in:
ohminy 2019-12-12 23:01:13 +09:00 committed by GitHub
parent bd435b175b
commit 9526051766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
}