NeoPixel Multi LED Controller

Hi guys!

I try to build a LED Strip Controller for WS2812B stripes.

The difficlulty is, it should control 2 different stripes simultaneously.

In my case both stripes are foldet and half parallel.
(1st 2x46 LEDs, 2nd 2x6 LEDs)

Furthermore there should be 2 buttons, one for each strip to:

change colour:

  • red, green, blue, purple, etc... (+black/off)
  • colour fade over black
  • colour fade from one colour to the other
  • rainbow -> fading from colour to colour and from one side to the other)

change motion:

  • filled colour
  • a small amount of LEDs runing from one side to the other around
  • a small amount of LEDs running parallel from one side to the other
  • strobe
  • police light (without colour mode)

Every colour should be combinable with every motion mode.

So for each stripe:
On a short press, change colour.
On a long press, change motion.

Thats the theory :smiley:

Till now I finished two basic programs, but both are complete crap...

In the first the functions slowed down the controller taht much, that a button press wasnt recognized properly.

Even the second one which worked better is slow when I start the rainbow mode.
Besides I finally recognized that the program is that slow, that both stripes together didnt run smooth.
You could see the jump into the output function from one stripe to the other.

MY QUESTION :smiley: :

Is it possible to realize that with an ATmega328p anyway or should I use two nanos, one for each stripe with 2 buttons each and work with interrupts?

Annexed is my last attempt.
I apprehend that I have to begin from scratch... :-/

LED_Controller_1.1.ino (8.86 KB)

LED_Controller_1.1.ino (8.86 KB)

Let's see your code. I am prepared to bet that you use the delay() function for timing and for loops to cycle through the sequences. If so then You need to look into using millis() for timing as in the BlinkWithoutDelay example and Several things at the same time

Save the time an event happens then each time through loop() check whether the required period has elapsed since the event. If not then go round loop() again reading inputs etc. If the period has elapsed then take the required action.

Use a state machine and switch/case to control which section(s) of code are active at any one time.

Here a Video from my old controller.

https://www.facebook.com/647658778675966/videos/759389794169530/

The equalizer mode over an microphone would also be cool but not that complicated I think.

I have modified the NeoPixel example and removed the delays!

My second attempt also was without for-loops.

I have attached the ino file of the project.

dont know how to post the code.

If I try to mark it as code it says its too long...

Click Reply, and then click "Attachments and other options" under the message box area.

I thought I could post it as text.
I allready attached the *.ino file.
Here's the cod as text document.

LED_Controler_1.1.txt (8.85 KB)

Thanks for your help!
@UKHeliBob:
I looked into the Several things at the same time. In basic its an example for timing with millis() I would said.

Actually I have no timing in my sketch, cause I dont need to synchronize anything atm.

I guess my problem is, that the NeoPixel need to be lighted one by one what's normally done in a for loop.

If you look on the serial monitor in my sketch you will see, that the button state is requested very slow, even without any delay.

Furthermore I think its better to integrate the color flow into the colorPick switch insted to implement it in every mode funktion.

Maybe it would be better and quicker if I work with four buttons and interrupts...

Actually I have no timing in my sketch,

What are you using mills() and delay() for if it is not for timing actions ?

I guess my problem is, that the NeoPixel need to be lighted one by one what's normally done in a for loop.

But it doesn't have to be done in a for loop because the loop() function does what it says and loops.

Save the millis() value at the time that the start action, such as setting the value of an RGB LED happens. Then, each time through loop(), check whether the required wait period has elapsed by subtracting the start time from the millis() value now. If the period has elapsed then act accordingly, perhaps by updating the LED display and save the start time for the next activity. If not, then go round loop() again, perhaps taking other actions and/or reading inputs, but don't block the free running of loop().

UKHeliBob:
What are you using mills() and delay() for if it is not for timing actions ?

I actually dont use any millis() nor delay() in my sketch.

I actually dont use any millis() nor delay() in my sketch.

//RAINBOW COLOR
void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip_1.numPixels(); i++) {
      strip_1.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip_1.show();
    delay(wait);
  }
}

I spy delay() in your code.

Sorry, I dint commented that out, but that function isnt called.
It was part of the example and i used it for testing at the beginning :roll_eyes:

Sp4rtan:
Sorry, I dint commented that out, but that function isnt called.
It was part of the example and i used it for testing at the beginning :roll_eyes:

So post the actual code... the one that isn't working but includes commented out functions...

The problem with the neopixel libraries is that rascally blocking code... lots of folks get tripped up in it!