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 - Star ...
 
Share:
Notifications
Clear all

[Solved] LED Effects - Star Trek Phaser Array

223 Posts
14 Users
33 Likes
82.7 K Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2691
Topic starter  

Hi Trace,

no worries - I'm just glad you managed to figure out what went wrong. A good lesson for all of us 😁 

As for Brightness control, well ... you have the FastLED.setBrightness() function, which would affect overall brightness - but I think you're already familiar with that one.

For the effect, I was thinking of having the initial color a little less bright than the flash - but even the flash color can be set to whatever you like.
I hope I understood your question 😉 

So the general idea:

1. Set a base color (which could be black of course)
2. When button pressed: call the StarTrekWarp function (with initialColor = the color used in step 1).

I realize I went a little overboard with the parameters - I just wanted the function to be as flexible as possible 😊 

So we'd be looking at something like this (untested, so this could look good or bad haha):

void loop() 
{
fill_solid( leds, NUM_LEDS, CRGB::Black );
FastLED.show();
StarTrekWarp(CRGB(0,0,0), 0, true, 10, 10, // Initial color = black, no hold fade to inital color CRGB(50,50,50), 20, 40, // bright to fade to, with stepsize and stepdelay CRGB(255,255,255), 500, false, 0, // flash color, flash duration, before/after black and black durationr 30, 100, // fade back to previous color stepsize and delay, true, true, 1000); // end with black, fade to black, how long to wait before going to black delay(10000); }

   
ReplyQuote
(@trace)
Estimable Member
Joined: 4 years ago
Posts: 170
 

Hi Hans,

you are such a big help and one special kind of programmer. Your way of explaining things makes me able to figure out what´s going on.

I think my explanation of the wanted effect was a bit confusing. And now after I understood the initial code, I am happy about your "overboardness" of parameters, because it is highly customisable. So even without testing your last code adjustment, I was able to get (mostly) the effect I want.

But there is still a "problem". When tweaking the stepsize and stepdelay paramters for brightcolor, of course it "influences" the time before flash. So "bright fade to - stepdelay" devided by "bright fade to - stepsize" gives us the time needed for fading.

100/10 = 10 seconds. 5 seconds for fading and another 5 seconds having the color stay on before flash.

For example, this gives a smooth fade of 5 seconds but badly another 5 seconds after fade before flash:

This also makes "fade to" and "fade back to" look different, even with same settings.

 

void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop()
{
StarTrekWarp(CRGB(0, 50, 50), 0, false, 0, 0, // Initial start color and hold time, fade to inital color with stepsize and stepdealy
CRGB(0, 255, 255), 10, 100, // bright to fade to, with stepsize and stepdelay
CRGB(200, 255, 255), 100, false, 0, // flash color, flash duration, before/after black and black durationr
30, 100, // fade back to previous color stepsize and delay,
false, false, 0); // end with black, fade to black, how long to wait before going to black

delay(5000);
}

 

Is there a possibilty to have the flash right after fading?


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

Thanks Trace 😊  - I just enjoy helping other, so you're most welcome.

I think I need another coffee though, trying to understand what you're saying (apologies for that).

The 100/10 is maybe not how that works.
A fade has indeed 2 parameters: stepsize and stepdelay. Lets assume these values are 10 for stepsize and 100 for step delay.
So let's assume we have black as our starting color and we want to go to white. This means that we have to go from 0 to 255.
With a steps zie of 10 this takes 25 or 26 steps. Each step will have a delay, so the total time it takes would be:

Number of steps  X  step delay per step  =  25  X  100ms = 2500 ms = 2,5 seconds.

Note: this may not be 100% accurate to say it will be 25 steps, but I think you got the general idea.

Now coming back to the "end" fade out effect with the Flash: you can tweak the code if you'd like to fit your needs.
I just wrote to code to give you a good starting point, since I wasn't 100% sure what effect you'd prefer.

For example:

void warpFlash(CRGB flashColor, bool blackInBetween, int blackDelay, int flashDuration, bool InstantFlash, int fadeStepsize, int fadeDelay)
{
  // FLASH
  // temporary black if blackInBetween=true
  if(blackInBetween) {
    fill_solid( leds, NUM_LEDS, CRGB::Black ); 
    FastLED.show();
    delay(blackDelay);
  }

  // Flash color either instant or with fade
  if(InstantFlash)
  {
    fill_solid( leds, NUM_LEDS, flashColor ); 
    FastLED.show();
    delay(flashDuration);
  }
  else
  {
    CRGB tmpColor = leds[0];     // copy current color
    CRGB previousColor = leds[0];
    
    tmpColor = fadeToColor( tmpColor, flashColor,    fadeStepsize, fadeDelay);    // fade to flash color
    tmpColor = fadeToColor( tmpColor, previousColor, fadeStepsize, fadeDelay); // fade back to start color
  }
  
  // temporary black if blackInBetween=true
  if(blackInBetween) {
    fill_solid( leds, NUM_LEDS, CRGB::Black ); 
    FastLED.show();
    delay(blackDelay);
  }  
}

The bold and red line is where the code fades back to "previousColor".
If you wanted to have the fade out to go faster, you could replace it with something like this:

 tmpColor = fadeToColor( tmpColor, previousColor, fadeStepsize/2, fadeDelay); // fade back to start color

or

 tmpColor = fadeToColor( tmpColor, previousColor, fadeStepsize, fadeDelay/2); // fade back to start color

I'm just dividing stepsize or stepdelay through 2 (arbitrary number) - you can change the number 2 with something more suitable, or even apply it to both parameters.

This would probably a good approach for testing to see what you like best.

 

Note: If you'd want to make that variable, by passing stepsize and stepdelay for fadeout, then you could do that as well.

void warpFlash(CRGB flashColor, bool blackInBetween, int blackDelay, int flashDuration, bool InstantFlash, int fadeStepsize, int fadeDelay, int fadeOutStepSize, int fadeOutdelay)
{
  // FLASH
  // temporary black if blackInBetween=true
  if(blackInBetween) {
    fill_solid( leds, NUM_LEDS, CRGB::Black ); 
    FastLED.show();
    delay(blackDelay);
  }

  // Flash color either instant or with fade
  if(InstantFlash)
  {
    fill_solid( leds, NUM_LEDS, flashColor ); 
    FastLED.show();
    delay(flashDuration);
  }
  else
  {
    CRGB tmpColor = leds[0];     // copy current color
    CRGB previousColor = leds[0];
    
    tmpColor = fadeToColor( tmpColor, flashColor,    fadeStepsize, fadeDelay);    // fade to flash color
    tmpColor = fadeToColor( tmpColor, previousColor, fadeOutStepSize, fadeOutdelay); // fade back to start color
  }
  
  // temporary black if blackInBetween=true
  if(blackInBetween) {
    fill_solid( leds, NUM_LEDS, CRGB::Black ); 
    FastLED.show();
    delay(blackDelay);
  }  
}

Your call to the function would of course change then as well:

  // *** Step 3 - flash
  warpFlash(flashColor, blackbetweenFlash, prepostFlashDelay, flashDuration, false, 20, 5, 10, 1);

Which then comes with the question if we'd want to do this for the StarTrekWarp function as well.
Now you see how I got to go overboard hahaha.

 

I hope this answers your question - again, I just got up and am enjoying my first coffee 😁 


   
ReplyQuote
(@trace)
Estimable Member
Joined: 4 years ago
Posts: 170
 

Hi Hans, I hope your Coffee tastes good ;)

It is always hard to understand the language of a beginner when you are far more advanced. So I will try to make it more clear.

I should have looked up the stepsize and stepdelay thing and I would have noticed my calculation and understanding of it was wrong. Thanks for your explanation.

First things first, everything after the flash is fine. But it´s good to know how to change the stepsize and stepdelay numbers and make it variable.

I have a problem with the timing between fading to and right before the flash. As you will see in the Video, it fades from and to a specific color (in this case from 0,0,0 to 0,255,255), then stays on for a moment and then flashes.

But what I want is, fading from and to a specific color and immediately after the fade color is reached (0,255,255), I want the flash.

To stay with your example, I start with black color (0,0,0) and want to fade to 0,255,255 (white with RGB looks terrible :D ). Stepsize is 10 and stepdelay is 100. So the fading takes indeed about 2,5 seconds. Two things to be noticed in the video.

The first thing, it takes 2,5 seconds for fading but then it stays on 0,255,255 for 5 seconds (2 times it took for fading).

I have tested different timings and it always stays on 2 times it took for fading.

To repeat myself, I want the flash right after fade, without having the fade color staying on.

The second thing to mention, it doesn´t fade from off to full brightness with continues steps. As you can see in the video, it is off and jumps straight to a much brighter color from which it then fades to full brightness. The weird thing: the fade back to funktion doesn´t jump. it slowly fades to off.

Oh dear.....I can´t upload the video (24MB) it loads up and then says "Error Request Timeout". But I hope I have made clear what the problem is.


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

Haha, thank you for the compliment, but I wouldn't call myself more advanced 😊 

I've played a little with the values you're using. Can you tell me if this is getting closer to what you had in mind?

We have to keep in mind that with each fade step, the color value increases by stepsize, and right after a step it inserts a brief delay.

So smaller stepsize = slower fade, and especially with LEDs, the last couple hundred steps will be hard to see.
For example (50,50,50) is much brighter than half the brightness of (100,100,100).

A smaller delay also helps making the fade faster.

 StarTrekWarp(CRGB(0, 50, 50), 0, false, 0, 0, // Initial start color and hold time, fade to inital color with stepsize and stepdealy
CRGB(0, 255, 255), 30, 50, // bright to fade to, with stepsize and stepdelay
CRGB(200, 255, 255), 100, false, 0, // flash color, flash duration, before/after black and black durationr
30, 100, // fade back to previous color stepsize and delay,
false, false, 0); // end with black, fade to black, how long to wait before going to black

To give you a good comparison:

 StarTrekWarp(CRGB(0, 50, 50), 0, false, 0, 0, // Initial start color and hold time, fade to inital color with stepsize and stepdealy
CRGB(0, 255, 255), 1, 0, // bright to fade to, with stepsize and stepdelay
CRGB(200, 255, 255), 100, false, 0, // flash color, flash duration, before/after black and black durationr
30, 100, // fade back to previous color stepsize and delay,
false, false, 0); // end with black, fade to black, how long to wait before going to black

In the first example, we take bigger steps, so we reach the desired color pretty quick. The delay is bigger as well, so the fader would not go too fast.

In the second example we take very small steps but we have a delay of zero. So the fade will be more gradual.

Give it a try and see which direction you'd like to go.


   
ReplyQuote
(@trace)
Estimable Member
Joined: 4 years ago
Posts: 170
 

So the "effect" of having the fade color staying on is just a visual illusion because the human eye isn´t capable of seeing the difference between brightness values of the last hundred steps?

But why does it take about 7,5 seconds for the effect before flashing, when stepsize and stepdelay is set to 10 and 100 and it should only take 2,5 seconds?

Or do I miss something?

Thanks to your last comment about bigger steps and lower delays, I was able to got some timings I can play with.  This is my setting for now:


StarTrekWarp(CRGB(0, 6, 6), 0, false, 0, 0, // Initial start color and hold time, fade to inital color with stepsize and stepdealy
CRGB(0, 60, 60), 1, 60, // bright to fade to, with stepsize and stepdelay
CRGB(0, 255, 255), 100, false, 0, // flash color, flash duration, before/after black and black durationr
2, 40, // fade back to previous color stepsize and delay,
false, false, 0); // end with black, fade to black, how long to wait before going to black


I try to upload a video again. But it still would be great to figure out why the 10 and 100 timing (with 0,0,0 to 0,255,255) takes 7,5 seconds before flash instead of 2,5?!

 

Can I donate somehow?


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

Indeed; the LEDs have a nasty little "habit" of having 2 (if I'm right) ranges where the color difference per step is hard to detect with the human eye.
As far as I know: the darkest range and the brightest ranges make it difficult to see a difference.
You could try this yourself with a simple loop, something like this:

for(i=0;i<256;i++) {
fill_solid( leds, NUM_LEDS, CRGB(i, i, i) ); FastLED.show(); delay(500);
}

You'll also notice that brightness does not go linear.

The longer delay may also be related to using the scale8_video function - the functions "fadeTowardColor" and "nblendU8TowardU8" were borrowed from  Kriegsman's GitHub example.
So there may be something in there that is not helpful.

Another point that could be contributing to this is that one of the colors (red, green, blue) takes more time to catch up to get to the desired value - but I'd expect this to be visible in such a case.

It's quite a puzzle 😊 

The video looks good though! Although I'd probably make the flash duration a tiny bit longer to better match up with the sound.
Looks cool though!


   
ReplyQuote
(@trace)
Estimable Member
Joined: 4 years ago
Posts: 170
 

Yeah I´ve already read about LED´s and their non liniar behavior. But it still makes me wonder to see the "fade out" effect with a nice smooth fading from bright do dark while the "fade to" effect is somehow jumping.

The soundfile was just a quick test. But yeah, I will make some changes here and there to match lighting and sound better.

Too bad to have a weird timing effect with Kriegsman´s Code. Would have been great to set a value and know the timings to be able to match sound much better and easier. Like it is now, the timing really depends on from where the initial color starts and to which color it shall fade and which stepsize and stepdelay is set. So it is a bit trial and error with settings. But Im sure I can figure it out.

Yesterday I have just realised that this effect can also be used as a really nice Photon Torpedo. As you can see here for a Klingon Bird of Prey TNG (sound volume is a bit low):

The next step for me is to combine the effects with one LED strip for your Warp-effect, one for your Phaser and one single WS2811 for yourTorpedo. So 3 outputs, 3 soundfiles, 3 buttons and all together in one code. And maybe some movie soundfiles on other buttons (TNG theme or so).

If the code can handle it then, I will try to implement standard light effects too, like flashing nav-lights. Or would it be easier to use more than one Arduino?


   
jackmtaco reacted
ReplyQuote
(@jackmtaco)
Eminent Member
Joined: 3 years ago
Posts: 22
 

Oh my gosh! I just want to say thank you so much from providing this coding and help. I'm working on the exact same effects for my Star Trek Voyager Model and was having an awful time trying to figure out how to code it. I may start another thread as I am using an Adafruit Music Maker shield on my board to produce the sound effects to coordinate with the lighting effects. 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2691
Topic starter  
Posted by: @trace

Too bad to have a weird timing effect with Kriegsman´s Code. Would have been great to set a value and know the timings to be able to match sound much better and easier. Like it is now, the timing really depends on from where the initial color starts and to which color it shall fade and which stepsize and stepdelay is set. So it is a bit trial and error with settings. But Im sure I can figure it out.

Yesterday I have just realised that this effect can also be used as a really nice Photon Torpedo. As you can see here for a Klingon Bird of Prey TNG (sound volume is a bit low):

If we'd want to make it fit an exact time, then I'm afraid we'd still be hoping for the best timing, since speed can be different per LED strip, and per Arduino (although we'd be able to get pretty close). It would also have implications with the code, so for now we're stuck with trial and error.

Oh I love that Klingon effect - wow, really nice, especially with the frosted material in front of it. Nice!! 😊 

Posted by: @jackmtaco

I may start another thread as I am using an Adafruit Music Maker shield on my board to produce the sound effects to coordinate with the lighting effects. 

Awesome to see that others enjoy the work Trace and I have done!
As for the Adafruit Music Maker shield (I had to Google it): I do not have this shield, and I'm not sure if Trace has one either.
I would however guess that controlling it may not be that difficult, the pinout however will be quite different. I also see that it supports more formats maybe than the board Trace is using.


   
jackmtaco reacted
ReplyQuote
(@jackmtaco)
Eminent Member
Joined: 3 years ago
Posts: 22
 

@hans

This is exactly what I am going to do with mine for the phaser. So I'll will probably be asking for some help with the coding aspect of turning on the laser for the actual phaser when the WS2812 LED's finish with the "aim" effect.


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

Funny to see you bought the exact same lasers I did last week 😊 

Two potential problems with the laser though:

  1. The phaser gets fired at a particular point in the "circle" - not sure how we could get the laser in the exact right position. Maybe a stepper motor will do the trick?
  2. Trace and I talked about a laser before; the visibility of the "beam" will be tricky to make visible to viewers. You may need some kind of smoke.

   
jackmtaco reacted
ReplyQuote
(@jackmtaco)
Eminent Member
Joined: 3 years ago
Posts: 22
 

@hans

 

I have been studying the code and I believe you have the phaser set for randomizing correct? If so, can we modify it to stop in one spot instead? If we can, then what I could do is stick the laser in between the LED strips and turn it on when the phaser firing comes to that particular point. I don't want the laser to move around, i would just like the effect to have the leds chase down to a point and then turn the laser on for the firing. (although I have some micro stepper motors that I thought about incorporating into moving the laser (phaser) around like it does in the show but that would just require more coding and also figuring out a way to fit that in the model)

Regarding being able to see the laser beam itself, I plan to have a vapor machine built into the model baser stand to create a slight mist so that the lasers will be visible and also mimic the effect of an actually phaser firing. 

**Could you show me how you embedded the picture in the post? I tried a few times and couldn't figure it out cause it kept missing the last 4 characters of the link from dropbox. 


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

Hi Jack,

I had to dig through some posts as well, to even find the sketch.
You'll see that I have written the code to already accomodate a fixed position for the laser.

void startrek_phaser(byte PhaserRed, byte PhaserGreen, byte PhaserBlue, int TargetLED,
                     byte PhaserWidth, byte ShootingWidth, int msAimDelay, 
                     int PulsateAmount, int msPulsateDelayBright, int msPulsateDelayDarker) 
{

...

}

The parameter "TargetLED" should be set to the LED you'd like to use.
If this is set to "-1" then a random position is used (which is what Trace uses).

Easy fix 😁 

A vapor machine would indeed do the trick to make the laser visible.
Man now I'm curious how well this works, but I do not have a vapor machine available hahah.

As for posting pictures: this will eventually open up for you.
The forum will not allow posting attachments (like pictures) for the first 5 (I believe) posts for new users. This to avoid that spammers pretend to be regular users and then suddenly start posting inappropriate pictures or documents. However, for new users, when I see (like in your previous post) that a picture or video is linked to another site/service, then I usually download it and place it for the user.

Thanks again for the donation! ☕ 👍 


   
jackmtaco reacted
ReplyQuote
(@jackmtaco)
Eminent Member
Joined: 3 years ago
Posts: 22
 

@hans  Awesome! Thank you for the quick response regarding setting the target LED. 

As for the vapor machine, I took apart an Essential Oil diffuser and will use that to mount into the base to create a misting effect for the laser to be visible. 

One of these 


   
ReplyQuote
Page 8 / 15
Share: