Using the PAD Sound Board to Simulate Blaster Fire

Using the PAD Sound Board to Simulate Blaster Fire

This code is used by our board to control Neopixels ( WS2812B) LEDS mounted on a light bar inside of your blaster to simulate a laser blast firing along the inside.  It was developed to control the lights and sounds in our E-11D Blaster Kit.

You will need to also download the libraries for the DF Player (DFRobotDFPlayerMini.h) and the control for WS2812B LEDs (FastLED.h). These libraries can be found on Github.

 

The Arduino Code

--------------------------------------------------------


/***************************************************
Indexed LED E-11 blaster code

Plastic Arms Dealer Sound and Light Board
V2
December 2020
Andrew McClary
Copyright 2020 All Rights Reserved

UPDATES:
- Added in 3 neopixel strings with independent control
****************************************************/

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "FastLED.h"

//Setup serial connection to DF Player for audio control
SoftwareSerial mySoftwareSerial(8,9); // RX, TX
DFRobotDFPlayerMini myDFPlayer;

//Define all the LED strips
#define NUM_LEDS 2//small port
#define DATA_PIN 5
CRGB leds[NUM_LEDS];

#define NUM_LEDS2 6//large port
#define DATA_PIN2 11
CRGB leds2[NUM_LEDS2];

#define NUM_LEDS3 23//barrel
#define DATA_PIN3 6
CRGB leds3[NUM_LEDS3];

#define NUM_LEDS4 23//barrel
#define DATA_PIN4 7
CRGB leds4[NUM_LEDS4];

#define DATA_PINLaser 4 //laser

void printDetail(uint8_t type, int value);

int triggerButton = 12; //the pin where we connect the trigger button

int fireSound = 1;
int voiceSound = 1;


void setup()
{

mySoftwareSerial.begin(9600); //DF player communications
//Serial.begin(115200); //Debugging communications



// Setup and activate the LED Strips
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);
FastLED.addLeds<NEOPIXEL, DATA_PIN3>(leds3, NUM_LEDS3);
FastLED.addLeds<NEOPIXEL, DATA_PIN4>(leds3, NUM_LEDS3);

//setup laser pin out
pinMode(DATA_PINLaser, OUTPUT); //set the LED pin as OUTPUT

//Initialize and setup DF MP3 player
//Serial.println();
//Serial.println(F("Plastic Arms Dealer Blaster Sound System V beta 1"));
//Serial.println(F("Initializing Sound Player ... (May take 3~5 seconds)"));

if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3.
//Serial.println(F("Unable to begin:"));
//Serial.println(F("1.Please recheck the connection!"));
//Serial.println(F("2.Please insert the SD card!"));
while(true);
}
//Serial.println(F("Plastic Arms Dealer Blaster Sound System online."));
//Serial.println(F("Folder 1."));
//Serial.println(myDFPlayer.readFileCountsInFolder(1)); //read fill counts in folder SD:/1
//Serial.println(F("Folder 2"));
//Serial.println(myDFPlayer.readFileCountsInFolder(2)); //read fill counts in folder SD:/03
//Serial.println(F("Folder 3"));
//Serial.println(myDFPlayer.readFileCountsInFolder(3)); //read fill counts in folder SD:/03
myDFPlayer.volume(30); //Set volume value. From 0 to 30

//Play startup sound
myDFPlayer.playLargeFolder(03, 1);;


//Put the LEDS in startup mode
FastLED.setBrightness(20);
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot] = CRGB::Yellow;
FastLED.show();
// clear this led for the next time around the loop
//leds[dot] = CRGB::Black;
}

for(int dot = 0; dot < NUM_LEDS2; dot++) {
leds2[dot] = CRGB::Red;
FastLED.show();
// clear this led for the next time around the loop
//leds2[dot] = CRGB::Black;
delay(200);
}
//Test the barrel
for(int dot = 0; dot < NUM_LEDS3; dot++) {
leds3[dot] = CRGB::Blue;
FastLED.show();
// clear this led for the next time around the loop

delay(50);
}
for(int dot = 0; dot < NUM_LEDS3; dot++) {
leds3[dot] = CRGB::Black;
FastLED.show();
delay(100);
}
//Setup the buttons
pinMode(triggerButton, INPUT_PULLUP); //set the button pin as INPUT


}


//This is the main control code
void loop()
{
static unsigned long timer = millis();

int stateButton = digitalRead(triggerButton); //read the state of the button

//Check for Fire button
if(stateButton == LOW) { //if is pressed
//Serial.println(F("Fire button Pressed"));

//Play the sound file
myDFPlayer.playLargeFolder(02, fireSound);
printDetail(myDFPlayer.readType(), myDFPlayer.read());


//*****Fire the Blaster****

//cycle back port
for(int dot = 0; dot < NUM_LEDS2; dot++) {
leds2[dot] = CRGB::Black;
FastLED.show();
// clear this led for the next time around the loop
//leds2[dot] = CRGB::Black;
}
for(int dot = NUM_LEDS2; dot > 0; dot--) {
leds2[dot] = CRGB::Red;
FastLED.show();
// clear this led for the next time around the loop

leds2[dot] = CRGB::Black;
delay(20);
}

//Turn small port white
FastLED.setBrightness(100);
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot] = CRGB::White;
FastLED.show();
// clear this led for the next time around the loop
//leds[dot] = CRGB::Black;
delay(5);
}




for(int dot = 0; dot < NUM_LEDS3; dot++) {
leds3[dot] = CRGB::Red;
FastLED.show();
// clear this led for the next time around the loop
leds3[dot] = CRGB::Black;
delay(5);
}

//Flash the laser
digitalWrite(DATA_PINLaser, HIGH); //write 1 or HIGH to led pin
delay(200);
digitalWrite(DATA_PINLaser, LOW); //write 1 or HIGH to led pin
delay(100);


//**Reset the side pannels

FastLED.setBrightness(20);
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot] = CRGB::Yellow;
FastLED.show();
// clear this led for the next time around the loop
//leds[dot] = CRGB::Black;

}

for(int dot = 0; dot < NUM_LEDS2; dot++) {
leds2[dot] = CRGB::Red;
FastLED.show();
// clear this led for the next time around the loop
//leds2[dot] = CRGB::Black;
}


//***End fire sequence***


//Change the blaster sound to the next in the list
fireSound++;
//Serial.print("Fire Button Pressed - ");
//Serial.print(fireSound);
if (fireSound >= 10){
fireSound = 1;
}
}



} //END Loop


//DF Player Errors List
void printDetail(uint8_t type, int value){
switch (type) {
case TimeOut:
//Serial.println(F("Time Out!"));
break;
case WrongStack:
//Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
//Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
//Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
//Serial.println(F("Card Online!"));
break;
case DFPlayerPlayFinished:
//Serial.print(F("Number:"));
//Serial.print(value);
//Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
//Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
//Serial.println(F("Card not found"));
break;
case Sleeping:
//Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
//Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
//Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
//Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
//Serial.println(F("Cannot Find File"));
break;
case Advertise:
//Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}
}

----------------------------------------------------------