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?