Turn Signals - Multiple switch inputs solved!

Oh you’te referring to the presets.json shown above. I see that being a good idea, however, that doesnt solve the multi switch input problem, right?

Why not?

I installed everything as per your instructions. They all work on its own. However, when i pressed 2 buttons at the same time, e.g. when I’m braking while the turn signal is on, it cancels the first button pushed, then starts the preset for the 2nd button pushed. Unless I’m not understanding this right, i will have to pick between turning left, or pressing my brakes. Am i wrong?

Every combination of switch inputs results in a unique value. Each of those values needs a preset assigned to it. If there are 4 buttons, there would be 16 different combinations/presets to configure.

Not necessarily if those presets don’t interfere with others.
That’s why custom API in each of them.

Using this usermod to build a custom switch button combination for Hazard mode i make it for myself long time ago using esp32

#include “wled.h”

// Pin definitions for the switches
#define BUTTON_PIN_1 14 // GPIO14 (D14)
#define BUTTON_PIN_2 27 // GPIO27 (D27)
#define BUTTON_PIN_3 12 // GPIO12 (D12)

// Button states
bool buttonState1 = HIGH;
bool buttonState2 = HIGH;
bool buttonState3 = HIGH;
bool buttonPressed1 = false;
bool buttonPressed2 = false;
bool buttonPressed3 = false;

// Preset and segment variables
int currentPreset = 0; // Tracks the current preset
int currentSegment = 0; // Tracks the current segment

// Delay timer variables
unsigned long buttonReleasedTime = 0;
const unsigned long presetDelay = 2000; // Delay time in milliseconds

void handleButtonPress()
{
if (buttonPressed3)
{
// Switch 3 triggered
strip.setPreset(3, true); // Transition to preset 3
currentPreset = 3; // Update current preset
currentSegment = 0; // Reset current segment

// Cancel the effects of switch 1 and switch 2
buttonPressed1 = false;
buttonPressed2 = false;

}
else if (buttonPressed1 && !buttonPressed2)
{
// Switch 1 triggered
if (currentSegment == 0)
{
strip.setPreset(2, true); // Transition segment 1 to preset 2
currentSegment = 1; // Update current segment
}
}
else if (!buttonPressed1 && buttonPressed2)
{
// Switch 2 triggered
if (currentSegment == 1)
{
strip.setPreset(2, true); // Transition segment 2 to preset 2
currentSegment = 0; // Update current segment
}
}

// Check if switch 1 and switch 2 are triggered simultaneously
if (buttonPressed1 && buttonPressed2)
{
strip.setPreset(3, true); // Transition to preset 3
currentPreset = 3; // Update current preset
currentSegment = 0; // Reset current segment
}

// Update the JSON state
if (WLED_CONNECTED)
{
JsonObject state = server[“state”];
state[“ps”] = currentPreset;
state[“seg”] = currentSegment;
}
}

void handleButtonStateChange()
{
// Detect button 1 state change
bool newButtonState1 = digitalRead(BUTTON_PIN_1);
if (newButtonState1 != buttonState1)
{
buttonState1 = newButtonState1;
if (buttonState1 == LOW)
{
buttonPressed1 = true;
buttonReleasedTime = 0; // Reset the button release time
}
else
{
buttonPressed1 = false;
buttonReleasedTime = millis(); // Set the button release time
}
handleButtonPress();
}

// Detect button 2 state change
bool newButtonState2 = digitalRead(BUTTON_PIN_2);
if (newButtonState2 != buttonState2)
{
buttonState2 = newButtonState2;
if (buttonState2 == LOW)
{
buttonPressed2 = true;
buttonReleasedTime = 0; // Reset the button release time
}
else
{
buttonPressed2 = false;
buttonReleasedTime = millis(); // Set the button release time
}
handleButtonPress();
}

// Detect button 3 state change
bool newButtonState3 = digitalRead(BUTTON_PIN_3);
if (newButtonState3 != buttonState3)
{
buttonState3 = newButtonState3;
if (buttonState3 == LOW)
{
buttonPressed3 = true;
buttonReleasedTime = 0; // Reset the button release time
}
else
{
buttonPressed3 = false;
buttonReleasedTime = millis(); // Set the button release time

  // Reset to the first preset when switch 3 is released
  if (currentPreset != 1)
  {
    strip.setPreset(1, true); // Transition to the first preset
    currentPreset = 1; // Update current preset
    currentSegment = 0; // Reset current segment
  }
}
handleButtonPress();

}
}

void buttonSetup()
{
pinMode(BUTTON_PIN_1, INPUT_PULLUP);
pinMode(BUTTON_PIN_2, INPUT_PULLUP);
pinMode(BUTTON_PIN_3, INPUT_PULLUP);
}

void usermodSetup()
{
buttonSetup();
}

void usermodLoop()
{
handleButtonStateChange();

// If no button is pressed, revert to the first preset
if (!buttonPressed1 && !buttonPressed2 && !buttonPressed3 && currentPreset != 1)
{
// Check if the delay time has elapsed since the last button release
if (buttonReleasedTime != 0 && (millis() - buttonReleasedTime) >= presetDelay)
{
strip.setPreset(1, true); // Transition to the first preset
currentPreset = 1; // Update current preset
currentSegment = 0; // Reset current segment
}
}
else
{
// Reset the delay timer when a button is pressed
buttonReleasedTime = 0;
}
}

Hi johnycokeche07 This looks like something ive been after. How are the inputs sorted. Left and Right for input 1 and 2? and what is the 3rd input, DRL or park light? Very curious. Cheers

Fairly new to wled and very new to the forum. Right now a lot of this is completely over my head, but I have a similar simple goal.

I have and electric skateboard that currently has brakelights. They work as running lights and have a brake light function when the brake is applied on the remote.

I could set a strip default to red so the running lights would turn on when the board is turned on. Then I would just have to splice into the break wire and have that trigger a preset some how? Flashing etc. Then when off the brake, just go back to running lights.

Since this is a simpler task could this be achieved with just “button pushes” triggered but the existing brake lights?

Sure. Only need a couple of presets.

hi , im tryng to implement your solution but when i edit the API to modify the LED count for the segments it appears to be very glitchy/unstable. for instance i will edit the length for “Brake On” get it to work than edit the length for “Hazard On” but as soon as i save it will break “Brake On” it will no longer turn on. i have tried doing it in wled 14.1,14.0, 13.3 and have tried editng LED length 1 at a time also all at once. im using a esp32, with 2 LED strips on different gpio pins. i dont know whats wrong

Make sure when you make segment changes, you only check the segments you want to modify.
Then when you save the changes to a preset, click “overwrite State” and “Checked Segments only”.
That will make sure your changes don’t overwrite anything else that’s active.

i tried modifying the segment LED start/stop for “brake on” under the API of preset [99] while only haivng the “Brake On” segment checked, and it worked, but as soon as i work on another modying another segment length , the previous one become unfunctional. Does the API of preset [99] have any special command lines or can i just do these presets/segments from scratch?

edit; still doesnt appear to work , this is my steps i use: i load the Preset.json>reboot>assign preset 99 as boot>reboot>then i check all segments and edit segment 99 API to edit the LED start/stop>reboot . now i go test out each preset labeled “On” but only Hazards works . Left: 8 LEDs, Right: 13 LEDs, tottal LEDs 21

has anybody gottten this to work? as soon as i upload the json file, none of the pre-configured presets work properly

Did you end up getting it to work?