Turn Signals - Multiple switch inputs solved!

You will need to write a usermod from scratch.
Check existing usermods to get the idea how.

Maybe I’m wrong (probably am), but to me, it seems like a multi-segment, multi-API type of thing. Segment 1 = Left turn
Segment 2 = Right turn
Preset 1 = Left Turn only (Segment 1 ON, Segment 2 OFF)
Preset 2 = Right Turn only (Segment 1 OFF, Segment 2 ON)
Preset 3 = Brake (both Segment 1 & 2 ON - left and right turn)
Preset 4 = Brake + Left Turn (Segment 1/Left Turn toggling, Segment 2/Right Turn solid)
Preset 5 = Brake + Right Turn Segment 1/Left Turn solid, Segment 2/Right Turn toggling)

Then for each situation, call the correct preset. With 3 switch inputs, you can - theoretically - call up to 8 presets, correct (left and right turn + brake switch inputs).

Is the main problem that WLED does not support 3 switch input configurations or that there are currently only 2 switch inputs and a 3rd is really needed, or something else?

The problem with this approach is that button logic has to be upgraded to support combination of button presses. Not anything like this in on WLED roadmap.

As said above a usermod with button override behaviour would be in order as this is possible since 0.13.3.
When usermod with such behaviour is created probably your suggestion of presets would be in order (depends on how usermod would handle preset calling).

1 Like

Can anyone help me to implement this.

I can compile WLED and I pasted the code provided into usermod.cpp, but the variables like PIN_BRAKE are not defined anywhere. Do I need to link them to the buttons being used?

Also does anything need modified in buttons.cpp or will this usermod just overide? TYIA!

I can’t get this to work. When you send a API command to change the state of a segment, if the other segments data is not present that section turns off.

How can you have each preset control a segment independently and not change the other segments?

Are you writing a usermod or something else?
With usermod you do not deal with API commands but rather manipulate segment states independently.

If you are trying to do it via JSON API, create each API call manually using only one segment in it.

I could not get this to work on 13.3, but a fresh compile of the current master branch has it working.

Well I am doing both.
But yesterday I was seeing if I could get your suggestion to work of having a preset independently control a segment and I could not get it to work as described using 0.13.3. When the API only contains one segment ID the other segments turn off. I want them to not be affected. Below Numanair suggested it might behave differently in the current build.

I rewrote (internal) segment handling from scratch for 0.14.

2 Likes

Hi, I’m looking for the user’s usermod but I can’t find it anywhere… does anyone know anything? Thanks greetings!!

Hi thanks! It is supposed that the user Aa7bq solved it with that code that he puts… but I don’t know how to make the modification…

What is the name of this usermod? I would LOVE to see this and get it on my ESP32. I saw a YouTube video from Dave’s Garage on Sequential Lights and it has me really wanting to do the same, but I can not for the life of me figure out how to code it. If there was a usermod I could use a template, it would help a lot!

1 Like

There is an example in the code along with all of the other usermods to look at.

@srg74 asked me to write a usermod and I may get to that at some point. :slight_smile:
Until then here is the presets.json file with a few presets that will enable blinkers (turn lights), brake and hazard lights from OP to work seamlessly together.

{"0":{},"1":{"transition":0,"seg":[{"id":0,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"col":[[255,160,0],[0,0,0],[0,0,0]],"fx":1,"sx":204,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"Left On"},"2":{"transition":0,"seg":[{"id":1,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"col":[[255,160,0],[0,0,0],[0,0,0]],"fx":1,"sx":204,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"Right On"},"3":{"transition":0,"seg":[{"id":2,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"col":[[255,0,0],[0,0,0],[0,0,0]],"fx":0,"sx":204,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"Brake On"},"4":{"transition":0,"seg":[{"id":3,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"col":[[0,0,255],[255,0,0],[0,0,0]],"fx":50,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"Hazard On"},"5":{"transition":0,"seg":[{"id":0,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"col":[[0,0,0],[0,0,0],[0,0,0]],"fx":0,"sx":204,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"Left Off"},"6":{"transition":0,"seg":[{"id":1,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"col":[[0,0,0],[0,0,0],[0,0,0]],"fx":0,"sx":204,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"Right Off"},"7":{"transition":0,"seg":[{"id":2,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"col":[[0,0,0],[0,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"Brake Off"},"8":{"transition":0,"seg":[{"id":3,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"col":[[0,0,0],[0,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"Hazard Off"},"99":{"on":true,"bri":128,"transition":0,"mainseg":0,"seg":[{"id":0,"start":0,"stop":5,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"n":"Left","col":[[0,0,0],[0,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0},{"id":1,"start":5,"stop":10,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"n":"Right","col":[[0,0,0],[0,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0},{"id":2,"start":10,"stop":20,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"n":"Brake","col":[[0,0,0],[0,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0},{"id":3,"start":20,"stop":30,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"group":0,"n":"Hazard","col":[[0,0,0],[255,0,0],[0,0,0]],"fx":0,"sx":128,"ix":128,"pal":0,"c1":128,"c2":128,"c3":16,"sel":true,"rev":false,"mi":false,"o1":false,"o2":false,"o3":false,"si":0,"m12":0}],"n":"All Off"}}

Set-up instructions:

  1. assign preset “All Off” [99] as a boot preset (you may need to modify segment LED counts for all segments in this preset)
  2. set up 4 “buttons” as switches in LED settings (be careful to use compatible GPIO as incompatible may prevent booting of ESP if switched on)
  3. assign “XXX On” preset (e.g. “Left On” [1]) for switch Off->On transition and “XXX Off” (e.g. “Left Off” [5]) for switch On->Off transition.
  4. repeat for all switches/buttons

After set-up and testing you may modify effects used but you will need to edit API command in the preset directly and not use “Save state”. In such case you should modify "fx", "ix", "sx" properties of JSON API and leave everything else untouched (unless you know what you’re doing).
For preset “All Off” [99] you should only modify "start" and "stop" properties in each segment.

2 Likes

Thank you @blazoncek for your time and help. I have to say it works but need to compile 5 buttons version of firmware. Reason is special behavior of button0. Start assigning buttons actions from button1 instead. Button 0 must be default ON/OFF for WLED.
Modifications comment by @blazoncek is very important as I already have mess up with presets :joy:

2 Likes

Good point about button 0 but that, luckily, only applies if it is indeed a “button” and not a “switch”.
If button 0 is assigned as a “switch” its default behaviour does not work any more so you do not need special build with 5 buttons.

Unfortunately most of the controllers use flashing/programming button (usually GPIO0) as a primary input button (0) and, as mentioned above, that button (GPIO0) is not compatible with “switch” function. Still if the controller offers additional GPIO headers/exposed pins use those. In such case re-assign button 0 to some other GPIO.

You will loose On/Off button in such case but that is not needed in application as OP requested. In such case WLED must remain in On state at all times.

1 Like

Hello, just wondering if you’ve released a tutorial on how to implement this on the wled usermod. Im still new to wled. Or is there a way to copy your codes and put it on my wled?

Thank you!

No usermod needed for solution from above.

Hello, would you mind explaining how i can make this work then? I’ve set everything up already, just trying to figure this out so i can actually use it on my tail lights.
Thank you so much!

What else is there to explain?
Upload provided presets.json (use copy/paste into notepad and save) using backup/restore in Security settings and follow above instructions.