I have sorted out all of the pieces I will need and the code to be able to trigger the tracks using light sensors. HOWEVER, I have been hitting a lot of road blocks, one major one being that I am finding it difficult to find a 5V FTDI board that connects to the LilyPad. It’s time to call in the big guns (aka my tutors) to troubleshoot this.

I also cannot get my hands on the small speakers and will start to look into making fabric DIY speakers now instead.

Prototype 2 in the works. 1

This is the code that I am going to use once I sort out the FTDI to LilyPad connection issue:
void setup()
{
byte result;

// Use TRIG1 as an anlog input for our light sensor:

pinMode(TRIG1,INPUT);

// Use TRIG2 as a digital output that will be HIGH
// while we’re playing an audio file and LOW otherwise:

pinMode(TRIG2,OUTPUT);
digitalWrite(TRIG2,LOW);

// If serial port debugging is inconvenient, you can connect
// a LED to the red channel of the rotary encoder to blink
// startup error codes:

pinMode(ROT_LEDR,OUTPUT);
digitalWrite(ROT_LEDR,HIGH); // HIGH = off

// The board uses a single I/O pin to select the
// mode the MP3 chip will start up in (MP3 or MIDI),
// and to enable/disable the amplifier chip:

pinMode(EN_GPIO1,OUTPUT);
digitalWrite(EN_GPIO1,LOW); // MP3 mode / amp off

// If debugging is true, initialize the serial port:
// (The ‘F’ stores constant strings in flash memory to save RAM)

if (debugging)
{
Serial.begin(9600);
Serial.println(F(“Lilypad MP3 Player trigger sketch”));
}

// Initialize the SD card; SS = pin 9, half speed at first

if (debugging) Serial.print(F(“initialize SD card… “));

result = sd.begin(SD_CS, SPI_HALF_SPEED); // 1 for success

if (result != 1) // Problem initializing the SD card
{
if (debugging) Serial.print(F(“error, halting”));
errorBlink(1); // Halt forever, blink LED if present.
}
else
if (debugging) Serial.println(F(“success!”));

// Start up the MP3 library

if (debugging) Serial.print(F(“initialize MP3 chip… “));

result = MP3player.begin(); // 0 or 6 for success

// Check the result, see the MP3 library readme for error codes.

if ((result != 0) && (result != 6)) // Problem starting up
{
if (debugging)
{
Serial.print(F(“error code “));
Serial.print(result);
Serial.print(F(“, halting.”));
}
errorBlink(result); // Halt forever, blink red LED if present.
}
else
if (debugging) Serial.println(F(“success!”));

// Set the VS1053 volume. 0 is loudest, 255 is lowest (off):

MP3player.setVolume(10,10);

// Get baseline readings from the light sensor:

threshold = (analogRead(TRIG1));
if (debugging)
{
Serial.print(F(“measured threshold value: “));
Serial.println(threshold);
}

threshold = threshold * sensitivity;
if (debugging)
{
Serial.print(F(“modified threshold value: “));
Serial.println(threshold);
}

// Turn on the amplifier chip:

digitalWrite(EN_GPIO1,HIGH);
delay(2);
}
void loop()
{
byte result;
byte sensorvalue;

// Get the current light level (sensorvalue):

sensorvalue = analogRead(TRIG1);

if (debugging)
{
Serial.print(F(“sensor value: “));
Serial.print(sensorvalue);
Serial.print(F(” threshold: “));
Serial.println(threshold);
}

// Check to see whether we’re below the threshold

if (sensorvalue < threshold)
{
if(debugging)
{
Serial.println(F(“got a trigger!”));
}

// If we’re currently playing a file, let it finish (don’t start over)

if (MP3player.isPlaying())
{
if(debugging)
{
Serial.println(F(“…but we’re already playing”));
}
}
else
{
// Play the file!

result = MP3player.playMP3(filename);

// Print out error information for debugging

if(debugging)
{
if(result != 0)
{
Serial.print(F(“error “));
Serial.print(result);
Serial.print(F(” when trying to play track “));
}
else
{
Serial.print(F(“playing “));
}
Serial.println(filename);
}
}
}

// For fun, we’ll set TRIG2 HIGH while we’re playing a file,
// and LOW when the player is silent.

if (MP3player.isPlaying())
digitalWrite(TRIG2,HIGH);
else
digitalWrite(TRIG2,LOW);
}
void errorBlink(int blinks)
{
// The following function will blink the red LED in the rotary
// encoder (optional) a given number of times and repeat forever.
// This is so you can see any startup error codes without having
// to use the serial monitor window.

int x;

while(true) // Loop forever
{
for (x=0; x < blinks; x++) // Blink the given number of times
{
digitalWrite(ROT_LEDR,LOW); // Turn LED ON
delay(250);
digitalWrite(ROT_LEDR,HIGH); // Turn LED OFF
delay(250);
}
delay(1500); // Longer pause between blink-groups
}
}