Need help with Star Trek project!

This is my sketch for a Star Trek project I am doing:

// Simple Navigation & Strobe light flashing
// Impulse/Warp Mode Fade-out and Fade-in
// Double Photon Torpedo Effect and Phaser Effect
// Drydock Startup Sequence using a Shift Register
// Audio Sound Effects
// Red Alert Effect
// Original Author: Ostrich Longneck
// Date: 27 December, 2016
// Adjusted original sketch by Pete Becerra
// Date 23 Spetember 2022

// LedFlasher Library by Nick Gammon, 23 Dec 2012
  #include <LedFlasher.h>

// Audio TMRpcm Library by Various Contributors
#include <TMRpcm.h>
#include <SPI.h>
#include <SD.h>

// Set up LEDs
// Always flashing LEDs: PIN  OFF  ON (milliseconds)
LedFlasher strobeLights(14, 900, 100);
LedFlasher navLights(13, 500, 1000);
LedFlasher phaserLights(25, 50, 100);

// set up the pin numbers used for warp mode activation/deactivation
const int impulsePin = 11;  // Pin 11 is a PWM pin, used to fade the yellow impulse LED up and down
const int warpPin = 12;     // Pin 12 is a PWM pin, used to fade the blue warp LED up and down
const int warpButton = 26;  // Warpmode will be activated & deactivated by a button on pin 26 (= A3)

// set up pin numbers used for photon torpedo effect
const int photonPin1 = 23;  // Pin 23 & 24 are digital (non-PWM) pins (= A0 & A1)
const int photonPin2 = 24;
const int photonButton = 27;  // photon torpedo effect will be activated by a button on pin 27 (= A4)

// set up pin numbers used for phaser effect
const int phaserPin = 25;     // Pin 25 is a digital pin (= A2)
const int phaserButton = 28;  // phaser effect will be activated by a button on pin 28 (= A5)

// set up pin numbers used for red alert effect
const int redSwitch = 3;  // Red Alert will be activated by a button on pin 3

// Set up Arrays & Variables used for the Floodlights in the Drydock Startup Sequence
const int dryDock[7] = { 14, 15, 16, 17, 18, 19, 8 };                // Output pin numbers used in drydock startup sequence
const int dryDockTime[7] = { 1760, 3240, 5080, 6720, 8560, 10200 };  // Timeline in milliseconds between floodlights
int dryDockStart = 2000;                                             // Time before first floodlight starts the sequence (in milliseconds)
int dryDockCounter = 0;                                              // Counter used to keep track of floodlight number in sequence
long dryDockSeqStart = 0;                                            // Time in milliseconds when drydocksequence was initiated
long dryDockSeqEnd = 0;                                              // Variable used to check if it's time for the next floodlight to light up
int dryDockStack = 1;                                                // Variable used to calculate value to be written to 74HC595 Shift Register

// Set up variables used to activate/deactivate warp mode
int fadeVal = 0;          // variable for fade loop
int fadeTime = 0;         // variable for fade delay loop
int fadeTo = 0;           // variable for length of fade delay
int maxFade = 255;        // set max brightness value for fade-up and fade-down
int warpMode = 0;         // Warp mode: 0=impulse; 1=warp
int warpButtonState = 0;  // flag to check if button has been pressed
int stateChange = 0;      // flag to prevent reading button on pin 1 during warp LEDs fade-in & fade-out
int fadeLength = 6000;    // approximate length of time (milliseconds) in which the fade-down fade-up cycle will take place
int fadeDown = 0;         // flag to check if we are currently fading down to 0
int fadeUp = 0;           // flag to check if we are currently fading up to 255

// Set up variables used in the photon torpedo effect
int photonButtonState = 0;  // flag to check if button has been pressed
int photonState = 0;        // flag to prevent reading of button 2 while effect runs
int photonTorpedo1 = 0;     // flag to check if torpedo #1 has been launched
int photonTorpedo2 = 0;     // flag to check if torpedo #2 has been launched
// int lowFlash = 35; // intensity of first torpedo flash
// int highFlash = 255; // intensity of second torpedo flash
int flashLength = 1000;  // (approximate) time in milliseconds for torpedo to flash low & high
int flashTogether = 0;   // flag: if zero, torpedos fire separately; if one, torpedos fire simultaneously

 // Set up variables used in the phaser effect
int phaserButtonState = 0;   //flag to check if button has been pressed
int phaserState = 0;         // 0 = phasers off; 1 = phasers firing
int phaserBurst = 4000;      // length of phaser burst in milliseconds
int startBurst = 0;          // flag to initiate start of phaser burst
int lastPhaserState = 0;     // flag to check previous button state
long lastDebounceTime = 0;   // last time phaser button was pressed
long debounceDelay = 50;     // debounce time in milliseconds
long phaserStartMillis = 0;  // time when phaser burst started

 // Set up variables used for sound effects
char* sample[10] = { (char*)"PWRDOWN2.wav", (char*)"qtorpedoes.wav", (char*)"Phaser.wav", (char*)"alert10.wav", (char*)"Phastorp.wav", (char*)"POWERUP.wav", (char*)"STEOPENING.wav" };
int firstSound = 1;  // flag to finish playing intro before other sound effects start
char mychar;
const int CS_PIN = 10;
TMRpcm audio;

 // Set up variables for 74HC595 Shift Register
int latchPin = 6;  // Pin connected to ST_CP of 74HC595
int clockPin = 4;  // Pin connected to SH_CP of 74HC595
int dataPin = 5;   // Pin connected to DS of 74HC595


 // Set up variables used for Red Alert Effect
int redState = 0;         // Check if button has been pressed: 0=no; 1=yes
int redLength = 17500;    // Length of Red Alert Effect in milliseconds
int lastRedState = 0;     // flag to check previous button state
long redStartMillis = 0;  // Time when Red Alert started
int lightsOff = 1;        // switch off floodlights during Red Alert: 0=no; 1=yes

void setup() {
  // Set up pins used by shift register
  pinMode(redSwitch, INPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  // Clear shift register
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 0);
  digitalWrite(latchPin, HIGH);

  // Set up pins for audio effects
  audio.speakerPin = 15;  // Speaker pin on output pin 15
  //Serial.begin(9600);
  pinMode(CS_PIN, OUTPUT);
  if (!SD.begin(CS_PIN))
    return;

  //Serial.println("Card Ready");
  audio.setVolume(5);
  audio.quality(1);
  // Finished audio setup, now to play the Intro
  audio.play((char*)"STEOPENING.wav");

  strobeLights.begin();  // Initialize strobe lights
  navLights.begin();     // Initialize navigation lights
  phaserLights.begin();  // Initializes phaser lights

  pinMode(impulsePin, OUTPUT);  // Impulse LED on pin 11
  pinMode(warpPin, OUTPUT);     // Warp LED on pin 12
  pinMode(warpButton, INPUT);   // Warp mode button on pin 26

  pinMode(photonPin1, OUTPUT);   // Photon torpedo #1 LED on pin 23
  pinMode(photonPin2, OUTPUT);   // Photon torpedo #2 LED on pin 24
  pinMode(photonButton, INPUT);  // Photon torpedo button on pin 27

  pinMode(phaserPin, OUTPUT);    // Phaser LED on pin 25
  pinMode(phaserButton, INPUT);  // Phaser button on pin 28

  fadeTo = fadeLength / 8;  // used for delay timer in fade loop

  // small delay before fade-up of yellow impulse mode LED
  // because it looks kinda cool...
  // delete the next 6 lines if you want to remove this delay
  for (int deLay1 = 0; deLay1 <= 120; deLay1 += 1) {
    for (int deLay2 = 0; deLay2 <= 5000; deLay2 += 1) {
      strobeLights.update();
      navLights.update();
    }
  }  // end of small delay on startup

  // DRYDOCK STARTUP SEQUENCE USING ARDUINO DATAPIN TO DRIVE A 74HC595 SHIFT REGISTER
  // Initial delay before first floodlight starts
  dryDockSeqEnd = millis() + dryDockStart;
  while (millis() < dryDockSeqEnd) {  // Wait around until it's time for the first floodlight to light up
    strobeLights.update();
    navLights.update();
  }
  // Switch on LEDs 0 to 5 according to Timeline
  dryDockSeqStart = millis();  // Marks the time when the timeline initiates (first floodlight zero-time)
  dryDockSeqEnd = dryDockSeqStart + dryDockTime[1];
  for (dryDockCounter = 0; dryDockCounter < 6; dryDockCounter += 1) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, dryDockStack);
    digitalWrite(latchPin, HIGH);
    dryDockStack = dryDockStack * 2 + 1;
    dryDockSeqEnd = dryDockSeqStart + dryDockTime[dryDockCounter];
    while (millis() < dryDockSeqEnd) {  // Pause between floodlights
      strobeLights.update();
      navLights.update();
    }
  }
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, dryDockStack);
  digitalWrite(latchPin, HIGH);
  // end of Drydock Startup Sequence

  // RAMP UP YELLOW/BLUE LED AT STARTUP
  for (fadeVal = 0; fadeVal <= maxFade; fadeVal += 1) {
    if (warpMode == 0) {
      analogWrite(impulsePin, fadeVal);
    } else {
      analogWrite(warpPin, fadeVal);
    }
    for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
      strobeLights.update();
      navLights.update();
    }
  }

}  // end of setup

void loop()  // The main program
{
  // update lights
  strobeLights.update();
  navLights.update();
  if (firstSound == 1 and audio.isPlaying() == 0) {  // If Intro has stopped playing ...
    firstSound = 0;                                  // ...set intro flag to zero
  }
  if (phaserState == 1 and firstSound == 0 and audio.isPlaying() == 0) {  // If Phasers are active and no sound is playing...
    audio.play((char*)"Phaser.wav");                                      // ... start playing Phaser soundFX
  }
  if (phaserState == 1) {  // if phasers are active then update phaser flash
    phaserLights.update();
  } else {
    digitalWrite(phaserPin, 0);  // otherwise switch phasers off...
    if (firstSound == 0) {       // ... and provided Intro is not playing ... {
                                 //audio.stopPlayback(); // ... switch phaser sound off
    }
  }

  // SWITCH BETWEEN WARP MODE AND IMPULSE MODE
  warpButtonState = digitalRead(warpButton);           // check for button press
  if (warpButtonState == HIGH and stateChange == 0) {  // if button has been pressed and state change between impulse/warp has not begun yet, then:
    stateChange = 1;                                   // initialize state change
    fadeDown = 1;                                      // initialize fade down (dimming)
    fadeUp = 0;                                        // do not fade up yet (brightening)
    phaserState = 0;                                   // turn off phaser effect...
    digitalWrite(phaserPin, LOW);                      // ... and switch off phaser LED
  }

  // IMPULSE TO WARP - Fade orange to black first
  if (warpMode == 0 && stateChange == 1 && fadeDown == 1) {
    for (fadeVal = maxFade; fadeVal >= 0; fadeVal -= 1) {
      analogWrite(impulsePin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
        strobeLights.update();
        navLights.update();
      }
    }

    fadeDown = 0;
    fadeUp = 1;
  }

  // IMPULSE TO WARP - Fade black to blue
  if (warpMode == 0 and stateChange == 1 and fadeUp == 1) {
    for (fadeVal = 0; fadeVal <= maxFade; fadeVal += 1) {
      analogWrite(warpPin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
        strobeLights.update();
        navLights.update();
      }
    }

    fadeUp = 0;
    stateChange = 0;
    warpMode = 1;
  }

  // SWITCH BETWEEN IMPULSE MODE AND WARP MODE
  // button state was cheked above; state change and fade down were activated

  // WARP TO IMPULSE - Fade blue to black first
  if (warpMode == 1 and stateChange == 1 and fadeDown == 1) {
    for (fadeVal = maxFade; fadeVal >= 0; fadeVal -= 1) {
      analogWrite(warpPin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
        strobeLights.update();
        navLights.update();
      }
    }

    fadeDown = 0;
    fadeUp = 1;
  }

  // WARP TO IMPULSE - Fade black to yellow
  if (warpMode == 1 and stateChange == 1 and fadeUp == 1) {
    for (fadeVal = 0; fadeVal <= maxFade; fadeVal += 1) {
      analogWrite(impulsePin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
        strobeLights.update();
        navLights.update();
      }
    }

    fadeUp = 0;
    stateChange = 0;
    warpMode = 0;
  }

   // THE PHOTON TORPEDO EFFECT
   // The following code checks for the photon torpedo button press, then fires torpedo #1 and torpedo #2 in quick succession
  int photonButtonState = digitalRead(photonButton);     // check for button press
  if (photonButtonState == HIGH and photonState == 0) {  // if button has been pressed and state change between impulse/warp has not begun yet, then:
    photonState = 1;                                     // initialize state change
    photonTorpedo1 = 1;                                  // initialize torpedo #1 firing
    photonTorpedo2 = 0;                                  // do not fire torpedo #2 yet
                                                         // phaserState = 0; // turn off phaser effect
                                                         // digitalWrite (phaserPin, LOW); // switch off phaser LED


    // FIRE TORPEDO # 1 - a short low-level burst followed by a longer high-level burst
    if (photonState == 1 and photonTorpedo1 == 1) {
      digitalWrite(photonPin1, HIGH);    // fire short burst
      if (flashTogether == 1) {          // if flag is set...
        digitalWrite(photonPin2, HIGH);  // ... fire torpedo #2 simultaneously
      }
      for (int deLay1 = 0; deLay1 <= flashLength * 7; deLay1 += 1) {  // delay loop for short burst
        strobeLights.update();
        navLights.update();
        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        }
        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
            audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
          }
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 0) {
              audio.stopPlayback();
            }
          }
        }
        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }
      digitalWrite(photonPin1, 0);                                     // turn off pin after low-intensity burst
      digitalWrite(photonPin2, 0);                                     // turn off torpedo #2 in case flashTogether flag was set
      for (int deLay1 = 0; deLay1 <= flashLength * 15; deLay1 += 1) {  // delay loop for a short pause
        strobeLights.update();
        navLights.update();

        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
            audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
          }
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 1) {
              audio.stopPlayback();
            }
          }
        }

        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }
      digitalWrite(photonPin1, HIGH);              // full-intensity burst
      if (firstSound == 1 and phaserState == 0) {  // engine sound is still playing and phasers ARE NOT firing...
        audio.play((char*)"qtorpedoes.wav");       // ... play Torpedo soundFX
      }
      if (firstSound == 1 and phaserState == 1) {  // engine sound is still playing and phasers ARE active ...
        audio.play((char*)"Phastorp.wav");         // ... play Torpedo + Phaser soundFX
      }
      if (flashTogether == 1) {          // if flag is set
        digitalWrite(photonPin2, HIGH);  // ... fire torpedo #2 simultaneously
      }

      for (int deLay1 = 0; deLay1 <= flashLength * 30; deLay1 += 1) {  // delay loop for longer burst
        strobeLights.update();
        navLights.update();

        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          //if (firstSound == 1){ // engine sound is still playing and phasers are firing...
          //audio.play("Phaser.wav"); // ... play Phaser soundFX
          //}
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 1) {
              //audio.stopPlayback ((char*)"Phaser.wav");
            }
          }
        }

        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }
      digitalWrite(photonPin1, 0);  // turn off torpedo #1
      digitalWrite(photonPin2, 0);  // turn off torpedo #2 in case flashTogether flag was set
      photonTorpedo1 = 0;           // time to fire torpedo #2
      photonTorpedo2 = 1;           //
    }
    if (phaserState == 1 and firstSound == 1) {
      audio.play((char*)"Phaser.wav");  // Play Phaser SFX between Torpedos
    }

    // FIRE TORPEDO # 2 - a short low-level burst followed by a longer high-level burst

    if (photonState == 1 and photonTorpedo2 == 1) {
      for (int deLay1 = 0; deLay1 <= 14000; deLay1 += 1) {  // delay loop between photon torpedo #1 and #2 firing; also prevents overlap when flashTogether = 1
        strobeLights.update();
        navLights.update();

        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          if (firstSound == 1) {              // engine sound is stillplaying amd phasers are firing...
            audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
          }
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 0) {
              //audio.stopPlayback ();
            }
          }
        }

        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }
      if (flashTogether == 0) {                                         // if torpedos don't fire simultaneously, then fire torpedo #2
        digitalWrite(photonPin2, HIGH);                                 // first short burst
        for (int deLay1 = 0; deLay1 <= flashLength * 7; deLay1 += 1) {  // delay loop for short burst
          strobeLights.update();
          navLights.update();

          // Check for Phaser Button Press
          phaserState = digitalRead(phaserButton);
          if (phaserState == 1 and startBurst == 0) {
            startBurst = 1;
            if (firstSound == 1) {              //engine sound is still playing and phasers are firing...
              audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
            }
            phaserStartMillis = millis();
          }
          if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
            phaserState = 1;
          } else {
            startBurst = 0;
            if (phaserBurst > 0) {
              phaserState = 0;
              if (firstSound == 0) {
                //audio.stopPlayback ();
              }
            }
          }

          if (phaserState == 1) {  // if phasers are active then update phaser flash
            phaserLights.update();
          } else {
            digitalWrite(phaserPin, 0);  // otherwise switch phasers off
          }
        }
        digitalWrite(photonPin2, 0);                                     // turn off pin after low-intensity burst
        for (int deLay1 = 0; deLay1 <= flashLength * 15; deLay1 += 1) {  // delay loop for short burst
          strobeLights.update();
          navLights.update();

          // Check for Phaser Button Press
          phaserState = digitalRead(phaserButton);
          if (phaserState == 1 and startBurst == 0) {
            startBurst = 1;
            if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
              audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
            }
            phaserStartMillis = millis();
          }
          if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
            phaserState = 1;
          } else {
            startBurst = 0;
            if (phaserBurst > 0) {
              phaserState = 0;
              if (firstSound == 0) {
                //audio.stopPlayback ();
              }
            }
          }

          if (phaserState == 1) {  // if phasers are active then update phaser flash
            phaserLights.update();
          } else {
            digitalWrite(phaserPin, 0);  // otherwise switch phasers off
          }
        }
        digitalWrite(photonPin2, HIGH);              // full-intensity burst
        if (firstSound == 1 and phaserState == 0) {  // engine sound is still playing and phasers are not firing...
          audio.play((char*)"qtorpedoes.wav");       // ... play Torpedo soundFX
        }
        if (firstSound == 1 and phaserState == 1) {  // engine sound is still playing and phasers ARE active...
          audio.play((char*)"Phastorp.wav");         // ... play Torpedo + Phaser soundFX
        }
        for (int deLay1 = 0; deLay1 <= flashLength * 30; deLay1 += 1) {  // delay loop for longer burst
          strobeLights.update();
          navLights.update();

          // Check for Phaser Button Press
          phaserState = digitalRead(phaserButton);
          if (phaserState == 1 and startBurst == 0) {
            startBurst = 1;
            //if (firstSound == 1){ // engine sound is still playing and phasers are firing...
            //  audio.play("Phaser.wav"); // ... play Phaser soundFX
            //}
            phaserStartMillis = millis();
          }

          if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
            phaserState = 1;
          } else {
            startBurst = 0;
            if (phaserBurst > 0) {
              phaserState = 0;
              if (firstSound == 0) {
                //audio.stopPlayback ();
              }
            }
          }
        }

        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }

      digitalWrite(photonPin2, 0);  // turn off torpedo #2
      photonTorpedo2 = 0;           // done firing torpedo #2
      photonState = 0;              // photon torpedo effect is completed
      while (audio.isPlaying() > 0 and firstSound == 1) {
        strobeLights.update();
        navLights.update();

        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
            audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
          }
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 0) {
              //audio.stopPlayback ();
            }
          }
        }
      }
    }
  }

  // THE PHASER EFFECT
  // The following code debounces the phaser button, then activates or deactivates the phaser firing accordingly
  int reading = digitalRead(phaserButton);
  if (reading != lastPhaserState) {  // if switch state changed....
    lastDebounceTime = millis();     // .. reset debounce timer
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {  // if reading has been there for longer than the debounce delay...
    phaserState = reading;                              // ... change phaser state to the button state
  }
  if (phaserState == 1 and startBurst == 0) {
    startBurst = 1;
    if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
      audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
    }
    phaserStartMillis = millis();
  }
  lastPhaserState = reading;  // this variable is used to check switch state change & initiate the debounce process above
  if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
    phaserState = 1;
  } else {
    startBurst = 0;
    if (phaserBurst > 0) {
      phaserState = 0;
      if (firstSound == 1) {
        audio.stopPlayback();
      }
    }
  }

  // THE RED ALERT EFFECT
      redState = digitalRead(redSwitch);
      if (redState == 1) {
         digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, MSBFIRST, 255 - 127 * lightsOff);  // Activate pin 7 of 
          Shift Register; keep floodlights on
        digitalWrite(latchPin, HIGH);
       digitalWrite(phaserPin, 0);  // switch phasers off
       phaserState = 0;
       audio.play((char*)"alert10.wav");  // ... play Red Alert soundFX
       redStartMillis = millis();
        while (millis() < (redStartMillis + redLength)) {  // Delay while Red Alert runs
      strobeLights.update();
      navLights.update();
    }
    digitalWrite(latchPin, LOW);                             // Red Alert over, return to normal
    shiftOut(dataPin, clockPin, MSBFIRST, 127 + lightsOff);  // Switch off pin 7 if floodlights are on; keep pin 7 on if floodlights are off
    digitalWrite(latchPin, HIGH);

    if (lightsOff == 1) {
      dryDockStack = 1;
      for (dryDockCounter = 0; dryDockCounter < 7; dryDockCounter += 1) {
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, MSBFIRST, dryDockStack + 128 * (dryDockCounter < 4));
        digitalWrite(latchPin, HIGH);
        dryDockStack = dryDockStack * 2 + 1;
        for (int deLay1 = 0; deLay1 < 30000; deLay1 += 1) {  // Pause between floodlights
          strobeLights.update();
          navLights.update();
          if (firstSound == 0) {
            //audio.stopPlayback ();
          }
        }
      }
    }
  }


}  // end of loop

I am using a stand alone ATMega328P in the final circuit and here is the ATMega328P pin out compared to the bread boarded circuit:

I have a 12VDC/1Amp and 5VDC/4 Amp wall power supply.

When I power it all up, I have 5VDC at pins 7, 20, and 21. According to the sketch, I should have the LED's attached to pins 7 and 8 on. The LED attached to pin 5 should be on and sound should be heard out of the speaker via pin 15. Instead, nothing is on except the LED on pin 5 and either the LED on pin 23 or 24 is blinking, no sound but static instead and LED's attached to pins 7 and 8 are not on.

I am a beginner writing code and the Arduino board, but I do have a degree in electronics and worked on electronics in the Army.
What could be my problem?

Welcome to the forum

You appear to be using the chip pin numbers in your sketch rather than the Arduino pin numbers. Is that deliberate ?

These look like physical PIN numbers... that is the pins on the actual chip 1-28.

In your code you should be using the logical GPIO Pin numbers.

This pinout diagram might make it clearer... in your code you should be using the Brown numbers in your code.

For example PIN 5 is physical pin 11 on the chip.

Yes. I used the Arduino board to build and test the circuits first.
So when I changed everything to the stand alone ATMega328, aren't I supposed to change the pins to correspond to the chip.
Here is the bread boarded circuit:

No

Use the same pin numbers as you used with the Arduino board. The compilation process will take care of the mapping

WELL DARN IT!!!!!! That makes a lot of sense! I learned something new today.

The person who originally wrote this sketch had it that way. I assumed you had to change the pins numbers to correspond to the actual chip.

Thank you, I'm going to try that in the morning.

where can I find this picture and a explanation of what each color and/or column means?

search term: arduino uno pinout diagram

https://www.google.com/search?client=safari&rls=en&q=atmega328p+pinout

Thank you goes out to @red_car and @UKHeliBob for pointing out my mistake with the pin number call out in the sketch. It got a majority of all my lights working.

Now I am having issues with the sound and the lights attached to the shift register and Darlington driver. This includes the "RED ALERT" switch and LED. I am not getting any sound and no LED's lit up that are attached to the ULN2803A Darlington Transistor pins 12 to 18. Below is the bread boarded circuit for the speaker and Mini SD reader.

Is there something wrong in the sketch?

// Simple Navigation & Strobe light flashing
// Impulse/Warp Mode Fade-out and Fade-in
// Double Photon Torpedo Effect and Phaser Effect
// Drydock Startup Sequence using a Shift Register
// Audio Sound Effects
// Red Alert Effect
// Original Author: Ostrich Longneck
// Date: 27 December, 2016
// Adjusted original sketch by Pete Becerra
// Date 23 Spetember 2022

// LedFlasher Library by Nick Gammon, 23 Dec 2012
#include <LedFlasher.h>

// Audio TMRpcm Library by Various Contributors
#include <TMRpcm.h>
#include <SPI.h>
#include <SD.h>

// Set up LEDs
// Always flashing LEDs: PIN  OFF  ON (milliseconds)
LedFlasher strobeLights(8, 900, 100);
LedFlasher navLights(7, 500, 1000);
LedFlasher phaserLights(16, 50, 100);

// set up the pin numbers used for warp mode activation/deactivation
const int impulsePin = 5;  // Pin 5 is a PWM pin, used to fade the yellow impulse LED up and down
const int warpPin = 6;     // Pin 6 is a PWM pin, used to fade the blue warp LED up and down
const int warpButton = 17;  // Warpmode will be activated & deactivated by a button on pin 17 (= A3)

// set up pin numbers used for photon torpedo effect
const int photonPin1 = 14;  // Pin 14 & 15 are digital (non-PWM) pins (= A0 & A1)
const int photonPin2 = 15;
const int photonButton = 18;  // photon torpedo effect will be activated by a button on pin 18 (= A4)

// set up pin numbers used for phaser effect
const int phaserPin = 16;     // Pin 16 is a digital pin (= A2)
const int phaserButton = 19;  // phaser effect will be activated by a button on pin 19 (= A5)

// set up pin numbers used for red alert effect
const int redSwitch = 1;  // Red Alert will be activated by a button on pin 1

// Set up Arrays & Variables used for the Floodlights in the Drydock Startup Sequence
const int dryDockTime[7] = { 1760, 3240, 5080, 6720, 8560, 10200 };  // Timeline in milliseconds between floodlights
int dryDockStart = 0;                                             // Time before first floodlight starts the sequence (in milliseconds)
int dryDockCounter = 0;                                              // Counter used to keep track of floodlight number in sequence
long dryDockSeqStart = 0;                                            // Time in milliseconds when drydocksequence was initiated
long dryDockSeqEnd = 0;                                              // Variable used to check if it's time for the next floodlight to light up
int dryDockStack = 1;                                                // Variable used to calculate value to be written to 74HC595 Shift Register


// Set up variables used to activate/deactivate warp mode
int fadeVal = 0;          // variable for fade loop
int fadeTime = 0;         // variable for fade delay loop
int fadeTo = 0;           // variable for length of fade delay
int maxFade = 255;        // set max brightness value for fade-up and fade-down
int warpMode = 0;         // Warp mode: 0=impulse; 1=warp
int warpButtonState = 0;  // flag to check if button has been pressed
int stateChange = 0;      // flag to prevent reading button on pin 1 during warp LEDs fade-in & fade-out
int fadeLength = 1000;    // approximate length of time (milliseconds) in which the fade-down fade-up cycle will take place
int fadeDown = 0;         // flag to check if we are currently fading down to 0
int fadeUp = 0;           // flag to check if we are currently fading up to 255

// Set up variables used in the photon torpedo effect
int photonButtonState = 0;  // flag to check if button has been pressed
int photonState = 0;        // flag to prevent reading of button 2 while effect runs
int photonTorpedo1 = 0;     // flag to check if torpedo #1 has been launched
int photonTorpedo2 = 0;     // flag to check if torpedo #2 has been launched
// int lowFlash = 35; // intensity of first torpedo flash
// int highFlash = 255; // intensity of second torpedo flash
int flashLength = 1000;  // (approximate) time in milliseconds for torpedo to flash low & high
int flashTogether = 0;   // flag: if zero, torpedos fire separately; if one, torpedos fire simultaneously

// Set up variables used in the phaser effect
int phaserButtonState = 0;   //flag to check if button has been pressed
int phaserState = 0;         // 0 = phasers off; 1 = phasers firing
int phaserBurst = 4000;      // length of phaser burst in milliseconds
int startBurst = 0;          // flag to initiate start of phaser burst
int lastPhaserState = 0;     // flag to check previous button state
long lastDebounceTime = 0;   // last time phaser button was pressed
long debounceDelay = 50;     // debounce time in milliseconds
long phaserStartMillis = 0;  // time when phaser burst started

// Set up variables used for sound effects
int firstSound = 1;  // flag to finish playing intro before other sound effects start
char mychar;
const int CS_PIN = 10;
TMRpcm audio;

// Set up variables for 74HC595 Shift Register
int latchPin = 4;  // Pin connected to ST_CP of 74HC595
int clockPin = 2;  // Pin connected to SH_CP of 74HC595
int dataPin = 3;   // Pin connected to DS of 74HC595

// Set up variables used for Red Alert Effect
int redState = 0;         // Check if button has been pressed: 0=no; 1=yes
int redLength = 17500;    // Length of Red Alert Effect in milliseconds
int lastRedState = 0;     // flag to check previous button state
long redStartMillis = 0;  // Time when Red Alert started
int lightsOff = 1;        // switch off floodlights during Red Alert: 0=no; 1=yes

void setup() {
  // Set up pins used by shift register
  pinMode(redSwitch, INPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  // Clear shift register
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, 0);
  digitalWrite(latchPin, HIGH);

  // Set up pins for audio effects
  audio.speakerPin = 9;  // Speaker pin on output pin 9
  //Serial.begin(9600);
  pinMode(CS_PIN, OUTPUT);
  if (!SD.begin(CS_PIN))
    return;

  audio.setVolume(5);
  audio.quality(1);
  // Finished audio setup, now to play the Intro
  audio.play((char*)"STEOPENING.wav");

  strobeLights.begin();  // Initialize strobe lights
  navLights.begin();     // Initialize navigation lights
  phaserLights.begin();  // Initializes phaser lights

  pinMode(impulsePin, OUTPUT);  // Impulse LED on pin 11
  pinMode(warpPin, OUTPUT);     // Warp LED on pin 12
  pinMode(warpButton, INPUT);   // Warp mode button on pin 26

  pinMode(photonPin1, OUTPUT);   // Photon torpedo #1 LED on pin 23
  pinMode(photonPin2, OUTPUT);   // Photon torpedo #2 LED on pin 24
  pinMode(photonButton, INPUT);  // Photon torpedo button on pin 27

  pinMode(phaserPin, OUTPUT);    // Phaser LED on pin 25
  pinMode(phaserButton, INPUT);  // Phaser button on pin 28

  fadeTo = fadeLength / 8;  // used for delay timer in fade loop


  // small delay before fade-up of yellow impulse mode LED
  // because it looks kinda cool...
  // delete the next 6 lines if you want to remove this delay
  for (int deLay1 = 0; deLay1 <= 120; deLay1 += 1) {
    for (int deLay2 = 0; deLay2 <= 5000; deLay2 += 1) {
      strobeLights.update();
      navLights.update();
    }
  }  // end of small delay on startup

  // DRYDOCK STARTUP SEQUENCE USING ARDUINO DATAPIN TO DRIVE A 74HC595 SHIFT REGISTER
  // Initial delay before first floodlight starts
  dryDockSeqEnd = millis() + dryDockStart;
  while (millis() < dryDockSeqEnd) {  // Wait around until it's time for the first floodlight to light up
    strobeLights.update();
    navLights.update();
  }
  // Switch on LEDs 0 to 5 according to Timeline
  dryDockSeqStart = millis();  // Marks the time when the timeline initiates (first floodlight zero-time)
  dryDockSeqEnd = dryDockSeqStart + dryDockTime[1];
  for (dryDockCounter = 0; dryDockCounter < 6; dryDockCounter += 1) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, dryDockStack);
    digitalWrite(latchPin, HIGH);
    dryDockStack = dryDockStack * 2 + 1;
    dryDockSeqEnd = dryDockSeqStart + dryDockTime[dryDockCounter];
    while (millis() < dryDockSeqEnd) {  // Pause between floodlights
      strobeLights.update();
      navLights.update();
    }
  }
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, dryDockStack);
  digitalWrite(latchPin, HIGH);
  // end of Drydock Startup Sequence

  // RAMP UP YELLOW/BLUE LED AT STARTUP
  for (fadeVal = 0; fadeVal <= maxFade; fadeVal += 1) {
    if (warpMode == 0) {
      analogWrite(impulsePin, fadeVal);
    } else {
      analogWrite(warpPin, fadeVal);
    }
    for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
      strobeLights.update();
      navLights.update();
    }
  }

}  // end of setup

void loop()  // The main program
{
  // update lights
  strobeLights.update();
  navLights.update();
  if (firstSound == 1 and audio.isPlaying() == 0) {  // If Intro has stopped playing ...
    firstSound = 0;                                  // ...set intro flag to zero
  }
  if (phaserState == 1 and firstSound == 0 and audio.isPlaying() == 0) {  // If Phasers are active and no sound is playing...
    audio.play((char*)"Phaser.wav");                                      // ... start playing Phaser soundFX
  }
  if (phaserState == 1) {  // if phasers are active then update phaser flash
    phaserLights.update();
  } else {
    digitalWrite(phaserPin, 0);  // otherwise switch phasers off...
    if (firstSound == 0) {       // ... and provided Intro is not playing ... {
                                 //audio.stopPlayback(); // ... switch phaser sound off
    }
  }

  // SWITCH BETWEEN WARP MODE AND IMPULSE MODE
  warpButtonState = digitalRead(warpButton);           // check for button press
  if (warpButtonState == HIGH and stateChange == 0) {  // if button has been pressed and state change between impulse/warp has not begun yet, then:
    stateChange = 1;                                   // initialize state change
    fadeDown = 1;                                      // initialize fade down (dimming)
    fadeUp = 0;                                        // do not fade up yet (brightening)
    phaserState = 0;                                   // turn off phaser effect...
    digitalWrite(phaserPin, LOW);                      // ... and switch off phaser LED
  }


  // IMPULSE TO WARP - Fade orange to black first
  if (warpMode == 0 && stateChange == 1 && fadeDown == 1) {
    for (fadeVal = maxFade; fadeVal >= 0; fadeVal -= 1) {
      analogWrite(impulsePin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
        strobeLights.update();
        navLights.update();
      }
    }



    fadeDown = 0;
    fadeUp = 1;
  }


  // IMPULSE TO WARP - Fade black to blue
  if (warpMode == 0 and stateChange == 1 and fadeUp == 1) {
    for (fadeVal = 0; fadeVal <= maxFade; fadeVal += 1) {
      analogWrite(warpPin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
        strobeLights.update();
        navLights.update();
      }
    }


    fadeUp = 0;
    stateChange = 0;
    warpMode = 1;
  }

  // SWITCH BETWEEN IMPULSE MODE AND WARP MODE
  // button state was cheked above; state change and fade down were activated

  // WARP TO IMPULSE - Fade blue to black first
  if (warpMode == 1 and stateChange == 1 and fadeDown == 1) {
    for (fadeVal = maxFade; fadeVal >= 0; fadeVal -= 1) {
      analogWrite(warpPin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
        strobeLights.update();
        navLights.update();
      }
    }

    fadeDown = 0;
    fadeUp = 1;
  }

  // WARP TO IMPULSE - Fade black to yellow
  if (warpMode == 1 and stateChange == 1 and fadeUp == 1) {
    for (fadeVal = 0; fadeVal <= maxFade; fadeVal += 1) {
      analogWrite(impulsePin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1) {
        strobeLights.update();
        navLights.update();
      }
    }

    fadeUp = 0;
    stateChange = 0;
    warpMode = 0;
  }

  // THE PHOTON TORPEDO EFFECT
  // The following code checks for the photon torpedo button press, then fires torpedo #1 and torpedo #2 in quick succession
  int photonButtonState = digitalRead(photonButton);     // check for button press
  if (photonButtonState == HIGH and photonState == 0) {  // if button has been pressed and state change between impulse/warp has not begun yet, then:
    photonState = 1;                                     // initialize state change
    photonTorpedo1 = 1;                                  // initialize torpedo #1 firing
    photonTorpedo2 = 0;                                  // do not fire torpedo #2 yet
                                                         // phaserState = 0; // turn off phaser effect
                                                         // digitalWrite (phaserPin, LOW); // switch off phaser LED


    // FIRE TORPEDO # 1 - a short low-level burst followed by a longer high-level burst
    if (photonState == 1 and photonTorpedo1 == 1) {
      digitalWrite(photonPin1, HIGH);    // fire short burst
      if (flashTogether == 1) {          // if flag is set...
        digitalWrite(photonPin2, HIGH);  // ... fire torpedo #2 simultaneously
      }
      for (int deLay1 = 0; deLay1 <= flashLength * 7; deLay1 += 1) {  // delay loop for short burst
        strobeLights.update();
        navLights.update();
        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        }
        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
            audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
          }
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 0) {
              audio.stopPlayback();
            }
          }
        }




        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }



      digitalWrite(photonPin1, 0);                                     // turn off pin after low-intensity burst
      digitalWrite(photonPin2, 0);                                     // turn off torpedo #2 in case flashTogether flag was set
      for (int deLay1 = 0; deLay1 <= flashLength * 15; deLay1 += 1) {  // delay loop for a short pause
        strobeLights.update();
        navLights.update();



        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
            audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
          }
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 1) {
              audio.stopPlayback();
            }
          }
        }

        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }
      digitalWrite(photonPin1, HIGH);              // full-intensity burst
      if (firstSound == 1 and phaserState == 0) {  // engine sound is still playing and phasers ARE NOT firing...
        audio.play((char*)"qtorpedoes.wav");       // ... play Torpedo soundFX
      }
      if (firstSound == 1 and phaserState == 1) {  // engine sound is still playing and phasers ARE active ...
        audio.play((char*)"Phastorp.wav");         // ... play Torpedo + Phaser soundFX
      }
      if (flashTogether == 1) {          // if flag is set
        digitalWrite(photonPin2, HIGH);  // ... fire torpedo #2 simultaneously
      }

      for (int deLay1 = 0; deLay1 <= flashLength * 30; deLay1 += 1) {  // delay loop for longer burst
        strobeLights.update();
        navLights.update();

        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          //if (firstSound == 1){ // engine sound is still playing and phasers are firing...
          //audio.play("Phaser.wav"); // ... play Phaser soundFX
          //}
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 1) {
              //audio.stopPlayback ((char*)"Phaser.wav");
            }
          }
        }

        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }
      digitalWrite(photonPin1, 0);  // turn off torpedo #1
      digitalWrite(photonPin2, 0);  // turn off torpedo #2 in case flashTogether flag was set
      photonTorpedo1 = 0;           // time to fire torpedo #2
      photonTorpedo2 = 1;           //
    }
    if (phaserState == 1 and firstSound == 1) {
      audio.play((char*)"Phaser.wav");  // Play Phaser SFX between Torpedos
    }

    // FIRE TORPEDO # 2 - a short low-level burst followed by a longer high-level burst

    if (photonState == 1 and photonTorpedo2 == 1) {
      for (int deLay1 = 0; deLay1 <= 14000; deLay1 += 1) {  // delay loop between photon torpedo #1 and #2 firing; also prevents overlap when flashTogether = 1
        strobeLights.update();
        navLights.update();

        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          if (firstSound == 1) {              // engine sound is stillplaying amd phasers are firing...
            audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
          }
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 0) {
              //audio.stopPlayback ();
            }
          }
        }




        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }
      if (flashTogether == 0) {                                         // if torpedos don't fire simultaneously, then fire torpedo #2
        digitalWrite(photonPin2, HIGH);                                 // first short burst
        for (int deLay1 = 0; deLay1 <= flashLength * 7; deLay1 += 1) {  // delay loop for short burst
          strobeLights.update();
          navLights.update();


          // Check for Phaser Button Press
          phaserState = digitalRead(phaserButton);
          if (phaserState == 1 and startBurst == 0) {
            startBurst = 1;
            if (firstSound == 1) {              //engine sound is still playing and phasers are firing...
              audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
            }
            phaserStartMillis = millis();
          }
          if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
            phaserState = 1;
          } else {
            startBurst = 0;
            if (phaserBurst > 0) {
              phaserState = 0;
              if (firstSound == 0) {
                //audio.stopPlayback ();
              }
            }
          }

          if (phaserState == 1) {  // if phasers are active then update phaser flash
            phaserLights.update();
          } else {
            digitalWrite(phaserPin, 0);  // otherwise switch phasers off
          }
        }
        digitalWrite(photonPin2, 0);                                     // turn off pin after low-intensity burst
        for (int deLay1 = 0; deLay1 <= flashLength * 15; deLay1 += 1) {  // delay loop for short burst
          strobeLights.update();
          navLights.update();

          // Check for Phaser Button Press
          phaserState = digitalRead(phaserButton);
          if (phaserState == 1 and startBurst == 0) {
            startBurst = 1;
            if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
              audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
            }
            phaserStartMillis = millis();
          }
          if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
            phaserState = 1;
          } else {
            startBurst = 0;
            if (phaserBurst > 0) {
              phaserState = 0;
              if (firstSound == 0) {
                //audio.stopPlayback ();
              }
            }
          }

          if (phaserState == 1) {  // if phasers are active then update phaser flash
            phaserLights.update();
          } else {
            digitalWrite(phaserPin, 0);  // otherwise switch phasers off
          }
        }
        digitalWrite(photonPin2, HIGH);              // full-intensity burst
        if (firstSound == 1 and phaserState == 0) {  // engine sound is still playing and phasers are not firing...
          audio.play((char*)"qtorpedoes.wav");       // ... play Torpedo soundFX
        }
        if (firstSound == 1 and phaserState == 1) {  // engine sound is still playing and phasers ARE active...
          audio.play((char*)"Phastorp.wav");         // ... play Torpedo + Phaser soundFX
        }
        for (int deLay1 = 0; deLay1 <= flashLength * 30; deLay1 += 1) {  // delay loop for longer burst
          strobeLights.update();
          navLights.update();


          // Check for Phaser Button Press
          phaserState = digitalRead(phaserButton);
          if (phaserState == 1 and startBurst == 0) {
            startBurst = 1;
            //if (firstSound == 1){ // engine sound is still playing and phasers are firing...
            //  audio.play("Phaser.wav"); // ... play Phaser soundFX
            //}
            phaserStartMillis = millis();
          }


          if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
            phaserState = 1;
          } else {
            startBurst = 0;
            if (phaserBurst > 0) {
              phaserState = 0;
              if (firstSound == 0) {
                //audio.stopPlayback ();
              }
            }
          }
        }


        if (phaserState == 1) {  // if phasers are active then update phaser flash
          phaserLights.update();
        } else {
          digitalWrite(phaserPin, 0);  // otherwise switch phasers off
        }
      }


      digitalWrite(photonPin2, 0);  // turn off torpedo #2
      photonTorpedo2 = 0;           // done firing torpedo #2
      photonState = 0;              // photon torpedo effect is completed
      while (audio.isPlaying() > 0 and firstSound == 1) {
        strobeLights.update();
        navLights.update();

        // Check for Phaser Button Press
        phaserState = digitalRead(phaserButton);
        if (phaserState == 1 and startBurst == 0) {
          startBurst = 1;
          if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
            audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
          }
          phaserStartMillis = millis();
        }
        if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
          phaserState = 1;
        } else {
          startBurst = 0;
          if (phaserBurst > 0) {
            phaserState = 0;
            if (firstSound == 0) {
              //audio.stopPlayback ();
            }
          }
        }
      }
    }
  }

  // THE PHASER EFFECT
  // The following code debounces the phaser button, then activates or deactivates the phaser firing accordingly
  int reading = digitalRead(phaserButton);
  if (reading != lastPhaserState) {  // if switch state changed....
    lastDebounceTime = millis();     // .. reset debounce timer
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {  // if reading has been there for longer than the debounce delay...
    phaserState = reading;                              // ... change phaser state to the button state
  }
  if (phaserState == 1 and startBurst == 0) {
    startBurst = 1;
    if (firstSound == 1) {              // engine sound is still playing and phasers are firing...
      audio.play((char*)"Phaser.wav");  // ... play Phaser soundFX
    }
    phaserStartMillis = millis();
  }
  lastPhaserState = reading;  // this variable is used to check switch state change & initiate the debounce process above
  if (phaserBurst > 0 and millis() < (phaserStartMillis + phaserBurst)) {
    phaserState = 1;
  } else {
    startBurst = 0;
    if (phaserBurst > 0) {
      phaserState = 0;
      if (firstSound == 1) {
        audio.stopPlayback();
      }
    }
  }

  // THE RED ALERT EFFECT
  redState = digitalRead(redSwitch);
  if (redState == 1) {
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, 255 - 127 * lightsOff);  // Activate pin 7 of Shift Register; keep floodlights on
    digitalWrite(latchPin, HIGH);
    digitalWrite(phaserPin, 0);  // switch phasers off
    phaserState = 0;
    audio.play((char*)"alert10.wav");  // ... play Red Alert soundFX
    redStartMillis = millis();
    while (millis() < (redStartMillis + redLength)) {  // Delay while Red Alert runs
      strobeLights.update();
      navLights.update();
    }
    digitalWrite(latchPin, LOW);                             // Red Alert over, return to normal
    shiftOut(dataPin, clockPin, MSBFIRST, 127 + lightsOff);  // Switch off pin 7 if floodlights are on; keep pin 7 on if floodlights are off
    digitalWrite(latchPin, HIGH);

    if (lightsOff == 1) {
      dryDockStack = 1;
      for (dryDockCounter = 0; dryDockCounter < 7; dryDockCounter += 1) {
        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, MSBFIRST, dryDockStack + 128 * (dryDockCounter < 4));
        digitalWrite(latchPin, HIGH);
        dryDockStack = dryDockStack * 2 + 1;
        for (int deLay1 = 0; deLay1 < 30000; deLay1 += 1) {  // Pause between floodlights
          strobeLights.update();
          navLights.update();
          if (firstSound == 0) {
            //audio.stopPlayback ();
          }
        }
      }
    }
  }


}  // end of loop

You appear to have a MOSFET connected to pin 9... but nothing in your code refers to pin 9 ?

image

Where is the LED connected?

And here is the circuit for the "RED ALERT" led. It's in the center of the smaller bread board. It's the loan red led and push button:

Yep sorry missed that.

There's a lot going on in that circuit... did you try testing with just a few components?

Yes I did. It a YouTube tutorial and the original author of the sketch breaks up the sketch and circuit into several different videos. For example, the first video was on the "strobeLights" and navLights":


So when it came to the sound effects, it was a separate video with just the "audio" circuit. Then he adds the "audio" sketch to the "complete" sketch and the circuitry to the complete circuitry.

If you want to get a better understanding of what I am doing, here is the guys YouTube sight:

And how does that button work. Connections seem strange to me...

Is your power supply sufficient to deliver power to that speaker?
Is it 8 ohm?
It will be quite noisy...

What happens if you connect any of the uln inputs to 5V or ground? Does that light the LED? That woukd prove the uln is ok.

Can you measure the voltage of these inputs during normal operation? That would show if everything before usb is ok.

Hi,
Can you please post some images of your project so we can see your component layout.

Can you please post a schematic, not a Fritzy.
Reverse engineer your project and DRAW a circuit diagram and post an image of it.
Please include your power supply and component names and pin labels.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Did you do that bit of the project in stages like he did, so each stage works, BEFORE connecting everything up.
OR did you just connect everything up as in the last segment of the videos and just load the final code.

If so can I suggest you go back to the tutorial and do all the steps to make sure your hardware connected and can be software controlled.

Tom.... :smiley: :+1: :coffee: :australia:

I built this circuit and NEVER got the red alert to run properly. I had to rewrite the whole sequence. And I don't code, so it was a lot of trial and error. I also changed to a DFPlayer, then finally to an Adafruit sound card, as the sound quality from the SD Card adapter was very poor.

And then my model flew off the shelf (the power units done broke) so I am building another, but I am intending to re-do the circuit. (I even designed a few PCBs to help organize the thing. But I always missed something). My major problem was using negative ground- and with NPN transistors and MOSFETS, the circuit called for positive common. So, eventually, it only half worked before the ship was destroyed. Doing it properly, now.

How are you doing with yours?

The two circuit boards on the left are independent from the ATMega328, Darlington transistor and shift register. Each one runs a separate 6 LED chaser circuit off of the 12VDC power supply. It works fine.

The bottom left board holds the ATMega328P chip and the upper left board mounts the Darlington transistor and shift register.