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.3 K Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2680
Topic starter  

Hi Jamie,

never apologize for being new at something - we all had to start at some point right? 😊 

As for the next error;
Could you post the entire code, and the complete error message (since it will have a line number in it).
I know, you cannot yet upload files, this will take 5 manually approved messages in the forum (to prevent spammers).
If pasting the code doesn't work; email me the INO file, and I'll post it here manually.

Note: The error basically says that element number 60, from the array called CRGB, is not of the type CRGB.
Probably why it fails is that the variable is called CRGB and the the type is called CRGB as well, which may confuse the compiler.


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

Thanks Hans - the code SHOULD be the same as the one Trace posted on page 2 of this thread:

 

#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
#define PIN 7
#define buttonPin 3 // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status

//=============== DFPlayer mini ===============//
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);
//=============== DFPlayer mini ===============//

void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
randomSeed(analogRead(0)); // for a better random
FastLED.setBrightness(20);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);

//=============== DFPlayer mini setup ===============//
mySoftwareSerial.begin(9600);
Serial.begin(115200);
if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
while(true);
}
myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms
myDFPlayer.volume(20); //Set volume value (0~30).
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD);
//=============== DFPlayer mini setup end ===============//

}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
myDFPlayer.playMp3Folder(5); // plays MP3 file number 5 which is a button sound
delay(1000); // this delay needs to be at least as long as the MP3 button sound file to give it enough time to be played
// turn phaser on 3x:
startrek_phaser( 0xff, 0x90, 0, -1, 4, 3, 10, 20, 60, 40);
startrek_phaser( 0xff, 0x90, 0, -1, 4, 3, 10, 20, 60, 40);
startrek_phaser( 0xff, 0x90, 0, -1, 4, 3, 10, 20, 60, 40);
}
}

void startrek_phaser(byte PhaserRed, byte PhaserGreen, byte PhaserBlue, int TargetLED,
byte PhaserWidth, byte ShootingWidth, int msAimDelay,
int PulsateAmount, int msPulsateDelayBright, int msPulsateDelayDarker)
{
// These define how much the outer LEDs sim during Aiming, Shooting and Pulsating
#define DimmingPhaserAim 200
#define DimmingShoot 128
#define DimmingPulsing 128

int PhaserHalf = PhaserWidth/2; // division will take integer part: 3/2 = 1.5 -> 1, 4/2 = 2 -> 2
int PhaserCenterWidth = 2 - (PhaserWidth%2); // odd numbers: 1, even numbers: 2
int PhaserAim;
myDFPlayer.playMp3Folder(1); // plays MP3 file number 1 which is the phaser sound

if(TargetLED==-1)
{
PhaserAim = random(NUM_LEDS); // Pick random aim point

if(PhaserAim<PhaserHalf) // just making sure we do not go out of the range of LEDs
{
PhaserAim = PhaserWidth;
}
else if(PhaserAim+PhaserHalf>NUM_LEDS)
{
PhaserAim = NUM_LEDS-PhaserHalf;
}
}
else
{
PhaserAim = TargetLED;
}

int StepsLeftside = PhaserAim; // 0 - PhaserAim
int StepsRightside = NUM_LEDS-PhaserAim; // PhaserAim - NUM_LEDS

int maxSteps = max( StepsLeftside, StepsRightside );

int LEDPos;

// move LEDs from outside to phaser position

for(int counter=0; counter<=maxSteps; counter++)
{
setAll(0,0,0); // set all LEDs dark
// Left side towards aim point

LEDPos = PhaserAim-maxSteps+counter;

if( LEDPos >= 0 ) {
for (int PhaserBlock = 0; PhaserBlock<PhaserWidth; PhaserBlock++)
{
if(LEDPos+PhaserBlock>0)
{
leds[LEDPos+PhaserBlock] = CRGB( PhaserRed, PhaserGreen, PhaserBlue);
// only center (odd width) or center 2 LEDs (even width) should be bright, others need to fade
if ( ( (PhaserCenterWidth==1) && (PhaserBlock!=PhaserHalf) ) ||
( (PhaserCenterWidth==2) && (PhaserBlock!=PhaserHalf-1) && (PhaserBlock!=PhaserHalf) ) )
{
leds[LEDPos+PhaserBlock].fadeLightBy( DimmingPhaserAim );
}
}
}
}
// Right side towards aim point
LEDPos = PhaserAim+maxSteps-counter;

if( LEDPos < NUM_LEDS ) {
for (int PhaserBlock = 0; PhaserBlock<PhaserWidth; PhaserBlock++)
{
if(LEDPos+PhaserBlock<NUM_LEDS)
{
leds[LEDPos+PhaserBlock] = CRGB( PhaserRed, PhaserGreen, PhaserBlue);
// only center (odd width) or center 2 LEDs (even width) should be bright, others need to fade
if ( ( (PhaserCenterWidth==1) && (PhaserBlock!=PhaserHalf) ) ||
( (PhaserCenterWidth==2) && (PhaserBlock!=PhaserHalf-1) && (PhaserBlock!=PhaserHalf) ) )
{
leds[LEDPos+PhaserBlock].fadeLightBy( DimmingPhaserAim );
}
}
}
}
FastLED.show();
delay(msAimDelay);
}

// pulsing LEDs when firing phaser
LEDPos = PhaserAim;

PhaserHalf = ShootingWidth/2; // division will take integer part: 3/2 = 1.5 -> 1, 4/2 = 2 -> 2
PhaserCenterWidth = 2 - (ShootingWidth%2); // odd numbers: 1, even numbers: 2

setAll(0,0,0); // set all to black since shooting width may be different than aiming width

for(int counter=0; counter<PulsateAmount; counter++) {

// Set phaser at aim position to the usual brightness
for (int PhaserBlock = 0; PhaserBlock<ShootingWidth; PhaserBlock++)
{
leds[LEDPos+PhaserBlock] = CRGB( PhaserRed, PhaserGreen, PhaserBlue);
// only center (odd width) or center 2 LEDs (even width) should be bright, others need to fade
if ( ( (PhaserCenterWidth==1) && (PhaserBlock!=PhaserHalf) ) ||
( (PhaserCenterWidth==2) && (PhaserBlock!=PhaserHalf-1) && (PhaserBlock!=PhaserHalf) ) )
{
leds[LEDPos+PhaserBlock].fadeLightBy( DimmingShoot );
}
}
FastLED.show();
delay(msPulsateDelayBright);
// Make the outer LEDs pulsate (not the center LED or LEDs)
for (int PhaserBlock = 0; PhaserBlock<ShootingWidth; PhaserBlock++)
{
if ( ( (PhaserCenterWidth==1) && (PhaserBlock!=PhaserHalf) ) ||
( (PhaserCenterWidth==2) && (PhaserBlock!=PhaserHalf-1) && (PhaserBlock!=PhaserHalf) ) )
{
leds[LEDPos+PhaserBlock].fadeLightBy( DimmingPulsing );
}
}
FastLED.show();
delay(msPulsateDelayDarker);
}

setAll(0,0,0);
delay(500);
}

// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
leds = CRGB(red, green, blue);
}

FastLED.show();
}

 

Hopefully the copy/paste works!

J


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

Since I do not know the line where the error occurs, my best guess would be at the end where I see:

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    leds = CRGB(red, green, blue);
  }

  FastLED.show();
}

The line "leds = CRGB ..." is wrong (may be a result from pasting it?) and should probably read: "leds[i] = CRGB ..."

Like so:

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    leds[i] = CRGB(red, green, blue);
  }

  FastLED.show();
}

[i] begin the index of a CRGB in that CRGB array, called "leds".

😊 

 

 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

@hans 

 

Yay! That fixed it!! Now I await the hardware to build it!

Thank you Sir!


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

You're most welcome! 😊 


   
ReplyQuote
(@Anonymous)
Joined: 1 second ago
Posts: 0
 

So now I have the hardware but can't seem to get this to work...I'm confident the sketch is correct as per previous posts.

Could someone please explain the physical connections - so far I have:

 

12v in to the LED strip (this lights up 3 LEDs)

Data wire connected to PIN 7 on the arduino

Jumper wire on PIN 3 (do I connect this to GND or 5v in to trigger this switch?)

Arduino in plugged into my laptop via USB

 

I have a 30 LED length of WS2811...

 

...However I'd LIKE to use WS2812C 150 LED strip - can the code be amended to allow this...?

 

Any help appreciated!!

 

 


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

If you have the WS2812C 150 LED strip; then sure, you can use it. Probably even better than your 12V strip (I have never used a 12V strip, but that doesn't mean they do not work).

Just modify the define:

#define NUM_LEDS 60

to

#define NUM_LEDS 150

As for the button; the other end is connected to GND as far as I recall. It will not harm your Arduino though if that was wrong.
A more common way to connect a button would be like documented here.

The +5V + 10 KOhm resistor are used to avoid bounce issues and such. Or as described in that documentation:

If you disconnect the digital I/O pin from everything, the LED may blink erratically.
This is because the input is "floating" - that is, it will randomly return either HIGH or LOW.
That's why you need a pull-up or pull-down resistor in the circuit.

Hope this helps 😊 


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

@hans Hi there Hans. Hope you feel great and everything goes well?! Its been again a long time and a lot of things happened. But with a lil bit of new energy......what about to revive this topic?


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

Hi Trace!

Good to hear from you again, and again apologies for the radio silence! 
A lot of things have changed here as well. Sometimes life can just fly by, doesn't it?

I'd love to revive this as a project, like we talked about before.
Just in the middle of potentially moving again, taking care of my mom and trying to find an income, man life sure becomes busy.
Added a big fat post-it on my laptop for this project, but not promising anything just yet on how quick I'll be able to work on this. 😊 


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

@hans Hi Hans, unfortunately I did not got any notification that you had answered me. But reading your answer now feels like, it is not too bad to reply that late. You had a lot to do on your list.
Im in search for income to. After bad news about my health, I had to quit my Job, cause it caused a big drop in my healthiness.
How is it going on your side?


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

@trace 

Hi Trace! Well, that's not good to hear 😞 - is it permanent? ... I'm kind-a in a similar boat. Initially hard to find work, and now my health prevents me to go find work (long black mold related story and hopefully not permanent).


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

@hans Hi Hans, yes, it is permanent and not curable, it can be only slowed down. But lucky for me, it does not have a big effect on my everday routine yet.
Im sorry to hear that you are in health trouble too. Hopefully you will feel better soon.
And yes, it is really hard to find a job which does not affect you health, where you get paid reasonable and does not cost too much of your lifetime.

This post was modified 8 months ago by Trace

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

Posted by: @trace
Yes, it is permanent and not curable, it can be only slowed down. But lucky for me, it does not have a big effect on my everyday routine yet.

I'm so so sorry to hear that 😞 - that is just terrible.
I guess I can only hope and wish that it indeed goes as slow as possible 😞 
Let me know if there is anything I can do for you. I know there will not be anything, but I'd like to offer anyway.

Sorry for the late reply - I have not been home for a while now. Should get home about 10 days from now. Had the wonderful opportunity to visit my aunt in Der Schweiz - but Internet is somewhat spotty over here. Kind-a nice though, just to "unplug" for a couple of weeks, and sit in the middle of nature. 😊 


   
ReplyQuote
Page 15 / 15
Share: