Daniel_Haro
Published © GPL3+

Sound Effects for Dok-Ondar's Lightsaber Box

Add sound effects to opening the box and lifting the lightsaber.

IntermediateShowcase (no instructions)2,077
Sound Effects for Dok-Ondar's Lightsaber Box

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
Arduino UNO is what I used.
×1
Adafruit Music Maker Shield
×1
3 Watt 8 Ohm Speaker
These are the speakers I used but they do not have to be the same
×1
Resistor 1k ohm
Resistor 1k ohm
×2
Microswitch, Roller Lever
Microswitch, Roller Lever
Solder a piece of wire to the common leg and another piece of wire to the NO leg
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Male/Male Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE
Audacity
I used this to edit the audio files for the project, not necessary.

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
PCB Holder, Soldering Iron
PCB Holder, Soldering Iron
This is not necessary but it helps to solder the pins and wires.

Story

Read more

Schematics

Finale Diagram

In the diagram, only the shield is shown, this is because the shield is stacked on top of the arduino.

Code

Finale.ino

Arduino
// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

//This part of the code is from the example in the Adafruit library. I just copied and pasted it, I don't really know what it does but it makes the code work.
// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = 
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

//Adds names to the pins for clarity
int button = 8;
int buttonVal = 0;
int done = 0;
int forceSensor = A0;
int forceVal = 0;
int musicPlaying = 0;
  
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(button, INPUT);

//Checks if any errors happen
  if(!musicPlayer.begin()){
    Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
    while (1);
    }
  Serial.println(F("VS1053 found"));
  
  if (!SD.begin(CARDCS)){
    Serial.println(F("SD failed, or not present"));
    while (1);
    }
  else{
    Serial.println("SD Card Successful");
    }
}

void loop() {
  // put your main code here, to run repeatedly:

  //Any Serial.print code is only used for debugging.
  buttonVal = digitalRead(button);
  forceVal = analogRead(forceSensor);
  Serial.print("ForceVal: ");
  Serial.print(forceVal);
  Serial.print(" ButtonVal: ");
  Serial.print(buttonVal);
  Serial.print(" Done: ");
  Serial.println(done);
  delay(500);

  //Checks if the box is closed and the lightsaber is in place. If it is, play the opening music
  //The values for forceVal may vary, if it doesn't work, try changing the values to see what happens.
  if(buttonVal == HIGH && done == 0 && forceVal >= 50){
    done = 1;
    musicPlayer.setVolume(20,20);
    Serial.println("Playing Opening");
    musicPlayer.playFullFile("open2.mp3");
    delay(200);
    }

  //Checks if the lightsaber has been removed. If it is play the lifting music.
  if(forceVal <=50 && done == 1){
    done = 2;
    musicPlayer.setVolume(10,10);
    Serial.println("Playing Lifting");
    musicPlayer.playFullFile("lift4.mp3");
    delay(200);
    }

  //This resets everything so that it can happen again.
  if(forceVal >= 50 && done == 2 && buttonVal == LOW){
    done = 0;
    delay(200);
    }

}

Credits

Daniel_Haro

Daniel_Haro

0 projects • 1 follower

Comments