Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!




Arduino - Strobing ...
 
Share:
Notifications
Clear all

Arduino - Strobing LEDs with Neopixel library


(@dp34067)
New Member
Joined: 5 years ago
Posts: 0
Topic starter  

I am a complete novice and suspect I have bitten of more than I might chew with this so I'd be extremely grateful for any help and direction that might be forthcoming.

I have lifted the core of the code from Hans's article on LEDStrip effects for Arduino and have made very limited progress as I find my way. So far I have made some minor modifications as is evident from the attached code that includes: -

  1.  Two additional strobe functions including and an additional integer that I have called BlackDelay which for the purpose of what I am trying to achieve requires a different value to the FlashDelay.
  2.  Corresponding duplicate function and statement blocks for the additional strobe functions.

What I would like to do is make each Pixel individually addressable with fixed colour/colour combination and strobe sequences, determined by the values entered for each pixel in the respective strobe functions - There are currently 3 strobe functions per pixel.

I have a Mega 2560 connected via pin 6 and a 470 ohm resistor and, a 1000 uf capacitor across the power rails on the breadboard with 5, PL9823 addressable RGB LEDS for testing but will eventually require >100, therefore 100 or so groups of 3 strobe functions. This is where it is getting messy and I'm sure there is a more professional way of going about this?

Not every one of the intended 100 or so Pixels will be unique, as in, some Pixels may share the same colour/colour combination and strobe sequenceI and I am assuming that if there are say 80 combination variants, that these could be configured in setup and then called from a loop function for each Pixel?

The  modified code is as follows:

#include <Adafruit_NeoPixel.h> // NeoPixel Library

#define PIN 6 // = pin number #define NUM_LEDS 5 // = number of pixels in the daisy chain

// Pixel type flags, include as required:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'V1' (not V2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels configured for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels configured for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_RGB + NEO_KHZ800); // Using PL9823 RGB LED (WS2811 drivers)
void setup() { strip.begin(); strip.show(); // Initialise all pixels to 'off' }
void loop() { // Strobe0 Strobe0(0xff, 0xff, 0xff, 5, 100, 500, 5000); // Strobe1 Strobe1(0x00, 0xff, 0x00, 1, 500, 1000, 3000); // Strobe2 Strobe2(0xff, 0xff, 0x00, 3, 300, 500, 3000); }
void Strobe0(byte red, byte green, byte blue, int Strobe0Count, int Flash0Delay, int Black0Delay, int End0Pause){ for(int j = 0; j < Strobe0Count; j++) { setAll(red,green,blue); showStrip(); delay(Flash0Delay); setAll(0,0,0); showStrip(); delay(Black0Delay); } delay(End0Pause); }
void Strobe1(byte red, byte green, byte blue, int Strobe1Count, int Flash1Delay, int Black1Delay, int End1Pause){ for(int j = 0; j < Strobe1Count; j++) { setAll(red,green,blue); showStrip(); delay(Flash1Delay); setAll(0,0,0); showStrip(); delay(Black1Delay); } delay(End1Pause); }
void Strobe2(byte red, byte green, byte blue, int Strobe2Count, int Flash2Delay, int Black2Delay, int End2Pause){ for(int j = 0; j < Strobe2Count; j++) { setAll(red,green,blue); showStrip(); delay(Flash2Delay); setAll(0,0,0); showStrip(); delay(Black2Delay); } delay(End2Pause); }
void showStrip() {
strip.show(); }
void setPixel(int Pixel, byte red, byte green, byte blue) {
strip.setPixelColor(Pixel, strip.Color(red, green, blue)); }
void setAll(byte red, byte green, byte blue) { for(int i = 0; i < NUM_LEDS; i++ ) { setPixel(i, red, green, blue); } showStrip(); }

I would be extremely grateful for any comments and ideas as to the methodology for this more complicated variant of the original code.


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1840
 

As far as I can see, you wouldn't need 3 strobe functions, they all look the same to me.

void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int BlackDelay, int EndPause){
  for(int j = 0; j < StrobeCount; j++) {
    setAll(red,green,blue);
    showStrip();
    delay(FlashDelay);
    setAll(0,0,0);
    showStrip();
    delay(BlackDelay);
  }

And your loop would look something like this:

void loop() { 
  // Strobe0
  Strobe(0xff, 0xff, 0xff, 5, 100, 500, 5000);
  // Strobe1
  Strobe(0x00, 0xff, 0x00, 1, 500, 1000, 3000);
  // Strobe2
  Strobe(0xff, 0xff, 0x00, 3, 300, 500, 3000);
}

Maybe I'm overlooking something here (nowhere near my stuff to test).


ReplyQuote
(@dp34067)
New Member
Joined: 5 years ago
Posts: 0
Topic starter  

Hello Josef,

Perhaps I havent explained clearly enough.

The reason for the 3 separate strobe functions is that up to 3 different stobe sequences may be applied to the same pixel in one cycle:

Example

Pixel 0 may flash red for 100ms 2 times with a delay of 200ms between flashes then a black period of 3000ms, then flash white for 200ms 5 times with a delay of 500ms between flashes then a black period of 10000ms, then flash blue for 200ms 6 times with a delay of 100ms between flashes then a black period of 3000ms, then return to start - red twice for 100ms, delay 200ms etc. .............

Pixel 1 may flash yellow for 100ms 5 times with a delay of 200ms between flashes then a black period of 1500ms, then return to the start of the cycle - yellow 5 times for 100ms, delay 200ms etc. .............

Pixel 2 .........

  • Each pixel will have its own strobe sequence that once set, will not change.
  • The strobe sequence for each pixel may be set to any combination of between 1 strobe sequence and 3 strobe sequences in one cycle.
  • Each pixel may be different to any other pixel.
  • All pixels will be cycling at the same time with their own sequence - obviously not synchronised as each pixl may have different strobe cycles.
  • The loop is continuous for the entire sring of pixels - once started, the loop continues without a break.
  • The break/reset routine should run once at the power up start and
    should light all pixels constantly for 10 seconds before starting the
    main strobe routine.
  • A break/reset may be initiated by the use of a push button momentary switch that will ground a suitable data pin and trigger the break/reset which should light all pixels constantly for 10 seconds before restarting the main strobe routine.

I hope this helps to clarify the matter.

Regards

David


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1840
 

Ah, I think I get what you mean now.

This looks like a pretty challenging strobe sequence when it comes to timing.

We'd almost have to break the sequence in 100ms steps, where a LED can have a color or not. Where the black periods are to be seen as a regular "strobe" color, just black.

So for example Pixel 0 the sequence would be:

RED, BLACK x2, RED, BLACK x30, WHITE x2, BLACK x5, WHITE x2, BLACK x5, WHITE x2, BLACK x5, WHITE x2, BLACK x5, WHITE x2, BLACK x5, WHITE x2, BLACK x5, WHITE x2, BLACK x100, BLUE x2, BLACK, BLUE x2, BLACK, BLUE x2, BLACK, BLUE x2, BLACK, BLUE x2, BLACK, BLUE x2, BLACK x30.

Where each "color" is shown for 100ms and the color black is the same as the LED being "OFF".

Does that sound about right (for the first LED)? 

If so, then it looks like we would need to define a pretty big array, holding the patterns for each LED, for each 100ms.

LED0 - red, black, black, red, black, black, black, black, black, black, black, black, black, black ... etc

LED1 - (similar)

etc.

In a loop we count then through the array, setting each LED color, depending on the position we're at.


ReplyQuote
(@dp34067)
New Member
Joined: 5 years ago
Posts: 0
Topic starter  

Hi Josef,

If that is the most efficient method then yes I think that is it.

For the time being we can limit the max number of pixels to 90 and the max number of strobe sequences to 2.

I'm assuming that you would give each array a unique name and if there is more than one pixel in the daisy chain that has the same strobe sequence, then we could call the same array for the strobe sequence used by another pixel.  If my assumption is correct I would like each Strobe array to be simply named such as strobe00, strobe 01, strobe02 ......

For clarity, what I am saying is, of the 90 pixels in total, 10 pixels share the same strobe sequence, then there would be 80 different arrays and not 90 - is that a correct supposition?

In reality there will probably be about 50 different strobe cycles and some of the strobe cycles will be unique to 1 pixel and in other cases one strobe cycle will be shared by 2 or more pixels.

NOTE: - Some strobe sequences will be the same timing but just the colour/s will be different.

This leads me into the next question - As I currently have limited knowledge but can fairly easily interpret the code once it is written, will it be possible to easily amend the code for different strobe sequences and smaller or larger numbers of pixels, i.e.will the sketch be scaleable for greater or fewer pixels and strobe sequences.

Looking ahead, the colours will be as follows: -

  • Red
  • Green
  • Blue
  • Yellow
  • Orange
  • White
  • Black

I hope I'm not over complicating matters?

Regards

David


ReplyQuote


(@dp34067)
New Member
Joined: 5 years ago
Posts: 0
Topic starter  

ADDENDUM

"For the time being we can limit the max number of pixels to 90 and the max number of strobe sequences to 2 per pixel."


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1840
 

Hi David,

(ps. my name is Hans, and not Joseph haha)

Your project wil take some time and effort to create.
Also not that an array can also be multi-dimensional, so with 2 dimensions we have rows and columns (like and Excel sheet).
So the row could be dedicated to a particular LED or LED group, and the column represents the 100ms color slots.
It will however take a lot of work to write out such an array and at some point we might run into memory limitations of the Arduino.

(hope that made sense)

The idea is indeed to write code so it's easy to modify afterwards, especially when colors and such change.


ReplyQuote
(@dp34067)
New Member
Joined: 5 years ago
Posts: 0
Topic starter  

Hello Hans,

My apologies, I was talking to somone in a different forum on the same subject and got confused!

That would also explain why it might have appeared to you that I was assuming you might undertake the work, that was not my intention in the context of this particular thread and again my apologies.

I realise that this could be a fairly significant amount of work and that I may need to offer a commercial incentive for somone to undertake the bulk of the coding as whilst I intend to get to grips with C I don't currently have the time in relation to this project.  Having said that, if there are any elements such as the array that are repetitive but relatively simple to set up then I could do the crunching for the arrays.

I have read the rules of the forum and cannot see any reference to not making a commercial offer in relation to a particular project so if you or indeed any other member reading this is interested in helping me out for a fee I would be interested in discussing the matter further.


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1840
 

No problem David haha ... it happens ...

You're most certainly free to offer a commercial incentive to get this build. It will indeed take some time ... but the most work will be in defining the patterns in arrays, and since you're the one knowing the specifics of the patterns, I would probably be you doing most of the work to begin with ...  

Feel free to send me an email (webmaster at tweaking4all dot com) with the suggestion you have in mind.
Also feel free to post a new topic with a description and a proposal for a bounty/incentive. I'm not sure if there are many users that would be interested, but you are free to ask ... 


ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: