Howdy smart programming peeps :) I am stuck on a way to achieve the

Howdy smart programming peeps :slight_smile:

I am stuck on a way to achieve the following:

I have a number of LEDs that I want to tell to flash in a certain pattern of colours, the same pattern for each led, each led showing a different pattern from each other. The timing of the patterns are different too.

For example, where colour and pause (off) are 1000ms:

LED1 goes Red, pause, pause, pause, White, pause, pause, pause, Red…
LED2 goes Red, Green, Red, Green, pause, pause, pause, pause, Red, Green…
LED3 goes White, White, Blue, Blue, pause, pause, pause, pause…

I want continuous colours and pauses - so when you go White, White, White, White there is no flicker or on/off, it just stays lit.

I’ve played round with iterating a bunch of arrays, like:

CRGB led1(1);
CRGB led2(1)
CRGB led3(1)

and using them in their own function, but it’s just junk :frowning:

Overall theres a number that ends up being the longest pattern - say 20 seconds in total of continuous light and dark.

My thought was, I would have a function for each pattern that stepped each pattern through and defined the setting for each individual LED, with a central timing sequence in the main loop that called the ‘colourising functions’
So a central counter from 1-20 with a case in each function setting the colour according to the central counter, followed by

FastLED.show();
delay 1000;

in the main loop.

Is that the best approach to something like this?

Feel free to point me to something similar or to make me stand in the corner and reflect on my programming ineptitude - You can t think less of my programming skills than I do :slight_smile:

Something like this should work

Have one array

CRGB Led[num_leds];
CRGB *colorPattern =[crgb::red,crgb::black,crgb::black,crgb::bblack,crgb::white…]

Int k=0;
Void loop
{
For (int i=0;i<num_leds;i++)
Led[i]=colorPattern[(i*k)%sizeofcolorpattern];
Fastled.show();
Delay(10)
k++;
}

I hope this help.
Yves

This was what I did, before I saw your post - it works, but is ugly and laborious: https://pastebin.com/W0V9SVpM

Looking at your code, it steps through the leds sequentially, doesn’t it? I’m still looking at it, but the fact you are counting up the array looks like it is.

However, the method of iterating the pattern is very neat… I think I should be able to make something of that - thanks :slight_smile:

Reference and dereference pointers make my head hurt!

I know I should learn to use them properly, as they save so much code, but ouch :slight_smile:

Right - into the breach. Thanks @Yves_BAZIN - thats definitely the way to go.

@Mike_Thornbury indeed I am going through the entire strip with the ‘for’ loop and then I just take the reference of the color in the pattern array. And the k++ will do the switch of color for a specific led
The switch case in your code
Can easily be replaced by array[i%20];
Wich will make it way simplier

@Mike_Thornbury it should be
cRBG colorPattern[20]={cRBG::Red,crgb::black ,}
And
i+k the and not i*k :wink:

This sounded like an interesting thing to code so I took a stab at it in my own fashion. A tiny bit manual to setup, but hopefully fairly straight forward to understand.

@Mike_Thornbury , I hope you’re going to eventually tell us what project this is for. :slight_smile:

Thanks @marmil - Asking for a friend… :slight_smile:

I got it working using my laborious case method, but I knew there was a better way.

He’s making an interactive shipping map with all the buoys, beacons, lighthouses, lights, using their real colours and patterns.

Which came from another person asking me to help him do the same thing - they are boaties together.

But, it holds promise for other things, like automated dolls-house lighting, train sets, RC aircraft, drones, boats etc. where you want to do stuff like flash a landing beacon, nav lights, cockpit lighting, cabin lighting…

I was even asked to tart up a sea kayak with nav lights and cool cockpit effects for the at-sea-stoner :slight_smile:

@Mike_Thornbury For sure! Yes, if the display time is made much shorter then some creative flashes and blinks could be created.

Actually, just messed around and made this blinky look (might go on an aircraft for example).

Instead of 1000ms, I used a pattern delay of 50ms to be able to get the strobe flashes, and repeated the blue in the center a bunch of times so it does a very slow blink. Red and green have a pattern length of just 1. For fun I removed a few of the repeated blacks in one of the strobes so it’s off time is slightly less then the other. Thus over time they slowly cycle which one fires first and will be in sync only briefly.