Notifications
Clear all

Theatre chase in opposite directions.

155 Posts
6 Users
2 Likes
11.5 K Views
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

Hi All,

         I am putting a sketch together for addressable LED's based on FastLED library. I would like to include a section where the LEDS light up and travel in opposite direction simultaneously. Any ideas?

 

Thanks,

Davy.


   
Quote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2527
 

@davy-ps

I'm not clear in my mind how any one LED will display two colours running in opposite directions at the same time.

Do you mean that all the odd numbers will be travelling one way and all the even numbers be travelling the opposite direction ? 

Also, do you mean that only one LED "runs" in each direction or that multiple LEDs will be lit at the same time ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

Hi Will,

          I am after the effect shown in this YouTube video at mark 3.20 to 3.22. Where the LEDS illuminate at each end and move toward each other and continue past each other. Single colour is OK.

 

Thanks,

Davy.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2527
 

@davy-ps 

That should be fairly easy. I think that you'll find the example sketch 'Cylon' (included in the FastLED library examples) will give you a very good base for the effect you want.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

That worked!!!!!!!!!! Thanks a lot Guys.

 

Cheers,

 

Davy.


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

Guys, if I can impose on your good nature again, I have noticed that the delay isn't being applied in one of the loops. I  have highlighted where it starts in red on the attached sketch. What happens is when LED [3] lights up it stays on for approximately twice as long as 0, 1 & 2. When the remaining LED's light they do the same as if there is no delay specified. IE light in sequence for twice as long as first three with no pause. So where it states {to pick one at random}

leds[5] = CRGB(0, 0, 0); //Yellow LED
delay(100);

It seems as if this is being ignored.

Any ideas? 

 

Cheers,

Davy.

image

 

 

 

[code]

#include <Adafruit_NeoPixel.h>
#include <FastLED.h>

#define LED_PIN 4
#define NUM_LEDS 9
CRGB leds[NUM_LEDS];
uint8_t hue = 0;

void setup() {
// Setup Serial Monitor
Serial.begin(9600);

FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(250);
}
void loop() {

for (int i = 0; i < NUM_LEDS; ++i) {
leds[i] = CHSV(hue + (i * 10), 255, 255);
}

//You can change the pattern speed here
EVERY_N_MILLISECONDS(300){
hue++;
}

FastLED.show();

leds[0] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(100);
leds[0] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(100);

leds[1] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(100);
leds[1] = CRGB(0, 0, 0); //Green LED
FastLED.show();
delay(100);

leds[2] = CRGB(0,25, 125); //Blue LED
FastLED.show();
delay(100);
leds[2] = CRGB(0, 0, 0); //Blue LED
FastLED.show();
delay(100);

leds[3] = CRGB(0,25, 125); //Blue LED
FastLED.show();
delay(100);
leds[3] = CRGB(0, 0, 0); //Blue LED
FastLED.show();
delay(100);

leds[4] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(100);
leds[4] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[5] = CRGB(25, 55, 0); //Yellow LED
FastLED.show();
delay(100);
leds[5] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[6] = CRGB(105, 25, 0); //Yellow LED
FastLED.show();
delay(100);
leds[6] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[7] = CRGB(0, 95, 150); //Yellow LED
FastLED.show();
delay(100);
leds[7] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[8] = CRGB(255, 0, 200); //Yellow LED
FastLED.show();
delay(100);
leds[8] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[8] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(100);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(100);

leds[7] = CRGB(255,255,0); //Red LED
FastLED.show();
delay(00);
leds[7] = CRGB(0, 0, 0); //Green LED
FastLED.show();
delay(100);

leds[6] = CRGB(0,25, 125); //Blue LED
FastLED.show();
delay(100);
leds[6] = CRGB(0, 0, 0); //Blue LED
FastLED.show();
delay(100);

leds[5] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(100);
leds[5] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[4] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(100);
leds[4] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[3] = CRGB(25, 55, 0); //Yellow LED
FastLED.show();
delay(100);
leds[3] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[2] = CRGB(105, 25, 0); //Yellow LED
FastLED.show();
delay(100);
leds[2] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[1] = CRGB(0, 95, 150); //Yellow LED
FastLED.show();
delay(100);
leds[1] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[0] = CRGB(255, 0, 200); //Yellow LED
FastLED.show();
delay(100);
leds[0] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[0] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(100);
leds[0] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(100);

leds[1] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(100);
leds[1] = CRGB(0, 0, 0); //Green LED
FastLED.show();
delay(100);

leds[2] = CRGB(0,25, 125); //Blue LED
FastLED.show();
delay(100);
leds[2] = CRGB(0, 0, 0); //Blue LED
FastLED.show();
delay(100);

leds[3] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(100);
leds[3] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[4] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(100);
leds[4] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[5] = CRGB(25, 55, 0); //Yellow LED
FastLED.show();
delay(100);
leds[5] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[6] = CRGB(105, 25, 0); //Yellow LED
FastLED.show();
delay(100);
leds[6] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[7] = CRGB(0, 95, 150); //Yellow LED
FastLED.show();
delay(100);
leds[7] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[8] = CRGB(255, 0, 200); //Yellow LED
FastLED.show();
delay(100);
leds[8] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[8] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(100);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(100);

leds[7] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(00);
leds[7] = CRGB(0, 0, 0); //Green LED
FastLED.show();
delay(100);

leds[6] = CRGB(0,25, 125); //Blue LED
FastLED.show();
delay(100);
leds[6] = CRGB(0, 0, 0); //Blue LED
FastLED.show();
delay(100);

leds[5] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(100);
leds[5] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[4] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(100);
leds[4] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[3] = CRGB(25, 55, 0); //Yellow LED
FastLED.show();
delay(100);
leds[3] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[2] = CRGB(105, 25, 0); //Yellow LED
FastLED.show();
delay(100);
leds[2] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[1] = CRGB(0, 95, 150); //Yellow LED
FastLED.show();
delay(100);
leds[1] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[0] = CRGB(255, 0, 200); //Yellow LED
FastLED.show();
delay(100);
leds[0] = CRGB(0, 0, 0); //Yellow LED
delay(100);

leds[0] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(1000);
leds[0] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(1000);

leds[1] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(1000);
leds[1] = CRGB(0, 0, 0); //Green LED
FastLED.show();
delay(1000);

leds[2] = CRGB(0,0, 255); //Blue LED
FastLED.show();
delay(1000);
leds[2] = CRGB(0, 0, 0); //Blue LED
FastLED.show();
delay(1000);

leds[3] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(1000);
leds[3] = CRGB(0, 0, 0); //Yellow LED
delay(1000);

leds[4] = CRGB(255, 255, 0); //Yellow LED
FastLED.show();
delay(1000);
leds[4] = CRGB(0, 0, 0); //Yellow LED
delay(1000);

leds[5] = CRGB(25, 55, 0); //Yellow LED
FastLED.show();
delay(1000);
leds[5] = CRGB(0, 0, 0); //Yellow LED
delay(1000);

leds[6] = CRGB(105, 25, 0); //Yellow LED
FastLED.show();
delay(1000);
leds[6] = CRGB(0, 0, 0); //Yellow LED
delay(1000);

leds[7] = CRGB(0, 95, 150); //Yellow LED
FastLED.show();
delay(1000);
leds[7] = CRGB(0, 0, 0); //Yellow LED
delay(1000);

leds[8] = CRGB(255, 0, 200); //Yellow LED
FastLED.show();
delay(1000);
leds[8] = CRGB(0, 0, 0); //Yellow LED
delay(1000);

leds[0] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[0] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[8] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[1] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[1] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[7] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[7] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[2] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[2] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[6] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[6] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[3] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[3] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[5] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[5] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[4] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[4] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[4] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[4] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[5] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[5] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[3] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[3] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[6] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[6] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[2] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[2] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[7] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[7] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[1] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[1] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[8] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[0] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[0] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[8] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[0] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[0] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[7] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[7] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[1] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[1] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[6] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[6] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[2] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[2] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[5] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[5] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[3] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[3] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[4] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[4] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[4] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[4] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[3] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[3] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[5] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[5] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[2] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[2] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[6] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[6] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[1] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[1] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[7] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[7] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[0] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(80);
leds[0] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[8] = CRGB(255,0,0); //Red LED
FastLED.show();
delay(80);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(80);

leds[7] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(400);
leds[7] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(400);

leds[8] = CRGB(0,0,255); //Red LED
FastLED.show();
delay(400);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(400);

leds[7] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(400);
leds[7] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(40);

leds[8] = CRGB(0,0,255); //Red LED
FastLED.show();
delay(400);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(40);

leds[7] = CRGB(0,255,0); //Red LED
FastLED.show();
delay(400);
leds[7] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(400);

leds[8] = CRGB(0,0,255); //Red LED
FastLED.show();
delay(400);
leds[8] = CRGB(0, 0, 0); //Red LED
FastLED.show();
delay(400);
}
[/code]


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2527
 

@davy-ps 

It'll take a lifetime just to read that code 🙂 i've attached a new version (called davy3) where the commands are adapted to use a subroutine with only one line per LED as in the original. The blinkIt takes the following arguments: LED number, the 3 colour arguments and the delay time.

Please run this sketch to verify that it works (i don't have the required components). If it does work, please convert the rest of the commands to call the sub the same way the first few are done.

Then, please repost your sketch and ask your question again.

Note that the first leds[3] block in your original duplicates the leds[2] block above it. Is this intentional? It would seem to double the time and may relate to your stated problem.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

Hi Will,

          Your version of sketch gives same result. When it gets to blinkIt  (3,0,25,125,100); and onward, the LED stays on for twice as long and there is no delay as 4,5,6,and 7 light up. It's as if the pin is high for the delay as well. Thanks so much for your time.

With the blinkIt command, is that a built in function of the library?   ;-}

 

Cheers Mate,

 

Davy.

image

 


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2527
 
Posted by: @davy-ps

Hi Will,

          Your version of sketch gives same result. When it gets to blinkIt  (3,0,25,125,100); and onward, the LED stays on for twice as long and there is no delay as 4,5,6,and 7 light up. It's as if the pin is high for the delay as well. Thanks so much for your time.

Interesting, We're obviously missing something.

With the blinkIt command, is that a built in function of the library?   ;-}

No, it's a product of my own sloth. I'm too lazy and sloppy to write all that code and besides, it's so bulky that it's almost impossible to go through and debug it. Collecting common code which only requires a few parameters is a common technique in programming.

You can see the effect because after conversion, much of your code will fit on the same page/screen.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2527
 

@davy-ps 

I can't find any reason for the weirdness in delay, but there is an alternative to try out.

It looks like the FastLED class has a 'built-in' method called delay. So maybe try changing both of the delay commands in blinkIt to FastLED.delay and see if that works.

Also, unless you're using them, get rid of the extra code at the top of the loop() 

for (int i = 0; i < NUM_LEDS; ++i) {
leds[i] = CHSV(hue + (i * 10), 255, 255);
}

//You can change the pattern speed here
EVERY_N_MILLISECONDS(300){
hue++;
}

These may be using interrupts.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2527
 
Posted by: @davy-ps

Hi Will,

          I am after the effect shown in this YouTube video at mark 3.20 to 3.22. Where the LEDS illuminate at each end and move toward each other and continue past each other. Single colour is OK.

Try this as a simple solution to the original request ... (compiled but not tested)

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Davy PS
(@davy-ps)
Member
Joined: 2 years ago
Posts: 74
Topic starter  

@will Mate, The Davy 4 version runs fantastically.  Thanks again.

 

Davy


   
ReplyQuote
Page 1 / 11