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 no translation for that post!



LED Effects - Scrol...
 
Share:
Notifications
Clear all

[Solved] LED Effects - Scrolling a pattern of 4 forever ...

5 Posts
2 Users
2 Reactions
2,118 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2728
Topic starter  

Based on Andre's question in the All-in-One LED Effects I started a forum topic to keep the code posts in the comment section to a minimum;


Hello Hans

Nice work and explanation for a novice like me
I have 20,000 led Christmas exterior decorations donated 1500 rgb on Chinese programmer
i have an arduino mega 2560 and your script is working amazing
But I’m wondering if I can program a string of 96 rgb leds blinking in 4 state
example 1-5-9-13 until 96
               2-6-10-14 “”
               3-7-11-15 “”
               4-8-12-16 “”
this like simple led garland programmers
sorry i don’t speak english hence google translator
thank you for your response desolé mauvais manipulation


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2728
Topic starter  

Coming back to your question ...
Let me first say: WOW! You have how many LEDs? Please send me pictures - that's impressive!

Since I'm not sure how comfortable you are with code, here a started point on how I have done this in one of my other projects:

1. I recommend using the FastLED library, if you haven't already.
2. Fill the strip with the initially desired pattern (one time only).
3. Shift all LEDs one position (in a loop).
4. Fill in the "new" blank LED with the color you need (in the same loop as step 3).

So step 2 could look something like this (assuming you have defined red, green and blue):

CRGB firstColor = CRGB(255,0,0); // define color of 1st LED
CRGB otherColor = CRGB(0,0,0); // define color of other 3 LEDs

for(int i=0; i<NUM_LEDS; i=i+4) {
led[i] =firstColor;
  for(int j=1; j<4; j++) {
  leds[i+j] = otherColor;
  }
}

Step 3 is very easy with memmove8 (once you know this function exists).
It takes 3 parameters: Destination, Source, Size, where size is the CRGB size times the number of LEDs we'd like to move:

memmove8( &leds[1], &leds[0], (NUM_LEDS-1) * sizeof(CRGB) );

So this moves all LEDs one position, where leds[0] moves to leds[1], leds[1] to leds[2], etc.

The only thing we now need to do is give leds[0] the correct color. This can be done with a confusing function, or we can simply copy the 4th LED.

Leds: X 0 0 0 X 0 0 0 X 0 0 0 X etc

becomes

Leds: ? X 0 0 0 X 0 0 0 X 0 0 0 etc

So we need to determine "?", which is the same color as the position + 4 (marked blue).
So in each step we do this followed by a delay that will influence how fast this effect will go:

leds[0] = leds[4];
delay(500); // 500 ms = ½ second delay

So all combined this effect would look something like this:

CRGB firstColor = CRGB(255,0,0); // define color of 1st LED
CRGB otherColor = CRGB(0,0,0); // define color of other 3 LEDs

for(int i=0; i<NUM_LEDS; i=i+4) {
led[i] = firstColor;  // set LED 0 of the pattern (counting starts with zero)
for(int j=1; j<4; j++) { // set LEDs 1, 2 and 3 of the pattern
  leds[i+j] = otherColor;
  }
}
while(true) {
  memmove8( &leds[1], &leds[0], (NUM_LEDS-1) * sizeof(CRGB) );
  leds[0] = leds[4];
delay(500);
}

I hope this will get you started, if not please feel free to ask questions here in this forum topic 😊 

Note: I have not tested this specific code and typed it all from memory, so there could be typos - I hope not though 😉 


   
ReplyQuote
(@andre)
New Member
Joined: 4 years ago
Posts: 2
 

 

Andre

Hello Hans

Many thanks for the sketch

one part works division by 4 then all blocks

But its probably me the problem not yet competent for this type of programming

I am 70 years old and I started 6 months ago I continue my tests

for christmas photos how to do because 1st time in my life on a forum

I am registered on the forum

once again well thank you for the example I will try to do the sketch

I wish you a happy and merry christmas

Andre

   
Hans reacted
ReplyQuote
(@andre)
New Member
Joined: 4 years ago
Posts: 2
 

désolé pour la traduction

andre


   
Hans reacted
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2728
Topic starter  

Hi Andre!

Merry Christmas to you as well.
And I do apologize for not speaking French (English/Dutch/German I can do though).

Enjoy the holidays, stay healthy and have fun with the Arduino 😉 


   
ReplyQuote
Share: