From 23c5ddce831370a5ead04b1a4984761677c29de7 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Fri, 28 May 2021 18:21:16 +0200 Subject: [PATCH] Added inverted analog button. --- wled00/button.cpp | 7 +++++-- wled00/const.h | 1 + wled00/data/settings_leds.htm | 1 + wled00/html_settings.h | 2 +- wled00/wled.h | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/wled00/button.cpp b/wled00/button.cpp index 28cecde4c..4bbd53da3 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -74,6 +74,9 @@ void handleAnalog(uint8_t b) #else uint16_t aRead = analogRead(btnPin[b]) >> 4; // convert 12bit read to 8bit #endif + + if (buttonType[b] == BTN_TYPE_ANALOG_INVERTED) aRead = 255 - aRead; + // remove noise & reduce frequency of UI updates aRead &= 0xFC; @@ -149,12 +152,12 @@ void handleButton() for (uint8_t b=0; b 250) { // button is not a button but a potentiometer + if ((buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) && millis() - lastRead > 250) { // button is not a button but a potentiometer if (b+1 == WLED_MAX_BUTTONS) lastRead = millis(); handleAnalog(b); continue; } diff --git a/wled00/const.h b/wled00/const.h index 2596eb9b8..9436d7dd9 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -161,6 +161,7 @@ #define BTN_TYPE_SWITCH_ACT_HIGH 5 #define BTN_TYPE_TOUCH 6 #define BTN_TYPE_ANALOG 7 +#define BTN_TYPE_ANALOG_INVERTED 8 //Ethernet board types #define WLED_NUM_ETH_TYPES 5 diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 047f0c056..e1fa89306 100644 --- a/wled00/data/settings_leds.htm +++ b/wled00/data/settings_leds.htm @@ -308,6 +308,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 f7f131db4..8d25f64b2 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -74,7 +74,7 @@ Do not enable if WiFi is working correctly, increases power consumption.
LED Settings