WLED v0.13.0 button implementation example (+ some issues)

Hi all,

I have searching all over for a simple overview of how to implement a momentary button to cycle through presets and could not find any (may be due to lack of proper “google skillz”) So this is an attempt to list what I did to make it work and also … some issues I noticed of which I hope Aircookie could address them

Disclaimer : I am terrible at coding, even the whole JSON library is abracadabra for me (heck, even CSS is a mystery to me) which is why I used the HTTP API. Anyways, this is what I did:

The goal of the setup was to enable a “real” interface enabling basic functions without the need for software UI or even wifi reception. This is going to be implemented in a lamp for my daughter that will double as a wake up light. She can choose and define the various effects. After that the buttons will be the main interfacing to WLED.
This might also make it possible to (temporarily) disable WIFI on the esp8266 as to improve LAN security.

Hardware setup :

  • esp8266, WEMOS D1 mini clone
  • Button 1 connection : GPIO 0 (pin D3) + GND
  • Button 2 connection : GPIO 1 (pin RX) + GND

Software: WLED v0.13.0 beta 3

Config => LED preferences

  • button 0 pin : 0, pushbutton
  • button 1 pin : 1, pushbutton

Config : Time & macros

  • button 0 short : (preset) 20
  • button 0 long : (preset) 21
  • button 1 short : (preset) 30
  • button 1 long : (preset) 31
  • button 1 double : (preset) 32

Main UI => presets

  • preset 1 to preset 5 have all a certain effect
  • no emtpy presets between 1 and 5
  • preset 6 does not exist, is not used or set
  • preset 7 => API command : &PL=1
  • preset 8-19 do not exist, are not used or set
  • preset 20 => &PL=~ (this is the API command to jump to next preset)
  • preset 21 => &T=2 (API command to turn esp8266 on/off)
  • preset 30 => &A=~5 (increase brightness by steps of 5)
  • preset 31 => &A=2 (reset to very low brightness)
  • preset 32 => &A=125 (jump straight to half of full brightness, since I hardly ever use 100%)

What does this do?
Button 0:

  • When turned off, short pressing the button turns it on and jumps straight to preferred preset (in my case 1)
  • Again short pressing the button makes it jump to the next preset
  • When at preset 5, again short pressing the button makes it jump to preset 1
  • long press will turn the setup off
  • either long or short press will turn it back on again

Button 1

  • short press : increases brightness with small increments
  • long press resets to lowest level
  • double click jumps to 50% brightness

What I do not understand / Issues I have found in my setup

  • I need to leave a preset empty (in the example preset 6) before the &PL=1 command otherwise the last effect preset is skipped entirely before jumping back to the first one.
  • Also, adding new presets after defining the “&PL=1” does not show the new presets, they are simply ignored. Until you re-apply that specific API command (even if you reuse the same preset number)
  • this does not show when simple changing already defined presets
  • you could set the double press to go the previous preset (API would be : &PL=~- ), but this does not seem to work all the time in v0.13.0. I haven’t tried it with v0.12.1

Both these issues do not show when using 0.12.1

  • I do not have skip a preset before using &PL=1
  • New presets or changed presets are not ignored

P.S. I absolutely love the addition of another button in v0.13.0. I really hope this is going to be expanded to more buttons in the future

3 Likes

Hi!

I would recommend that you change preset 20 to PL=~&P1=1&P2=5. This sets the range of the cycle to 1-5. In your case it is not strictly required, since 1-5 is the default, but if you wanted to cycle through more (or less) presets, it would be required.

I’m not sure that I understand the second problem you are experiencing. Do you mean that, if you apply PL=1 once, then change e.g. the effect of preset 1, and then apply PL=1 again, it doesn’t update to the new effect?

Sounds like even more buttons would be of use for your application :slight_smile:
2 is only the default (4 on ESP32), it is possible to raise it up to 10 buttons by custom compiling setting WLED_MAX_BUTTONS in const.h. The only reason 2 is the default is saving memory.

3 Likes

Awesome. I’ll definitely try that.
And about changing the button default, I’ll ask my brother to look at the code. It should be right up his alley

So I tried your suggestion and (of course) it works.
But how does this line work exactly? I can’t figure that one out.
I kinow that when I change the “5” to “8” it continues until preset 8, but what is the logic behind the PL=~&P1=1&P2= …??

P1 is the lower limit and P2 is the upper limit.

https://kno.wled.ge/interfaces/http-api/

It is getting more clear to me. I didn’t get the “first cycle preset” description and that you can add more instructions. Thanks.

However, I am probably asking more of these n00b-like question :slight_smile:

Hello, could you pass me the diagram of how you have the button connected to the wemos d1 mini? I do it according to your descriptions and it doesn’t work for me. Many thanks in advance.

https://kno.wled.ge/features/macros/

You have almost the same setup that I have in my bedroom :slight_smile:

But I have a problem with button 1.

If I program the long press of button 1 to the preset &T=2. Then the Light goes on and off and on an off while holding the button. Actually as long as I hold the button. If I do the same command with button 0 it is not happening.
(I can see this on-off-loop behavior only, if I disable the crossfade. If the fading is on, it is just flickering like hell.)
Also I tried to swap the pins for button 0 and button 1, to be sure, that it is not a hardware issue. But it always happens for the hardware-button that is connected to the pin related to button 1.

I have no idea, what to do about it. Can anybody see the same thing?

Another thin to add. If I for example program a fix preset to button 1 (e.g. like just blue LEDs), it works. So it stays at blue. But of cause that is not the same thing, as the command &T=2 is a Toggle-command.

Button 0 has some special handling and if you press it for more than 6s it will open AP, more than 12s it will factory reset.
Button 1 will ramp brightness by default.

@blazoncek Is this 6/12s thing only active if long button press isn’t configured otherwise?

Or should I better switch to Button > 0 to avoid accidental factory reset or unwanted AP :astonished:

No. Always!

Okay, good to know I didn’t recognized this, thanks :+1: