0

flashing different groups on one strip
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

flashing different groups on one strip

by Merkelck on Thu Feb 22, 2018 3:29 pm

I am interested in being able to flash specified groups (0-9,10-19,20-29) leds in a NEOPIXEL strip, Using different colors for each group. Can someone point me to some information regarding this or tell me if it is even possible in the same strip. I have considered using multiple strips to accomplish the same goal but was hoping it could be done with one strip
Thanks
KentM

Merkelck
 
Posts: 39
Joined: Mon Jan 22, 2018 10:55 pm

Re: flashing different groups on one strip

by kcl1s on Thu Feb 22, 2018 4:03 pm

Yes this will work. If you want to do different speeds or animations at the same time you will have to look into multitasking for the Arduino. These 3 tutorials have a lot of info on the subject https://learn.adafruit.com/search?q=multitasking&

Fellow Hobbyist
Keith

kcl1s
 
Posts: 857
Joined: Tue Aug 30, 2016 12:06 pm

Re: flashing different groups on one strip

by chemdoc77 on Thu Feb 22, 2018 6:25 pm

Hi KentM:

You asked:

I am interested in being able to flash specified groups (0-9,10-19,20-29) leds in a NEOPIXEL strip, Using different colors for each group.


You can use FastLED's CRGBSet array function along with the fill_solid function to do that. For an example of this, see:

https://gist.github.com/chemdoc77/80ab638588399c9a09e26a296d56f6e6

In that sketch, I put the CRGBSet array names in an array of arrays. You do not need to do that if you do not want to. You can put the CRGBSet array name directly into the fill_solid function.

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 119
Joined: Mon Jan 28, 2013 9:32 am

Re: flashing different groups on one strip

by Merkelck on Fri Feb 23, 2018 11:51 am

Thanks to you both for the suggestions. I put them both to the test and learned a lot from both methods. I wound up to the closest answer with the array method suggested by ChemDoc77. I am very close to having the answer but do have some remaining puzzles. My exact situation is that I have a 4m strip of ws2812b (ws2811) @60/m for a total of 240 pixels. These are being wrapped around the top of 2" aluminum flagpole. I have divided them into three 80 pixel sections and using the "fill_solid" functions, I flash the top 80 red, the mid section white and the bottom section blue. I am trying to figure out how to put those three sections of code together so that I can repeat that sequence several times. I simply removed the "rainbow" functions from the code.
Then I moved on to the code using the cd77 arrays. It looks to me like I could use that section by itself to do what I wanted in the first place. However, what I tried yielded some weird results. First I added a third line "cd77_arrayfill(CRGB::White);". Then I changed the number of pixels to 80. This worked fine. But then I got greedy and changed the number to 240. This looked promising until it got the red array. They all lite up nicely and then the whole thing went dead. I discovered while I was sitting there thinking about that after several minutes the sequence started again by itself and went to the same point and stopped. By now I am thinking a power problem, the PS itself is rated 5v@20Amps. Then I recalled that there was a power management statement in the code. Not fully understanding that code, I simply commented it out to see if the made any difference. I also questioned the next line of code dealing with pin 13??? I ran it again but got the same results. So I am going to try some more research next into the power situation. I am running the Arduino from the USB power and the pixels from the PS. The grounds are tied together. So I need to figure out why the thing is shutting down when lighting all the leds and then find a way to group the "fill_solid" function together.
Thanks for any and all assistance.
KentM

Merkelck
 
Posts: 39
Joined: Mon Jan 22, 2018 10:55 pm

Re: flashing different groups on one strip

by chemdoc77 on Fri Feb 23, 2018 12:23 pm

Hi KentM:

I am glad you are making progress.

Please confirm which animation you want:

A) to start with a dark NeoPixel strip, then have the red section go on and stay on, followed by the white section go on and stay on followed by the blue section go and stay on and finally all the sections go black and this animation repeats again.

B) to start with a dark NeoPixel strip, then have the red section go on and stay on for a period of time and go black, followed by the white section go on stay on for a period of time and go black, followed by the blue section go stay on for a period of time and go black and this animation repeats again.

You can do both but which animation do you want?

Please post your complete sketch here using the code button.

I am sure that once I see your complete sketch that I can help you make it work.

Finally a number in the CRGBSet array statement should never be larger than Num_LEDS -1, since you start numbering your leds at 0. That is probably the reason your strip went dead. I learned this lesson about using a number higher than Num_LEDS -1 in functions and the same thing that happened to you happened to me.

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 119
Joined: Mon Jan 28, 2013 9:32 am

Re: flashing different groups on one strip

by Merkelck on Fri Feb 23, 2018 3:30 pm

Thanks again, ChemDoc77
First of all, what I was using was your description B. But I like A as well and I have that figured out. I just need to work on a loop to run that section a specified number of times. The second part is where I tried to flash all the pixels at the same time. First all red then all white and finally all blue. What I tried first was to put the number 240 in both the color statement and the Black statement. But all red would come on and immediately go dark. Some time later the whole cycle would start over. Then I discovered (as the code is now) that using 80 in there instead of 240 would produce 0-79 red, black, then 80-159 red, and finally 160-239 red. Then repeat with white and then with blue. This was very stable and worked every time. If I used a smaller number than 80 (40) would work 0-39, 80-119, 160-199.
I would really like to flash all 240 red/white/blue for a specified number of time and then return to the loop at the start.
Thanks for your assistance
KentM
[code// Testing FastLED's CRGBSet array function and using it with the fill_solid and fill_rainbow functions.
// by Chemdoc77

#include "FastLED.h"
#define NUM_LEDS 240
#define Data_Pin 6
#define chipset NEOPIXEL
#define BRIGHTNESS 60


CRGB rawleds[NUM_LEDS];
CRGBSet leds(rawleds, NUM_LEDS);
CRGBSet leds1(leds(0,79));
CRGBSet leds2(leds(80,159));
CRGBSet leds3(leds(160,239));

struct CRGB * ledarray[] ={leds1, leds2, leds3};

void setup() {
delay(2000); // power-up safety delay
FastLED.addLeds<chipset, Data_Pin>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.setMaxPowerInVoltsAndMilliamps(5,16500);
set_max_power_indicator_LED(13);

}


void loop() {

fill_solid(ledarray[0], 80, CRGB( 255, 0, 0));
FastLED.show();
delay(700);
fill_solid( ledarray[0], 80, CRGB::Black);
FastLED.show();

fill_solid(ledarray[1], 80, CRGB(127, 127, 127));
FastLED.show();
delay(700);
fill_solid( ledarray[1], 80, CRGB::Black);
FastLED.show();

fill_solid(ledarray[2], 80, CRGB::Blue);
FastLED.show();
delay(700);
fill_solid( ledarray[2], 80, CRGB::Black);
FastLED.show();


cd77_arrayfill(CRGB::Red, 700);
cd77_arrayfill(CRGB::White, 700);
cd77_arrayfill(CRGB::Blue, 700);
}
//================ New Function =====================

void cd77_arrayfill(CRGB color, uint16_t wait){

for (uint8_t x=0; x<3; x++){
fill_solid(ledarray[x], 80, color);
FastLED.show();
delay(wait);
fill_solid( ledarray[x], 80, CRGB::Black);
FastLED.show();

}

}
[/code]

Merkelck
 
Posts: 39
Joined: Mon Jan 22, 2018 10:55 pm

Re: flashing different groups on one strip

by chemdoc77 on Fri Feb 23, 2018 3:46 pm

Hi KentM:

I have just written and posted on Gist a sketch that will do either animation that I mentioned in my previous post. It is located at:

https://gist.github.com/chemdoc77/2994b935d333c0c8cbf68d4d7782f6b3

I tested both functions on a 240 NeoPixel strip (4m 60 leds/m strip) and it works fine.

I tested it on Teensy 3.6 using the Arduino 1.8.3 IDE along with the Teensyduino 1.37. FYI, my Teensy 3.2 is being used in a 12 volt project so I used the 3.6. It should work on other MCUs with enough memory.

Please test it out. You will probably want to increase the milliamp level in line 30 to a higher level when you increase the BRIGHTNESS in line 11. You probably will need to inject power at the end of the strip for higher BRIGHTNESS levels.

This sketch assumes that pixel 0 is the first red pixel. If not, let me know so that I can help you make changes in the code.

If it does what you want and you use it, I have a request for you. Please post a video of your final project here so that I and everyone else can enjoy your finished project.

Finally, I have written a sketch that allows one to have groups of colored bars of various sizes and colors move on a NeoPixel strip at various intervals and speeds. This might be of interest to you. It can be found at:

https://forums.adafruit.com/viewtopic.php?f=47&t=128473

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 119
Joined: Mon Jan 28, 2013 9:32 am

Re: flashing different groups on one strip

by chemdoc77 on Fri Feb 23, 2018 4:32 pm

Hi KentM:

I have just added your new requested function that does what you asked with the whole strip one color at a time and it repeats z times to my gist at:

https://gist.github.com/chemdoc77/2994b935d333c0c8cbf68d4d7782f6b3

Also, I have the other functions running in the sketch loop, too.

It works well on my 240 NeoPixel strip with my Teensy 3.6. Please let me know if you have any more questions.

I am looking forward to seeing your finish project.

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 119
Joined: Mon Jan 28, 2013 9:32 am

Re: flashing different groups on one strip

by Merkelck on Sat Feb 24, 2018 4:50 pm

Hello, Here is the code that I am using at the moment. I rearranged some of your code to get here. The only addition that I would like to make would be to flash the final segment where all three colors are lit at the same time. I have tried several different things but my expertise just isn't there yet. I also have the video stuff set up and will get that going quickly. I am more than pleased with what I have right now thanks to your gracious help.
I just can't thank you enough for your help.
KentM
I would like to add something in the last segment of code where I have the 5sec delay that would flash all three colors at the same time..

Code: Select all | TOGGLE FULL SIZE
// special request - fill NeoPixel strip with one third red, one third white and one third blue.
// by Chemdoc77

//This was run on a Teensy 3.6 using the Arduino 1.8.3 and the Teensyduino 1.37


#include "FastLED.h"
#define NUM_LEDS 240
#define Data_Pin 6
#define chipset NEOPIXEL
#define BRIGHTNESS 20  //set the strips brightness from 1 to 255


CRGB rawleds[NUM_LEDS];
CRGBSet leds(rawleds, NUM_LEDS);
CRGBSet leds1(leds(0,79));
CRGBSet leds2(leds(80,159));
CRGBSet leds3(leds(160,239));

struct CRGB * ledarray[] ={leds1, leds2, leds3};
CRGB colorarry[]=  {CRGB::Red,CRGB::White, CRGB::Blue};

uint16_t x=0;  // needed so one can use x outside of a for statement


void setup() {
 delay(2000); // power-up safety delay
 FastLED.addLeds<chipset, Data_Pin>(leds, NUM_LEDS);
 FastLED.setBrightness(BRIGHTNESS);
 FastLED.setMaxPowerInVoltsAndMilliamps(5,1000);

}

void loop() {
cd77_arrayfill_RWB_all_one_color(3,450); // lights up the whole strip with one color at a time and repeats z times.
delay(2000);
cd77_arrayfill_RWB_each_alone(3,450); // lights up each segment in order
 delay(1000);
cd77_arrayfill_RWB_all(500); //lights up each segment and keeps it on until the end of the animation.
 delay(2000);
 }

 //================ New Function =====================


void cd77_arrayfill_RWB_all_one_color(uint16_t repeat, uint16_t wait){
 
  for(uint16_t z=0; z<repeat; z++){
   for ( x=0; x<3; x++){
  fill_solid( leds, NUM_LEDS, colorarry[x]);
   FastLED.delay(wait);
   fill_solid( leds, NUM_LEDS, CRGB::Black);
   FastLED.delay(wait);
    }
  }
}


void cd77_arrayfill_RWB_each_alone(uint16_t repeat, uint16_t wait){
  for(uint16_t z=0; z<repeat; z++){ 
  for ( x=0; x<3; x++){
  fill_solid(ledarray[x], 80, colorarry[x]);
   FastLED.delay(wait);
 
   fill_solid( ledarray[x], 80, CRGB::Black);
   FastLED.show();
    }
  }
}



void cd77_arrayfill_RWB_all (uint16_t wait){
 
   for ( x=0; x<3; x++){
  fill_solid(ledarray[x], 80, colorarry[x]);
   FastLED.delay(wait);}
   delay(5000);
   fill_solid( leds, NUM_LEDS, CRGB::Black);
   FastLED.delay(wait);
 
  }

Merkelck
 
Posts: 39
Joined: Mon Jan 22, 2018 10:55 pm

Re: flashing different groups on one strip

by chemdoc77 on Sat Feb 24, 2018 7:32 pm

Hi KentM:

I am glad that you like what I have done so far.

For your new function request, do you want:

A) all the color arrays to light up at the same time and stay on for 5 seconds

Or

B) all the color arrays to light up at the same time and then all of the color arrays blink on and off together at a certain rate for 5 seconds?

I can do either. Which do you want?

Finally, I learned from the FastLED G+ Community:

https://plus.google.com/communities/109127054924227823508

that the white color “looks” brighter to our mind than certain other colors like red and blue on a strip at the same strip brightness. This is fixed by using CRGB::Grey instead of CRGB::White. It still looks white but all colors look the same brightness, now. You might want to change this in line 21 of my code and see if this is better for you. I did on my test strip and it looks better to me.

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 119
Joined: Mon Jan 28, 2013 9:32 am

Re: flashing different groups on one strip

by Merkelck on Tue Feb 27, 2018 2:45 pm

Hello chemdoc77,
I just discovered that my last post does not appear to have made it here. More than likely an old fart error. I have a video on youtube
of the current progress. As you can see, in the early stages. If I make any more changes to the code it would be to make the final section flash all three segments simultaneously. The next big issue will be to decide on the controller and whether or not it will be mounted at the top of the pole or at the base where I could make code changes whenever I want to. But I am not sure that the controller outputs will stand a long run to the light strips.
Always a challenge
Thanks again for your support.
KentM

https://www.youtube.com/watch?v=0TSwhw_E4xs

Merkelck
 
Posts: 39
Joined: Mon Jan 22, 2018 10:55 pm

Re: flashing different groups on one strip

by chemdoc77 on Wed Feb 28, 2018 8:54 am

Hi KentM:

Your YouTube video looks great. I am looking forward to seeing the finished project.

Can you please let me know which type of final animation you want with all three color segments flashing on and off ( see my last post).

How tall is your flagpole? What would be the cable length from your MCU and the NeoPixel strip? What gauge RGB LED wire are you using between your MCU and the NeoPixel strip?

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 119
Joined: Mon Jan 28, 2013 9:32 am

Re: flashing different groups on one strip

by Merkelck on Wed Feb 28, 2018 10:04 am

Hello chemdoc77,
Sorry, I forgot that issue. I would like to be able to flash the complete combination of last three segments at the same time. Kind of a "finale" to the whole animation.
As for the flagpole, it is twenty feet long. The decision as to where to locate the controller has not been made. If I locate it at the pole it will have to be at the top because of the direction I wound the strip on to the pole. If I locate the controller in my shop ( the pole is three feet from the shop.) , I could feed the strip from the bottom. No matter where, I would probably use a number 14 or 12 to carry the 5 volt power from the shop to the pole. I am most concerned about the signal wire.
Another concern for me is just how much of a controller do I need to do this job. Most of these devices appear to be overkill for my project even if I think it is "complicated"... I have also thought about the use of a wifi controller at the pole or in the shop for that matter. The shop is a small out building. I'm not claiming to be lazy, but I would eventually be telling Alexa to "turn on the flagpole". I am currently playing with the ESP8266NODEMCU device.
For now I am just trying to get the code finalized. I have to avoid tweaking it to death!!!!
Thanks as usual
KentM

Merkelck
 
Posts: 39
Joined: Mon Jan 22, 2018 10:55 pm

Re: flashing different groups on one strip

by chemdoc77 on Wed Feb 28, 2018 11:08 pm

Hi KentM:

I have added your new requested animation to the following Github sketch:

https://gist.github.com/chemdoc77/2994b935d333c0c8cbf68d4d7782f6b3

As to the MCU, I would recommend that you consider using the Adafruit Metro Mini for this project. I have used them in a number of projects. They work well with FastLED. You can hook up your 5 volt power supply directly to the Metro Mini to power it. They are built with the same high quality that you except from an Adafruit product. I have used ESP-8266EX based MCU boards with FastLED. I have not started with the WiFi part of it yet. It is a lot of work and that is way down on my To Do list. I would stick with the Metro Mini.

As to the cable length, I would suggest that you do an experiment and have a 25 foot cable between your MCU and the NeoPixel strip. See if the sketch will run correctly. If you are having problems, the sketch will not run correctly as seen by flickering or the last pixels do not light correctly. If this happens then consider the following posts for ideas how to do long cable runs:

http://www.teknynja.com/2014/02/driving-ws2812neopixels-rgb-leds-over.html

https://plus.google.com/+JasonCoon1/posts/EJsbqE3imgS

Jason Coon’s post might be of interest to you which is based on work by Paul Stoffregen which Jason provides a link to.

Finally, I would urge you to consider adding the two resistor fix to protect the NeoPixels. Here is a link to a post on how to make and use the two resistor fix:

https://forums.adafruit.com/viewtopic.php?f=47&t=50434&p=254414&hilit=ws2812.jpg#p254414

and look for ws2812.jpeg. I use it on all of my projects.

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 119
Joined: Mon Jan 28, 2013 9:32 am

Re: flashing different groups on one strip

by Merkelck on Sat Mar 03, 2018 10:35 pm

Hello chemdoc77,
Here is an update as of Saturday evening in North Texas. I have incorporated your latest code additions and tweaked them a little to add exactly what I wanted. But for now I am declaring the code as "finalized". I say with "tongue in cheek". Most of my effort is now going toward the mechanical issues. I have the diffuser tube and the mounting spacers for that unit ready. My next effort is going to be to decide on the appropriate cabling as I fully intend to mount the controller in my shop so that I can have access to make changes as I see fit. Right now I have it running on a Arduino Pro Mini but I am going to investigate the Metro as you suggested. By the way, the diffuser tube that I will use is a piece of translucent acrylic that is 3" OD that allows me about 5/8 in of space for the leds that will be wrapped around the two inch aluminum pole.
I have already incorporated the two resisters into the system...
I will be publishing some photos here as well as on youtube with the link here. I am planning to have this in the air by the end of the week if not before.
Thanks for all of your assistance and effort.
KentM

Merkelck
 
Posts: 39
Joined: Mon Jan 22, 2018 10:55 pm

Please be positive and constructive with your questions and comments.