diff --git a/wled00/button.cpp b/wled00/button.cpp index 26218c15..ced01781 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -35,8 +35,6 @@ bool isButtonPressed(uint8_t i) case BTN_TYPE_TOUCH: #ifdef ARDUINO_ARCH_ESP32 if (touchRead(btnPin[i]) <= touchThreshold) return true; - DEBUG_PRINT(F("Touch value: ")); - DEBUG_PRINTLN(touchRead(btnPin[i])); #endif break; } @@ -70,13 +68,52 @@ void handleSwitch(uint8_t b) } +void handleAnalog(uint8_t b) +{ + static uint8_t oldRead[WLED_MAX_BUTTONS]; + #ifdef ESP8266 + uint8_t aRead = analogRead(A0) >> 2; // convert 10bit read to 8bit + #else + uint8_t aRead = analogRead(btnPin[b]) >> 4; // convert 12bit read to 8bit + #endif + + if (oldRead[b] == aRead) return; // no change in reading + + // if no macro for "short press" and "long press" is defined use brightness control + if (!macroButton[b] && !macroLongPress[b]) { + // if "double press" macro is 250 or greater use global brightness + if (macroDoublePress[b]>=250) { + // if change in analog read was detected change global brightness + bri = aRead; + } else { + // otherwise use "double press" for segment selection + //uint8_t mainSeg = strip.getMainSegmentId(); + WS2812FX::Segment& seg = strip.getSegment(macroDoublePress[b]); + if (aRead == 0) { + seg.setOption(SEG_OPTION_ON, 0, macroDoublePress[b]); // off + } else { + seg.setOpacity(aRead, macroDoublePress[b]); + seg.setOption(SEG_OPTION_ON, 1, macroDoublePress[b]); + } + } + } else { + //TODO: + // we can either trigger a preset depending on the level (between short and long entries) + // or use it for RGBW direct control + } + colorUpdated(NOTIFIER_CALL_MODE_DIRECT_CHANGE); +} + void handleButton() { for (uint8_t b=0; b BTN_TYPE_NONE)) continue; + if (buttonType[b] == BTN_TYPE_ANALOG) { // button is not a button but a potentiometer + handleAnalog(b); continue; + } - if (buttonType[b] == BTN_TYPE_SWITCH) { //button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NOT gpio0) + if (buttonType[b] == BTN_TYPE_SWITCH || buttonType[b] == BTN_TYPE_SWITCH_ACT_HIGH) { //button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NOT gpio0) handleSwitch(b); continue; } diff --git a/wled00/const.h b/wled00/const.h index d26c8486..36c55c7e 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -160,6 +160,7 @@ #define BTN_TYPE_SWITCH 4 #define BTN_TYPE_SWITCH_ACT_HIGH 5 #define BTN_TYPE_TOUCH 6 +#define BTN_TYPE_ANALOG 7 //Ethernet board types #define WLED_NUM_ETH_TYPES 5 diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 504dbd2b..d5f9a0ef 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -288,6 +288,7 @@ Reverse (rotated 180°): c += ``; c += ``; c += ``; + c += ``; c += ``; c += ` ×
`; gId("btns").innerHTML = c; diff --git a/wled00/html_settings.h b/wled00/html_settings.h index 02ce7e47..d1dfcca0 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -73,7 +73,7 @@ Do not enable if WiFi is working correctly, increases power consumption.
LED Settings