Controlling WS2811 Pixel LEDs

I'm looking to start a project; most of my stuff will arrive this week and I wanted to start researching on how to program my arduino uno to control these LEDs.

There are a lot of good tutorials out there; but none seem to fit what I was hoping to accomplish.

I will have a string of 150 lights arranged into a lightbulb pattern. I would like to set them up into arrays or groups (whichever works) so that I can control/change just the outline or whatever. The way I see it in my head and how i've sketched it out on paper is that bulbs 1 to 20 will be the base, 21 to 65 will be the outline, and the remainder will be the face on the inside.

I think I could pretty easily write a program that would light 1 to 20 as white, 21 to 65 as red, and the remainder as white. But what I would like the program to do is cycle through some effects on the 21 to 65 bulbs while leaving the others alone.

I've seen plenty of this done using controllers and software like Vixen or whatever - but I don't see why i can't do this right from the arduino. Especially since I'm just lighting the lights - I don't want to sync it to music (at least not yet... that may be a while down the road).

Does anyone know if there are good tutorials/examples I could read through to do this?
Is it even possible?

If it'll help, I've got a few drawings - but they are on my work computer; I can get that uploaded Monday if required.....


but I don't see why i can't do this right from the arduino.

No reason why you can't.

Does anyone know if there are good tutorials/examples I could read through to do this?

I suspect that their are not going to be any that do exactly what you want but it is easy enough.

But what I would like the program to do is cycle through some effects on the 21 to 65 bulbs while leaving the others alone.

So that is what you write. Look at the example demo codes with the libiary, they start with LED 0 and go to the end. All you have to do is to start at LED 21. So where it would say

for(int i = 0; i<65; i++) {.......
you write
for(int i = 21; i<65; i++) {.......

Remember the first LED is numbered 0 and the second 1 and so on.


I think I was on the same page as you with the for loop... I guess what I am hung up on; is wouldn't that affect the first 20 pixels? I guess I need to get em all hooked up to the arduino and start trying some code.

Really wanted to hang these lights this week - probably not going to happen with any code that'll animate any part of them yet.... This is what I get for trying to put some holiday lights on the house last minute. HA!

The FastLED library might be of interest.

.. I guess what I am hung up on; is wouldn't that affect the first 20 pixels?

What happens is all the code that you write changing colours just operates on a memory buffer. Then when you call the show method the memory buffer is transferred to the LEDs. If you don’t change the memory for those first 20 LEDs then they get sent the same colour as last time, so you don’t see a change.

That helps a lot. I'm looking forward to trying some code tonight as part of my order arrived today.

I've been looking at how best to write my code to call out a group of LEDs vs calling them individually. If I am understanding what I've been reading today - I'm going to need a multidimensional array. Here is what I've come up with to help organize my array.

Bulb		Qty		1		2		3		4
Socket		26		0-25	144-169	288-313	431-457
Outline	41		26-67	170-210	314-354	458-499
LeftEye		10		68-77	211-220	355-364	500-509
LeftCenter	3		78-80	221-223	365-367	510-512
RightEye	10		81-90	225-233	368-377	513-522
RightCenter	3		91-93	234-236	378-380	523-525
Mouth1		8		94-101	237-244	381-388	526-533
Mouth2		8		102-109	245-252	389-396	534-541
Mouth3		10		110-119	253-262	397-406	542-551
Mouth4		14		120-133	263-276	407-420	552-566
Mouth5		10		134-143	277-286	421-430	567-576

Sparkle or Color Fade		Bulb[1,Socket] etc		26,27,28,29,30,…67
Blink						Bulb[2,LeftEye]			211,212,213,214…220
Wink						Bulb[3,RightEye]		368,369,370…377
Mouth						Bulb[4,Mouth3]			542,543,544,545…551

The bottom of that attempts to show what I'm thinking of doing. For example, if I would like to change the color of bulb 2's outline, I would like to be able for my code to be:

setPixel(Bulb[2][outline], 200, 0, 0);

This line would set pixels #170 thru 210 to RED (after the showstrip() )

Just curious on your thoughts for this and to see if I am on the right track.
I'll just have to figure out how best to write my ideas into an array! :slight_smile:


Well I think the idea is there but that is not how to implement it. What I would do is to expand those arrays to cover all the values you want to change at once.

So as an example you have

LeftEye 10 68-77 211-220 355-364 500-509

The second column puzzles me as you have much more than 10 LEDs in this group.

If the other numbers all need to be filled with the same colour then I would define:-

int LeftEye [] = { 68,69,70,71,72,73,74,75,76,77,211,212,213,214,215,216,
                                217, 218,219,220, 355,356,357,358,359,360,361,362, 363,364,

And then use this to set them all:-

byte leftEyeNumber = (sizeof(LeftEye) / sizeof(LeftEye[0]));
for(int i =0; i< leftEyeNumber; i++){
// set colour with LED number ->  LeftEye[i], colour(x,y,z) // the exact command depends on the libiary you are using.

I would also consider putting these arrays in program memory if you run out of space but that is an other step in complexity.

Mike; I couldn't get it to format properly; was hoping that it would look better than this.

I've got 4 bulbs that I tried to identify on the first row of my data above. So, what you have shown:

int LeftEye [] = { 68,69,70,71,72,73,74,75,76,77,211,212,213,214,215,216,
                                217, 218,219,220, 355,356,357,358,359,360,361,362, 363,364,

is actually all the pixels for all 4 LeftEyes
Bulb2 left eye would only be 211-220; bulb4 lefteye would be 500-509

However; I think I do understand where you are going with the code. In this situation I would only need to know two numbers for each 'group'. I.E. Bulb2[lefteye] = 211,10 and Bulb4[lefteye] = 500,10
Knowing that information I think I could easily adapt the code you wrote above to work.

I was just talking to a coworker who does a lot of VB programming and knows a little C; but he recommended using object/classes. I was just starting to look into that when I saw your reply here.

I would avoid using classes, I don’t think you get any advantage using them here.

Bulb4[lefteye] = 500,10

Is not the correct syntax for defining this. Are the eyes lit up separately at any time or all together. I don’t think I have a clear idea about what you are making.
Would this not be better

Bulb4LeftEye []= {500,10};

That is assuming you want to turn on LEDs 500 to 510
But even simpler would be

Bulb4LeftEye []= {500,510};

After reading a bit on classes/etc. I'm in agreement.
While it may get the job done, I don't think I want to go down that road.

Here is a good example of what I"m working towards:

This example was using software like Vixen and while I am not looking to sync to music or anything (yet), for now I just would like to random blink the eyes and occasionally fade/sparkle the bulb coloring.

In your examples above I see a small issue.
I need to know three things for each item:

  1. Bulb Number
  2. Starting pixel number
  3. Number of Pixels for element

so, to light bulb 4's left eye, I would need 4, 500, 10

Looking back over your code in post 6; I will need to read up on the sizeof() command you are using. I've not used anything like that before. But if I could rewrite your 'for' line to be:

for(int i = Bulb[4][leftEyeStart; i<Bulb[4][LeftEyeStart]+[LeftEyeCount]; i++) {

Than I think that would greatly speed up my ideas.

Another thought hit me driving home from work tonight.
I don't need the Bulb[] {1,2,3,4} array... I can just use each 'section' as an array that's 2deep.
so LeftEyes[][] or Outline[][] should work....

I also thought about putting each bulb on it's own pin on the arduino... that may be an option as well...

Still; I'd like to figure out the array to do it all off of the single pin. If nothing else than to do it as a learning experience.

If one dimension of your array was the bulb number.
and the other dimension had the array elements
0. Starting pixel number

  1. Last pixel number + 1
    Then your for loop would be
for(int i = Bulb[4][0]; i<Bulb[4][1]; i++) {