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 Reactions
95.3 K Views
(@jackmtaco)
Eminent Member
Joined: 4 years ago
Posts: 22
 

@trace Thank you so much trace. I totally forgot the breakdown post explaining the parameters. This helped me significantly with the fine tuning of how the phaser needs to look. I'm trying to get all the electronic portions done before starting work back on the model again. I've drilled out all my windows but I'm waiting to start doing the interior lighting till I'm sure we can get all the LED's, Sounds and timing done before pressing forward. Do you have a code you could share for your nav lights? I've tried a few so far but timing wise or the actual look doesn't feel right. (I've borrowed them from people who used ardinos for their RC planes.) 


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

@Trace

First of all, thanks for chiming in! It is really cool to see how you guys are building these awesome Star Trek models 😁 

Combining effects can indeed be a challenge. The Arduino (with FastLED) can control multiple LED strips, however the Arduino is not so great at doing multitasking - at best you can do task switching, but this comes with some challenges. So if the used effects do not take place at the same time; this can be done with one Arduino.

However when you'd like to use multiple effects at the same time, then I'd consider using multiple LED strips and multiple Arduino's. Considering price, speed, memory size and board size, I'd actually look for some ESP8266's. For example these at Amazon.de - 3 for €14.

The ESP8266, I'm not sure if I had already mentioned this, can be used as an Arduino replacement - see also this example introduction.

If you decide to use one Arduino though, then you'd need to come up with a mechanism where when one effect runs, it checks if other effects are running, and execute each effect one step at a time. Right now I'm trying to finish a project where I use a much faster ESP8266, just to catch a button press (web-based), and that is already a pain. Catching a web-based button press is not nearly as complicated as running multiple effects.
Not to mention: since it involves task switching, your effect timing will have to be shared with the running effects, resulting in slower effects. Not sure if that is desirable.

Note: Multiple ESP8266's and LED strips can share the same power supply 😊 


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

@hans

Stupid question but I have a ton of Raspberry Pi's sitting around along with some Arduino Nano's. Is it possible to use the Pi to run the Arduino's together if I wanted to go with doing more complex tasks or is that just going over kill? 

This post was modified 4 years ago by jackmtaco

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

@jackmtaco

That would certainly be possible, not sure if it would make a project easier though.

One thing to keep in mind with Raspberry Pi's is that the OS you're running on it, is not intended for realtime processes. This doesn't mean you'd run into issue though - just anything depending on timing may or may not cause issues. If the Arduino's only need to be triggered to run an effect on an Arduino, then I don't think this will be an issue.

Thinking about it some more, I suspect you'd make your project more complicated than needed. Unless you're looking for something like using Bluetooth to control multiple Arduino's.

Note: my experience with this kind of an approach is pretty much zero.


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

@hans I kinda figured that. I'm good for the single effect at a time approach as I don't plan to try and complicate my model as it is already getting complicated the way it is (Almost thinking about abandoning it with it's complexity but I'm holding out hope). The only addressable LED's I plan to use is for the Phaser and Warp effect. Everything else lighting wise will be done with standard LED'S for the blinking NAV's, RED Alert and Photon Torpedo's (I don't plan to use WS2812 for the torpedo's).

The only other thing I'm gonna try and figure out is lifting the warp nacelles with a servo for warp prior to the warp effect kicking in with the lights. 

Is there a tutorial anywhere for combining all the code's written so far into a working single sketch? 

I still need to figure out the Adafruit Music Maker coding. Was looking over it last night and it just seems like a lot is involved with coding it. The only benefit is that Music Maker has 7 GPIO outputs on it to use for trigger effects (Guessing that makes it easier for writing code for using buttons to trigger effects)

There's one more thing I will be using WS2812s for but I'm holding out saying what it's for till I know we can get the rest of the effects going. Pretty sure @Trace will love it once I explain what it's for. 

 

 

This post was modified 4 years ago 3 times by jackmtaco

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

@jackmtaco

Thanks again for the another cup of coffee 😁  ☕ 

Don't give up just yet 😊

If you're not running the effects at the same time, then it should be very doable to combine the effects into one sketch.
With FastLED (I'll admit that I have never tried this), you can even hookup multiple LED strips.

This should work something like this:

#define NUM_LEDS_STRIP1 60  // assuming strip 1 has 60 LEDs
#define NUM_LEDS_STRIP2 20 // assuming strip 3 has 20 LEDs

...

#define STRIP1_PIN 6 // strip 1 connected to pin 6
#define STRIP2_PIN 7 // strip 1 connected to pin 7

...

CRGB ledstrip1[NUM_LEDS_STRIP1]; // define ledstrip1 instead of "leds"
CRGB ledstrip2[NUM_LEDS_STRIP2]; // define ledstrip2 instead of "leds"

...

void setup() {
// Create leds array for strip 1 (now called "ledstrip1" instead of "leds")
FastLED.addLeds< WS2811, STRIP1_PIN, GRB >(ledstrip1, NUM_LEDS_STRIP1).setCorrection( TypicalLEDStrip );
// Create leds array for strip 2 (now called "ledstrip2" instead of "leds")
FastLED.addLeds< WS2811, STRIP2_PIN, GRB >(ledstrip2, NUM_LEDS_STRIP2).setCorrection( TypicalLEDStrip );
...
}

...

// example from one of the effects, calling strip 1:
// was: leds[LEDPos+PhaserBlock].fadeLightBy( DimmingPhaserAim );
  ledstrip1[LEDPos+PhaserBlock].fadeLightBy( DimmingPhaserAim );

// example from one of the effects, calling strip 2:
// was: leds[LEDPos+PhaserBlock].fadeLightBy( DimmingPhaserAim );
  ledstrip2[LEDPos+PhaserBlock].fadeLightBy( DimmingPhaserAim );

...

So this would mean that you'd have to replace "leds" with "ledstrip1" and "NUM_LEDS" with "NUM_LEDS_STRIP1" for the effect that is supposed to run on the first strip.

This would also mean that you'd have to replace "leds" with "ledstrip2" and "NUM_LEDS" with "NUM_LEDS_STRIP2" for the effect that is supposed to run on the second strip.

Having done that, you can merge the functions of one sketch into the other.
If you could post your 2 effects, then I'll try to merge them for you - would be good to know the number or strips and the number of LEDs per strip.
Each strip has its own pin.

The basic steps to merge 2 sketches is to see first what they have in common (eg. led definitions and such), and what they do not have in common. Like I said: I can combine them for you if you'd like, and I can add an explanation with it as well.

As for selecting the effect, we could introduce 2 buttons, and in the loop check if one of the buttons is pressed or not.
Note: with this approach pressing another button will not be detected until the running effect is done. We can add an interrupt to catch that, if needed.

As for the AdaFruit Music Maker:
I have no experience with that one, and it looks (I could be wrong) a little more complicated than the DFPlayer Trace uses. I wouldn't mind looking at that with you (maybe start a separate topic for that one though).


   
jackmtaco reacted
ReplyQuote
(@trace)
Estimable Member
Joined: 5 years ago
Posts: 170
 
Posted by: @jackmtaco

@trace Thank you so much trace. I totally forgot the breakdown post explaining the parameters. This helped me significantly with the fine tuning of how the phaser needs to look. I'm trying to get all the electronic portions done before starting work back on the model again. I've drilled out all my windows but I'm waiting to start doing the interior lighting till I'm sure we can get all the LED's, Sounds and timing done before pressing forward. Do you have a code you could share for your nav lights? I've tried a few so far but timing wise or the actual look doesn't feel right. (I've borrowed them from people who used ardinos for their RC planes.) 

Indeed I have a code for blinking and no additional library is needed.

As an example, I have written 3 LED NavLight effects. The first one is a slow blinking light, second one is a slow flash (flash with pause) and the third one is a double flash. You can write your own timings to match on and off timings as you like. And you can also just add more LEDs. If you need help to undestand the code and how you change it or add LEDs, just let me know.

 

Here is the file:

 

 

And here is the code:


// Star Trek Navigation Lights blinking by TraceBerlin
// based on "LEDs schalten" by Jurs in Arduino-Forum Germany
//
// LED: Pin-Number of LED
// whole= whole length of all timings in line (add together all on-off timings)
// n= Number of on/off timings in line (add together how many times off and on happens)

// LED whole n off on off on off
int slowblink_timing[]= { 3, 3000, 2, 1000, 2000, 0, 0, 0};
int slowflash_timing[]= { 4, 1700, 3, 0, 100, 1500, 0, 0};
int doubleflash_timing[]= { 5, 1600, 5, 200, 100, 200, 100, 1000};

void setup() {
// put your setup code here, to run once:
// define OUTPUT pins
pinMode(slowblink_timing[0], OUTPUT);
pinMode(slowflash_timing[0], OUTPUT);
pinMode(doubleflash_timing[0], OUTPUT);

}


void NavBlink(int* Navdata)
{
// Start with blink lights on? true or false (false in this case, cause we start with LEDs off)
boolean blinkStatusOn=false;

long inCycleTime=millis() % Navdata[1];
int onoffCount=Navdata[2];
while (onoffCount>0 && inCycleTime-Navdata[3+Navdata[2]-onoffCount]>=0)
{
inCycleTime-=Navdata[3+Navdata[2]-onoffCount];
onoffCount--;
blinkStatusOn=!blinkStatusOn;
}
digitalWrite(Navdata[0], blinkStatusOn);
}

void loop() {
NavBlink(slowblink_timing);
NavBlink(slowflash_timing);
NavBlink(doubleflash_timing);

}

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

 

So this is the code I have come up with for the Navigation lights for Voyager.  (I apologize as I am getting really frustrated with figuring everything out as this took me 5hrs to do for something as simple as flashing a light) I still don't even know how I am going to apply this for use with the TLC5947 LED driver and also incorporate the music maker into this while also having the light effects from the addressable LED's. (This is starting to go way beyond my capabilities and I may just pay someone to do the coding for me) 

I think I'm just going to do nav lights only and give up... I can't even copy code into this forum correctly. I apologize if it seems I've wasted all your time with this. 

This post was modified 4 years ago by jackmtaco

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

@hans

As I can only speak for myself. I don´t need to run several effects at once. So if I press a button, I will have the phaser effect. Then I wait till the effect stops and press another button for the warp effect....again waiting till it ends and pressing another button for the torpedo effect. It would be nice to also have the NavBlinking effect (posted right before) in the Code and having it running all the time, but maybe I will use a second arduino (or Digispark) for this....otherwise I think it will overcomplicate the sketch.

And maybe some other buttons to play specific files on the DFPlayer mini. But I think I can implement that by myself.

To have our three effects with multiple WS2811 strips in one code would be great, becaue otherwise I would need an Arduino and DFPlayer for every strip. That would be too much.

Here are all three sketches. Please note that I didn´t change Data Pins and button Pins. So you can change them as needed. I also have already implemented the DFPlayer mini functions for sound. Hopefully that doesn´t make it too complicated for you. If so, just delete it and I will try to put it in afterwards. For the amount of LEDs each strip, I plan to have about 60 LEDs for the Warp effect. 2 times 8 LEDs for the warp (as mentioned before I will use two 8 LED strips on one data pin, because the effect is for left and right at the same time) and 1 LED for the Torpedo effect. All WS2811.


   
jackmtaco reacted
ReplyQuote
(@trace)
Estimable Member
Joined: 5 years ago
Posts: 170
 

@jackmtaco

Not long ago, I was at the same point as you. And I still can´t coding. But I can change existing codes for my needs...as long as I understand the code. Maybe you start a bit too far in the future. As Hans said, using Rasperry Pi is too much, also using the driver and the soundboard seems to be more complicated than needed. And that makes it even harder to understand what happens in the Code.

So maybe you just start with a single Arduino. Search for "DFPlayer mini" and buy one. So you can just copy and paste the codes. Also a wiring plan would be usefull and I think I can make one some other day. Get rid of the LED driver and try to manage all cables to fit inside the model and stand. It always worked for me.

If you give up, you will never reach your desired goal and you will never get to the point where you can say "oh yeah, I know how that works" (im far from it yet).

And you didn´t waste time. Because helping others makes me understanding my own stuff more and more and extend my capabilities. Also it is input for other ideas. And im curios about your use of adressable LEDs.

Do you have a Code for a torpedo effect with standard LEDs? If not, I have one. Just let me know.

Oh and your blinking Code is the basic of undestanding Arduino, but it wouldn´t work for more than just a single LED blinking, because of the "delay" function. It really delays the whole code. So while delay is active, Arduino can´t do anything else (easy spoken).

Maybe you already have seen my Blinking Code already.


   
jackmtaco reacted
ReplyQuote
(@jackmtaco)
Eminent Member
Joined: 4 years ago
Posts: 22
 
Posted by: @trace

@jackmtaco

Not long ago, I was at the same point as you. And I still can´t coding. But I can change existing codes for my needs...as long as I understand the code. Maybe you start a bit too far in the future. As Hans said, using Rasperry Pi is too much, also using the driver and the soundboard seems to be more complicated than needed. And that makes it even harder to understand what happens in the Code.

So maybe you just start with a single Arduino. Search for "DFPlayer mini" and buy one. So you can just copy and paste the codes. Also a wiring plan would be usefull and I think I can make one some other day. Get rid of the LED driver and try to manage all cables to fit inside the model and stand. It always worked for me.

If you give up, you will never reach your desired goal and you will never get to the point where you can say "oh yeah, I know how that works" (im far from it yet).

And you didn´t waste time. Because helping others makes me understanding my own stuff more and more and extend my capabilities. Also it is input for other ideas. And im curios about your use of adressable LEDs.

Do you have a Code for a torpedo effect with standard LEDs? If not, I have one. Just let me know.

Oh and your blinking Code is the basic of undestanding Arduino, but it wouldn´t work for more than just a single LED blinking, because of the "delay" function. It really delays the whole code. So while delay is active, Arduino can´t do anything else (easy spoken).

Maybe you already have seen my Blinking Code already.

You're right, I just need to have some patience with building this. The model is sitting apart and it's just 1 delay after another and I'm feeling rushed to want to have this together in working condition. I bought the DFmini player and I should have it tomorrow. 

I haven't coded anything for the torpedo effect so I may just go with using an addressable LED for them and "borrow" your code for it. 

In the end, I think you're right, I need to make it simple instead of trying to use additional devices to create the same effect. I'll just end up having to make the shaft that holds the model wider to accommodate the extra wiring (That was the reason to use the LED Driver separate so that it would only need a few wires to the model instead of all the wires from the Arduino running in it. )


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

@jackmtaco

Glad to read you will keep on track. So if you use addressable LEDs you can take a look at the Torpedo sketch in my last post (it is the same as the Warp sketch, just different timings). As Hans said, he will try to merge all together.

I can also upload the sound effects later this week, cause they are custom made by myself by using existing sounds and Audacity.

@hans

Please don´t feel forced to do all at once. Take your time and take a rest. ;)


   
jackmtaco reacted
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  
Posted by: @jackmtaco

I can't even copy code into this forum correctly

The forum has two oddities when pasting code;

  1. It removes double space, so indentation becomes a mess
  2. When < or > appears in the code, without a space in front of it, it may see this as the beginning of a HTML tag and somehow ruins it.

It is indeed not ideal, and I haven't found a fix for it.

What I do myself, which is not perfect either, is by adding the code in the HTML editor of the forum.
The button for this is the button just before the smiley (showing: " {;} "). I just made it visible again (I did hide it to avoid people posting malicious code). If the button doesn't show, then clear your browser cache so it loads the modified CSS.

In HTML this would be something like:

<pre>
// you Arduino code here
</pre>

But, I can see this to be cumbersome, and point (2) is something to pay attention to  (which I screw up almost every single tim).

Posted by: @jackmtaco

I apologize if it seems I've wasted all your time with this.

Don't worry - you're not 😉 
I can't speak for Trace, but I'm sure he's happy to help a fellow Star Trek fan, just like me.

Posted by: @jackmtaco

I still don't even know how I am going to apply this for use with the TLC5947 LED driver and also incorporate the music maker

Don't give up just yet ... I think key here is to start with small pieces, and make sure things remain as simple as possible. For example the TLC5947 may make things over complicated, especially when just starting with Arduino projects. I don't even know what to do with it, unless someone hands me a complete sketch so I can try to understand it or even use it. I'd need to do some reading up on it as well. 😊 

@jackmtaco and @Trace

Since I try to help out with other projects as well, I do every now and then lose details of a project.
Maybe we should make a list of effects (light and sound) you guys are looking for.
Then per item come up with final code.
And finally merge them into one sketch, possible one sketch accommodating both your projects 😊 

What do you think?


   
jackmtaco reacted
ReplyQuote
(@trace)
Estimable Member
Joined: 5 years ago
Posts: 170
 

@hans

Posted by: @hans

Since I try to help out with other projects as well, I do every now and then lose details of a project.
Maybe we should make a list of effects (light and sound) you guys are looking for.
Then per item come up with final code.
And finally merge them into one sketch, possible one sketch accommodating both your projects 

What do you think?

Sounds like a plan. Did you read this post? :

Posted by: @trace

As I can only speak for myself. I don´t need to run several effects at once. So if I press a button, I will have the phaser effect. Then I wait till the effect stops and press another button for the warp effect....again waiting till it ends and pressing another button for the torpedo effect. It would be nice to also have the NavBlinking effect (posted right before) in the Code and having it running all the time, but maybe I will use a second arduino (or Digispark) for this....otherwise I think it will overcomplicate the sketch.

And maybe some other buttons to play specific files on the DFPlayer mini. But I think I can implement that by myself.

To have our three effects with multiple WS2811 strips in one code would be great, becaue otherwise I would need an Arduino and DFPlayer for every strip. That would be too much.

Here are all three sketches. Please note that I didn´t change Data Pins and button Pins. So you can change them as needed. I also have already implemented the DFPlayer mini functions for sound. Hopefully that doesn´t make it too complicated for you. If so, just delete it and I will try to put it in afterwards. For the amount of LEDs each strip, I plan to have about 60 LEDs for the Warp effect. 2 times 8 LEDs for the warp (as mentioned before I will use two 8 LED strips on one data pin, because the effect is for left and right at the same time) and 1 LED for the Torpedo effect. All WS2811.

I have put all 3 sketches in there. Those are the effects we figured out together. So it´s the Phaser, Warp and Torpedo effect. Sound function and effect triggering with a button is already in the code. So there is a sound when pressing a button, and sound when the effect is running.

As wrote before, it will be one button for each effect (so 3 buttons). An additional thing would be navigation lights. So just simple LEDs where you can change on and off time to have different blinking rates or even flashes. An adjustable double flash function would be nice too.

Maybe you can somehow use my last sketch for this (StarTrek_NavBlink).

Another thing would be to have sound as a background music, like a Star Trek theme. I think it is much easier to use an extra DFPlayer just for the background music. So there is no need to implement this in the effect sketch.

Why using an extra DFPLayer? Well the DFPlayer can´t play different soundfiles at the same time. So if we use just one DFPLayer and letting it play a Star Trek theme, the music stops when pressing a effect button and plays the effect soundfile.

But if we use an additional DFPlayer we can just use the "stand alone - MP3" function of it with just two buttons. One button for previous soundfile and lowering volume when holding the button and another button for next soundfile and rising volume when holding the button. And because it is "stand alone" we don´t have to code anything or even hooking it up to Arduino.

Nice thing about this configuration, we can have some background music while triggering our effects which also have sound.

If something isn´t clear enough, just ask (im sure there will be alot of questions hahaha)


   
Hans reacted
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  
Posted by: @trace

Did you read this post?

Yes I did, but obviously not careful enough. Thanks for posting - that saves a lot of work 😊 
Reading this again, I'm not 100% sure if these were the only effects we are looking for - didn't we have 2 torpedo/laser variants?  (my bad - sorry)

Do I see this correctly: you use StarTrekTorpedo for Torpedo and Warp?

Seeing that we are using 3 effects (do we need a 4th for the other Torpedo effect?), I'd assume we can either implement 3 buttons (or 4) or a rotary switch (select effect) and a button (execute effect). I suppose 3 buttons is easier.

We could introduce the use of an interrupt, which would allow us to interrupt an effect (so the running effect stops) and start another effect?


   
ReplyQuote
Page 11 / 15
Share: