Go Down

Topic: How to divde an LED Strip into groups to display effects? (Read 720 times) previous topic - next topic

trallfazzz

Hi,
I'm new to this forum so please excuse any mistakes I possibly made. :)

I have an LED Strip (WS2812B) attached to an Arduino Nano and my plan is to divide the LED's into groups.
I want every group to show different lighting effects, so for example one group should include a rainbow effect and one group should constantly flicker and so on.

I'm currently struggling with these groups, I have defined 5 arrays of LED's but I don't know how to display effects to the groups.

For example I came up with a first idea of a code for the rainbow effect and now I want to show this effect on LED 1, 2, 3, 4, 5, 20, 21, 22 and 23.

Code: [Select]

#include "FastLED.h"

#define PIN 6
#define NUM_LEDS 40
#define BRIGHTNESS 50

CRGBArray<NUM_LEDS> leds;
uint8_t hue[NUM_LEDS];

void setup()
{
  FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  for (int i = 0; i < NUM_LEDS; i++)
  {
    hue[i] = 255 / NUM_LEDS * i;
  }

}

void loop()
{
  for (int i = 0; i < NUM_LEDS; i++)
  {
    leds[i] = CHSV(hue[i]++, 255, 255);
  }
  FastLED.show();
  delay(30);

}




Can anybody explain to my, how these groups work and how I could display effects to one special Array of LED's?

I'd really appreciate your help!! :)

PaulRB

Please read the forum guide, then modify your post above and add the code tags. As you can see, the forum has corrupted your code because you didn't use code tags.

Grumpy_Mike

Don't do this
Code: [Select]
for (int i = 0; i < NUM_LEDS; i++)
For just using LEDs 0 to 4 ( the first five ) use
Code: [Select]
for (int i = 0; i < 5; i++)
Then do
Code: [Select]
for (int i = 20; i < 24; i++)
And so on to build up the colours you want to show on the LEDs.

PaulRB

@trallfazzz thanks for putting in the code tags. +1 Karma. You got it almost right. The tag at the end should be [ / code ] but without the spaces I put in there. That's why your final question appears inside the code box.

trallfazzz

Don't do this
Code: [Select]
for (int i = 0; i < NUM_LEDS; i++)
For just using LEDs 0 to 4 ( the first five ) use
Code: [Select]
for (int i = 0; i < 5; i++)
Then do
Code: [Select]
for (int i = 20; i < 24; i++)
And so on to build up the colours you want to show on the LEDs.
@Grumpy_Mike big shoutout to you for this idea, it was a good starting point.

But the problem is that the effect is supposed to appear on special pixelgroups with gaps between each other.
So like I wrote in my first post, for example pixel 1,2,3,4,30,31,32 should show the same effect as a group. If they would have been in one row (from pixel 1 to 10 for example) this would have worked but I need them to be paired together with an effect that cycles threw all of the pixels of one group.
Any ideas?

boolrules

@Grumpy_Mike big shoutout to you for this idea, it was a good starting point.

But the problem is that the effect is supposed to appear on special pixelgroups with gaps between each other.
So like I wrote in my first post, for example pixel 1,2,3,4,30,31,32 should show the same effect as a group. If they would have been in one row (from pixel 1 to 10 for example) this would have worked but I need them to be paired together with an effect that cycles threw all of the pixels of one group.
Any ideas?
That is the idea.  You just need to apply it.  What problem do you think remains?

trallfazzz

@boolrules Sorry, I don't know what you mean by that answer.


I tried now to divide the LED's into some groups:

Code: [Select]

#include "FastLED.h"

#define PIN         6
#define NUM_LEDS    40
#define BRIGHTNESS  50
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
#define NUM_SEGMENTS  5
#define NUM_ROWS      8


CRGBArray<NUM_LEDS> leds;

uint8_t hue[NUM_ROWS];




const uint8_t aRowMap[NUM_SEGMENTS][NUM_ROWS] = { { 0,  1,  2,  3,  36, 37, 38, 39 },
                                                  { 4,  5,  6,  7,   8, 33, 34, 35 },
                                                  { 9, 10, 11, 12,  29, 30, 31, 32 },
                                                  {13, 14, 23, 24,  25, 26, 27, 28 },
                                                  {15, 16, 17, 18,  19, 20, 21, 22 }
                                                };
void setup()
{
  Serial.begin(115200);
 
  FastLED.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalSMD5050);
  FastLED.setBrightness(BRIGHTNESS);

  for (int i = 0; i < NUM_SEGMENTS; i++)
  {
    hue[i] = 255 / NUM_SEGMENTS * i;
  }
}

void loop()
{
  static uint8_t nCurrentRow =0;

  for (int i = 0; i < NUM_ROWS; i++)
  {
    leds[aRowMap[nCurrentRow][i]] = CHSV(hue[i]++, 255, 255);
  }
  FastLED.show();
  delay(50);

}




The current result is definitely not final, I just wanted to post it.
It divides the LED's into groups (at least this works), but I have no clue how to apply an effect to each individual group at the same time.

Maybe someone else has a better idea?



Grumpy_Mike

Quote
but I have no clue how to apply an effect to each individual group at the same time.
You apply it first to one section and then the other. Then when you call the show method all the LEDs are updated at the same time.

I am not sure what you are not understanding, please be more specific.

trallfazzz

I'm sorry, this was a bit unspecific.

So my plan is that every group of LED's can display a different effect and I wanted to start with a rainbow color cycle (5 arrays with 8 LED's each).

I have multiple arrays of LED's but I don't know how to display a simple rainbow effect to one of them, this is the problem. (Like I said I'm really new to this topic)

So maybe someone can show me an example of how I could apply a rainbow effect to an array of LED's.

I'd really appreciate your help and I'm already thankful for your answers!

Grumpy_Mike

The examples that come with the fast led library or the Adafruit Neopixel library show you how to make the effects. Use the IDE menu file -> Examples -> ( the library you want ) to load them in and look at them.

In the case of a rainbow you get the colours from stepping through the H values of the HSV colour space. Each library has its own way of handling HSV colours. If you don't know what that means look up the Wikipedia page on HSV colours.

Do you want the effect spread across the regions or repeated on each region? That will affect how you write your code.

Quote
I have multiple arrays of LED's
If you are new to this just start with a single array. Which out the apostrophe police don't pick you up for that quote.

trallfazzz

My goal was to just have a few LED groups that show different effects, so I thougt an array for every group could be a good solution. I want an effect to show across one group of pre-defined LED's.

But my problem is still that I don't know how to assign the effect to the LED group.

Grumpy_Mike

#11
May 30, 2019, 06:37 pm Last Edit: May 30, 2019, 06:38 pm by Grumpy_Mike
Quote
But my problem is still that I don't know how to assign the effect to the LED group.
I told you that in reply #4.

If you don't understand what I said then ask specifically about what I said that you do not understand.

Alternately if you can't understand what I said try this other approach.
Basically you have to use virtual pixel numbers to define the effect and then convert them to physical pixel numbers to set the colour of them in the library.

You can do this with a look up table, which is an array who's position is the virtual pixel number and the value is the physical pixel number. Use it a bit like your aRowMap only you need a one dimensional map but one for each set you have.

So for the set you asked about in the original post, that is
Quote
I want to show this effect on LED 1, 2, 3, 4, 5, 20, 21, 22 and 23.
The the array would be:-
Code: [Select]
byte firstGroup[] = {1, 2, 3, 4, 5, 20, 21, 22, 23};
Would map the virtual pixel numbers 0 to 8 into the physical pixel numbers you have specified.
So to fill the first group with a yellow colour use:-

Code: [Select]
for (int i = 0; i < 9; i++)
  {
    leds[firstGroup[i]].setRGB(255,128,0);
  }
  FastLED.show();
  delay(50);


By the way did you mean the second LED which is LED 1 or did you mean the first LED which is LED 0


Go Up