Several buttons active at the same time

Hello! Well I started again with wled and I’m still stuck…
Let’s see, I’ll tell you what I want to do and what’s wrong with me…

Everything revolves around this thread–> Turn Signals - Multiple switch inputs solved!

I don’t know if what I am going to indicate next is nonsense but hey, I will expose what I have done and it will surely be worse than bad…

I have modified the usermod_v2_empty as follows:

#pragma once

#include "wled.h"

//This is an empty v2 usermod template. Please see the file usermod_v2_example.h in the EXAMPLE_v2 usermod folder for documentation on the functions you can use!

class UsermodRenameMe : public Usermod {
  private:
    const int P_Conductor = 1;
    const int P_copiloto = 2;
    const int P_trasera_derecha = 3;
    const int P_trasera_izquierda = 4;
    int pin_state;
    int last_preset;

  public:
    void setup() {
      
    }

    void loop() {
      pin_state = digitalRead(P_Conductor);
      pin_state = pin_state << 1;
      pin_state |= digitalRead(P_copiloto);
      pin_state = pin_state << 1;
      pin_state |= digitalRead(P_trasera_derecha);
      pin_state = pin_state << 1;
      pin_state |= digitalRead(P_trasera_izquierda);
      pin_state++; // presets are 1-based

  if (pin_state != last_preset) {
    last_preset = pin_state;
    applyPreset(pin_state & 15);
  }
    }
};

Next I have added these lines to usermods_list.cpp:

....
...
....
..
* Add/uncomment your usermod filename here (and once more below)

* || || ||

* \/ \/ \/

*/

//#include "../usermods/EXAMPLE_v2/usermod_v2_example.h"
 #ifdef USERMOD_V2_COCHE
  #include "../usermods/coche/usermod_v2_coche.h"
#endif
.......
......
......

/*
   * Add your usermod class name here
   * || || ||
   * \/ \/ \/
   */
  //usermods.add(new MyExampleUsermod());
#ifdef USERMOD_V2_COCHE
  usermods.add(new usermod_v2_coche());
  #endif

and this other to wled00.ino

/*
 * WLED Arduino IDE compatibility file.
 * 
 * Where has everything gone?
 * 
 * In April 2020, the project's structure underwent a major change. 
 * Global variables are now found in file "wled.h"
 * Global function declarations are found in "fcn_declare.h"
 * 
 * Usermod compatibility: Existing wled06_usermod.ino mods should continue to work. Delete usermod.cpp.
 * New usermods should use usermod.cpp instead.
 */
#include "wled.h"
#include "usermod_v2_coche.h"
void setup() {
  WLED::instance().setup();
}

void loop() {
  WLED::instance().loop();
}


Everything is compiled, but it doesn’t mean that it works… I don’t know if this is right or not…

Would this be the way to add a user mod? (Leaving apart that the code at the beginning is wrong…) Would the file modifications be those? Would I have to see something in the usermod section on the wled website?

You will tell me… thanks a greeting!

The example and info is in the code at usermods\EXAMPLE_v2.

I have seen that I have not changed a thing “class UsermodRenameMe” but after modifying it, it still does not work. I looked at the instructions but… I have done something with arduiono but this is another level… I would appreciate it if someone could guide me through the process… thanks!

Hello, well, I’ve already made some progress… for translating incorrectly and assuming something I did wrong… I’ve already managed to get it to recognize user mode, but (there’s always a damn but…)it doesn’t work like It is due… In an arduino I have tested the main loop works correctly but in WLED it does not recognize the pins. I have tried to remove the port assignment to each button but I can’t get anything to work well.

It starts in a color configuration and then with the switches I can change between the four but it can no longer select more, if I reset it returns to the same configuration from the beginning, there are 15, it always selects the same one…

Any ideas? All the best!

Hello again… let’s see… I have been looking at the assigned pins (they are not the ones in the first message, those were for arduino) I have put 16, 17, 22 and 23 as I mentioned in the previous message, they do nothing If we assume that they take the decimal number from the generated binary, but they do what is configured in WLED, there are 4 colors, those do activate them but there is no way. Today I decided to try connecting the input pins to 3.3 and to gnd to see if any configuration other than 1,2,3 or 4 was activated, nothing has happened with any except with the GPIO4 that I have had a reaction by putting it to 3.3v (short press) it has changed to configuration 11! and by holding the 3.3v (long press) it has changed to setting 12! that could be happening?

Let’s see if someone tells me something because I don’t understand it…
If I put this in a user mode:

#pragma once

#include "wled.h"


class Usermod_v2 : public Usermod {
  private:
   

  public:
    void setup() {
    }

    void loop() {

  applyPreset(17);
    }
};

Configuration 17 is supposed to be active all the time, right?

Hey. I am really interested in make this work too. You make any progress? I dont see so many support here. I dont understand why so many people here has the knowledge to make this work and they wont offer a good help.

Hello, thanks to the help of a forum member I got it to work, then when I have time I’ll tell you…

Edit…

#include "wled.h"
/*
 * This v1 usermod file allows you to add own functionality to WLED more easily
 * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality
 * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in const.h)
 * If you just need 8 bytes, use 2551-2559 (you do not need to increase EEPSIZE)
 *
 * Consider the v2 usermod API if you need a more advanced feature set!
 */

//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t)

//gets called once at boot. Do all initialization that doesn't depend on network here
    const int AAAAAA = 16; pin switch
    const int BBBBBB = 17; pin switch
    const int CCCCCC = 22; pin switch
    const int DDDDDD = 23; pin switch
    
    int pin_state;
    int last_preset;
void userSetup()
{
     pinMode(AAAAAA , INPUT_PULLDOWN);
     pinMode(BBBBBB , INPUT_PULLDOWN);
     pinMode(CCCCCC , INPUT_PULLDOWN);
     pinMode(DDDDDD , INPUT_PULLDOWN);
    
}

//gets called every time WiFi is (re-)connected. Initialize own network interfaces here
void userConnected()
{

}

//loop. You can use "if (WLED_CONNECTED)" to check for successful connection
void userLoop()
{
  pin_state = digitalRead(AAAAAA);
  pin_state = pin_state << 1;
  pin_state |= digitalRead(BBBBBB);
  pin_state = pin_state << 1;
  pin_state |= digitalRead(CCCCCC);
  pin_state = pin_state << 1;
  pin_state |= digitalRead(DDDDDD);
  pin_state++; // presets are 1-based

  if (pin_state != last_preset) {
    last_preset = pin_state++;
    applyPreset(pin_state & 15);
  }
}

This would be the program created on the user Aa7bq. What you have to do is copy and paste it into the usermod.cpp file. The user Walfy07 told me that he added it to the usermod.cpp and that it worked but some things didn’t work well for him.

Logically the AAAA, BBBB, CCCC, DDDD you have to declare the name you want to put…

2 Likes

Hi there. Ive been trying the code you posted, however, i cant seem to get it to work. it keeps giving me errors in areas like the pin switch, or the input_pulldown. is there something im doing wrong? ive basically just copied and paste your code to usermod.cpp and saved it under a name i created.

hello, have u figure it out already? i am trying to do this usermod aswell im not experiecned and i dont like how every person that actuallly know how to deal with usermods response is “look at the examples”