Added inverted analog button.

This commit is contained in:
Blaz Kristan 2021-05-28 18:21:16 +02:00
parent 3bb9d220bb
commit 23c5ddce83
5 changed files with 9 additions and 4 deletions

View File

@ -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<WLED_MAX_BUTTONS; b++) {
#ifdef ESP8266
if ((btnPin[b]<0 && buttonType[b] != BTN_TYPE_ANALOG) || buttonType[b] == BTN_TYPE_NONE) continue;
if ((btnPin[b]<0 && !(buttonType[b] == BTN_TYPE_ANALOG) || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) || buttonType[b] == BTN_TYPE_NONE) continue;
#else
if (btnPin[b]<0 || buttonType[b] == BTN_TYPE_NONE) continue;
#endif
if (buttonType[b] == BTN_TYPE_ANALOG && millis() - lastRead > 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;
}

View File

@ -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

View File

@ -308,6 +308,7 @@ Reverse (rotated 180°): <input type="checkbox" name="CV${i}">
c += `<option value="5" ${t==5?"selected":""}>Switch inverted</option>`;
c += `<option value="6" ${t==6?"selected":""}>Touch</option>`;
c += `<option value="7" ${t==7?"selected":""}>Analog</option>`;
c += `<option value="8" ${t==8?"selected":""}>Analog inverted</option>`;
c += `</select>`;
c += `<span style="cursor: pointer;" onclick="off('${bt}')">&nbsp;&#215;</span><br>`;
gId("btns").innerHTML = c;

File diff suppressed because one or more lines are too long

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2105281
#define VERSION 2105282
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG