That fixed it! Thank you again for your wisdom.
Awesome! Haha I wouldn't call it wisdom, but I'm happy to see it worked 😁
I realized the firing effect for Voyager ship is different from Enterprise (Totally forgot). Instead of a two lights combining to a center point, it's a one way effect to the target LED for Voyager
Just quickly thrown together and untested:
To keep a "generic" function, here a suggestion that may work (note: I've lost track of the latest modifications for this function - so maybe you can post the full code when this works?).
I've added 2 parameters "bidirectional" and "startLeft".
If bidirectional = true then the phaser starts from left and right (the "old" way). The "startLeft" value will be ignored (but needs to be passed as parameter).
If bidirectional = false then the phaser starts either left (startLeft = true) or right (startLeft = false).
This is untested code and I highlighted the changes, which could be useful incase I copied the code of an incorrect version of the startrek_phaser function.
Let me know if it works or not 😊
void startrek_phaser(byte PhaserRed, byte PhaserGreen, byte PhaserBlue, int TargetLED,
byte PhaserWidth, byte ShootingWidth, int msAimDelay,
int PulsateAmount, int msPulsateDelayBright, int msPulsateDelayDarker,
bool bidirectional, bool startLeft)
{
// 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;
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
if( bidirectional || startLeft) // only show the left animation of birectional or startleft
{
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
if( bidirectional || (!startLeft)) // only show right animation if bidirectional or not startleft
{
LEDPosLEDPos = 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);
}
}
(I hope the code copied correctly here - the forum seems to like to screw around with the > and < characters if no spaces are placed around them, thinking it may be HTML code)