Help with 12 Switches and 12 Addressable Ws2811 LEDs

I'm making a MIDI control pedalboard to control guitar pedals and I need help from someone who knows more about Arduino than I do, as I'm a beginner and am just starting to learn how to write the code.

The midi part is made with a Leonardo board and works fine, but I need help with the LEDs.

I'm thinking of using another Nano board for the LEDs, but I also have a Pro Micro and a Leonardo. If there were any advantages, I'd appreciate your opinions.

What I intend to do is the following: I have 12 momentary switches and 12 WS2811 addressable LEDs. I'd like to know how to make the code so that each switch turns on and off only one LED and in the color I want.

For example, switch 1 turns on LED 1 in red and keeps the LED on until you press it again to turn the LED off (on-off).
Switch 2 LED 2 green with the same function as the previous one
Switch 3 LED 3 purple with the same function as the previous one.
Switch 4 LED 4 orange with the same function as the previous one
And so on until number 12, but each LED with a different color chosen by me.
In conclusion, what I want is for each switch to turn on and off only one of the LEDs and in the color I want. The idea is that when I press switch 1 on the pedalboard, the LED in the desired color stays on so I can identify by the color which guitar effect is connected.
I searched all over the web and forums for an example of how to do what I need but I couldn't find anything similar, so I appreciate any help anyone can give me or point me in the right direction where I can find an example of similar code.

Welcome to the forum

  • Do you know how to read the state of an input pin ?
  • Do you know how to determine that the state of an input pin has changed ?
  • Do you know how to turn on a single LED in a string of WS2811 LEDs (note that this is a trick question) ?

As I said, I'm new to Arduino so I'm asking for help with a sample code on how to light up a single LED on a WS2811 strip because I have no idea how to do it.

I know how to read the pin status and how to determine if the status has changed, but I don't know how to turn on a single LED on a WS2811 strip.

If I see a code example, I learn quickly, so if you can show me a code example, I'd appreciate it.

What voltage does the WS2811 strip run at ?

5 Volts

Are these individual LEDs or in a strip ?

Please post a link to the LEDs that you have

They are individual LEDs, they are the 5V clear ones here is the link to the site where I bought them.Adressable leds

From the page that you linked to
image

Yes, but the ones I bought are not the ones in the photo, but the clear ones that they also sell and work at 5 Volts.

Post a picture.

These are the ones I bought.

We will have to take your word for it that they are 5v LEDs

Wire a single one up to your Arduino with the DIN pin connected to a pin of your choice and DOUT not connected..

Install the FastLED library and try the Blink example that comes with it. Make sure that the #definition of DATA_PIN matches the pin that you have chosen and ignore the CLOCK_PIN #definition

Use this constructor call

    FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed

Upload the sketch. What happens ?

I uploaded the blink example sketch and the LED is blinking green as expected.

Will you show the "WS2812 blink" example code here? Thank you.

Surely here is the code that makes the LED blink.

/// @file    Blink.ino
/// @brief   Blink the first LED of an LED strip
/// @example Blink.ino

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 1

// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 3
#define CLOCK_PIN 13

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
    // Uncomment/edit one of the following lines for your leds arrangement.
    // ## Clockless types ##
    FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
    // FastLED.addLeds<SM16703, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1829, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1812, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<UCS1904, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<UCS2903, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<WS2852, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<GS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<SK6812, DATA_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<APA106, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<PL9823, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<SK6822, DATA_PIN, RGB>(leds, NUM_LEDS);
     FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<WS2813, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<APA104, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<WS2811_400, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<GE8822, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<LPD1886, DATA_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<LPD1886_8BIT, DATA_PIN, RGB>(leds, NUM_LEDS);
    // ## Clocked (SPI) types ##
    // FastLED.addLeds<LPD6803, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // GRB ordering is typical
    // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<WS2803, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
    // FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
    // FastLED.addLeds<DOTSTAR, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
    // FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
    // FastLED.addLeds<SK9822, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);  // BGR ordering is typical
}

void loop() { 
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(1500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(1500);
}

OK. Now you know how to turn a single LED on and off

Connect DOUT from the first LED to DIN of a second one. Change the sketch to indicate that you have 2 LEDs and blink both of them. For extra points, make them blink different colours with them being on alternately

I tested the code you published and it works as I want, turning on the LEDs in the colors defined in the sketch, but the LEDs only stay on while the button is pressed. What's missing is to make the buttons turn on the LED and keep it on until they are pressed again (toggle function).
What I want is to touch the switch and turn on the LED and keep it on until it is pressed again and then turn off the LED.
How can I modify the code to do this function on the switch?

The last code is perfect, exactly as I need it.
Thank you very much to everyone for your invaluable help.
Now to make it perfect I just need to find out how to make 4 of the switches work as selectors, turning on only one LED and turning off the other 3. This way my pedalboard would be perfect with 8 buttons to turn the effects on and off and the remaining 4 to change presets. This way I would know by looking at the LEDs which effects are on and which preset they are in. Thank you very much for all the help you are giving me, making it possible to complete my Midi pedalboard.

is this really what you want or you make new quest harder every time?

The last code you posted is exactly what I needed and for that I am very grateful and I hope this information can also help other people who, like me, are doing something similar.
Once again, thank you very much for all the help you gave me with this project.