# Can a usermod make use of WLED buttons?

**URL:** <https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708>\
**Category:** Usermods\
**Created:** [December 11, 2022, 8:05am UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708 "2022-12-11T08:05:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![allenhuffman](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/allenhuffman/32/4034_2.png) [@allenhuffman](https://wled.discourse.group/u/allenhuffman)\
**Post date:** [December 11, 2022, 8:05am UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/1 "2022-12-11T08:05:58Z")

</div>

For a usermod I worked on today, I created input routines based on code from button.cpp (just enough to handle debounce, short press and long press).

I saw how handleButton() can be used in the usermod to just return true and disable (I assume) the WLED button handling.

Can it go the other way? Is there a way for a usermod to get the benefits of seeing if Button 1 was double pressed, or Button 2 was released? It looks like there might be some way to hook in to that, but my web/forum/discord/REDDIT searching skills didn’t lead me to an answer.

The idea would be to avoid replicating so much code since buttons.cpp already does everything I needed, plus much more.

Cheers…

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [December 12, 2022, 7:55am UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/2 "2022-12-12T07:55:38Z")

</div>

What do you want to achieve?

---

<div class="post-metadata">

**Author:** ![allenhuffman](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/allenhuffman/32/4034_2.png) [@allenhuffman](https://wled.discourse.group/u/allenhuffman)\
**Post date:** [December 12, 2022, 3:04pm UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/3 "2022-12-12T15:04:31Z")

</div>

I want to have a Preset that uses an effect (like “blink” or whatever) on Segment 0, and have it play only to that segement, but also want to have Segment 1 and 2 (for example) playing a Preset that makes them solid.

I think I need to dive in to the checkboxes and enable/disable stuff in the UI. (Or learn the json so I can edit them there.)

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [December 12, 2022, 10:18pm UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/4 "2022-12-12T22:18:45Z")

</div>

Using JSON API is the way to go.

---

<div class="post-metadata">

**Author:** ![allenhuffman](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/allenhuffman/32/4034_2.png) [@allenhuffman](https://wled.discourse.group/u/allenhuffman)\
**Post date:** [December 12, 2022, 10:20pm UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/5 "2022-12-12T22:20:57Z")

</div>

Can I call that from a usermod? This is for a standalone box that reads inputs, and kicks off patterns based on inputs. But it’s not a simple “if button X, run preset Y”. It has behaviors and modes and such.

The initial idea was to let the UI be used to build presets, then the usermod invokes them. Preset effects can be changed by folks who don’t know how to code.

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [December 12, 2022, 10:22pm UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/6 "2022-12-12T22:22:08Z")

</div>

If you are writing a usermod forego JSON and manipulate WLED state directly.

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [December 12, 2022, 10:23pm UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/7 "2022-12-12T22:23:46Z")

</div>

Actually it is. You just need to wrap your head around it.

---

<div class="post-metadata">

**Author:** ![allenhuffman](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/allenhuffman/32/4034_2.png) [@allenhuffman](https://wled.discourse.group/u/allenhuffman)\
**Post date:** [December 12, 2022, 10:24pm UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/8 "2022-12-12T22:24:22Z")

</div>

Ideally, the presets would be configured through the web UI, so they can be changed without recompiling code.

Is there a C/C++ (?) function call API list that would show me how to launch an effect on a segment? Being able to say “do blinking, this speed, this color, this brightness, on LEDS 0-128” would be a good start for me.

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [December 12, 2022, 10:29pm UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/9 "2022-12-12T22:29:43Z")

</div>

If you are content with up to 14 buttons, you do not need to write usermod. Use existing stuff built into WLED.  
You will need to compile yourself, though.

---

<div class="post-metadata">

**Author:** ![allenhuffman](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/allenhuffman/32/4034_2.png) [@allenhuffman](https://wled.discourse.group/u/allenhuffman)\
**Post date:** [December 12, 2022, 10:41pm UTC](https://wled.discourse.group/t/can-a-usermod-make-use-of-wled-buttons/6708/10 "2022-12-12T22:41:07Z")

</div>

I am compiling out of git currently. The need for usermod is the complex sates that know what pattern to launch. It’s not just light switch type modes – certain combinations of buttons go in to a config mode, versus normal run mode, etc.
