SET YOUR POWER SUPPLY to 4.5 VOLTS or you will DESTROY the DAISY!!!!!!!
/* This sketch is for using the Daisy Mp3 player in Four Four mode with your Arduino.
Toggle through sound files using a pushbutton interface.
Each time the button is pushed, a new song plays.
IMPORTANT: All mp3 files must be labeled 00001.mp3, 00002.mp3... or they will not playback.
The sequence of sound files can be randomized.
See the Arduino Reference page to learn about random(): http://arduino.cc/en/Reference/Random
The Daisy Mp3 player will only work with an SD card, or a MMC card, that is formatted as FAT32.
My Macintosh computer performed this function using Disk Utilites, and erasing the card with MS-DOS format.
The SD card in the Daisy can be removed by gently pressing it inward (it then pops out). Gently depress the center of the card to transform it into a USB stick that you can insert into your USB port. Now you can upload your own sound files from your computer to the SD card.
Experiment with and modify the following code.
For example, try adding a distance sensor to trigger different sounds from different distances.
Change the number of tracks by playing with the math of the songcounter.
Access more infomration about the Daisy Mp3 player, and its manual, here: http://teuthis.com/daisy/index.html
*/
int songcounter =1;
int inPin = 2; // pushbutton connected to pin 2
int value = 0;
int Pin10 = 10; //arduino pin 10 goes to Daisy MP3 pin 0
int Pin9 = 9; //arduino pin 9 goes to Daisy MP3 pin 1
int Pin8 = 8; //arduino pin 8 goes to Daisy MP3 pin 2
int Pin7 = 7; //arduino pin 7 goes to Daisy MP3 pin 3
int Play11 = 11; //arduino pin 11 goes to Daisy MP3 B0
int trigger = 0;
void setup() //run once, when the sketch starts
{
pinMode (inPin, INPUT);
pinMode (Pin10, OUTPUT);
pinMode (Pin9, OUTPUT);
pinMode (Pin8, OUTPUT);
pinMode (Pin7, OUTPUT);
pinMode (Play11, OUTPUT);
Serial.begin(9600);
digitalWrite (Play11, HIGH); // so that it doesn't play on startup
}
void loop() //run over and over again
{ // Play track 0001
value = digitalRead(inPin);
Serial.println(songcounter);
if (value == 0){
if (trigger == 0){
songcounter++ ;
if (songcounter == 8){ // when the sketch starts, it will choose from 8 mp3 files.
songcounter = 1;
}
trigger = 1;
digitalWrite (Play11, HIGH);
delay(100);
}
}
else{
trigger = 0;
}
/* Notice in the code that each sound file has a unique id, defined by the configuration of four pins. Each of the four pin is set to HIGH or LOW. For example sound file 1 may be configured with all four pins LOW. Whereas the id for sound file six is set by assigning the four pins to this configuration: LOW, HIGH, LOW, LOW.*/
if (songcounter == 1){ // if the songcounter is equal to 1, set the four pins to the following configuration
digitalWrite(Pin10, LOW); // unique sound file id
digitalWrite(Pin9, LOW);
digitalWrite(Pin8, LOW);
digitalWrite(Pin7, LOW);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 2){ // if the songcounter is equal to 2, set the four pins to the following configuration
digitalWrite(Pin10, HIGH); // unique sound file id
digitalWrite(Pin9, LOW);
digitalWrite(Pin8, LOW);
digitalWrite(Pin7, LOW);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 3){ // if the songcounter is equal to 3, set the four pins to the following configuration
digitalWrite(Pin10, HIGH);
digitalWrite(Pin9, HIGH); // Dailsy MP3 Binary Track Choices
digitalWrite(Pin8, LOW);
digitalWrite(Pin7, LOW);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 4){ // if the songcounter is equal to 4, set the four pins to the following configuration
digitalWrite(Pin10, HIGH); // unique sound file id
digitalWrite(Pin9, HIGH);
digitalWrite(Pin8, HIGH);
digitalWrite(Pin7, LOW);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 5){ // if the songcounter is equal to 5, set the four pins to the following configuration
digitalWrite(Pin10, LOW); // unique sound file id
digitalWrite(Pin9, LOW);
digitalWrite(Pin8, HIGH);
digitalWrite(Pin7, LOW);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 6){ // if the songcounter is equal to 6, set the four pins to the following configuration
digitalWrite(Pin10, LOW); // unique sound file id
digitalWrite(Pin9, HIGH);
digitalWrite(Pin8, LOW);
digitalWrite(Pin7, LOW);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 7){ // if the songcounter is equal to 8, set the four pins to the following configuration
digitalWrite(Pin10, LOW); // unique sound file id
digitalWrite(Pin9, HIGH);
digitalWrite(Pin8, HIGH);
digitalWrite(Pin7, LOW);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 8){ // if the songcounter is equal to 8, set the four pins to the following configuration
digitalWrite(Pin10, LOW); // unique sound file id
digitalWrite(Pin9, HIGH);
digitalWrite(Pin8, LOW);
digitalWrite(Pin7, HIGH);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
*/ Add more sound files to the Daisy to enable up to 16 tracks. If you want to use the extra tracks, don't forget that you will need to modify the code for the number of possible tracks the songcounter will recognize. Do this under void loop(). /*
if (songcounter == 9){ // if the songcounter is equal to 9, set the four pins to the following configuration
digitalWrite(Pin10, LOW); // unique sound file id
digitalWrite(Pin9, HIGH);
digitalWrite(Pin8, HIGH);
digitalWrite(Pin7, HIGH);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 10){ // if the songcounter is equal to 10, set the four pins to the following configuration
digitalWrite(Pin10, HIGH); // unique sound file id
digitalWrite(Pin9, HIGH);
digitalWrite(Pin8, LOW);
digitalWrite(Pin7, HIGH);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 11){ // if the songcounter is equal to 11, set the four pins to the following configuration
digitalWrite(Pin10, HIGH); // unique sound file id
digitalWrite(Pin9, LOW);
digitalWrite(Pin8, HIGH);
digitalWrite(Pin7, HIGH);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 12){ // if the songcounter is equal to 12, set the four pins to the following configuration
digitalWrite(Pin10, LOW); // unique sound file id
digitalWrite(Pin9, LOW);
digitalWrite(Pin8, HIGH);
digitalWrite(Pin7, LOW);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
if (songcounter == 13){ // if the songcounter is equal to 13, set the four pins to the following configuration
digitalWrite(Pin10, HIGH); // unique sound file id
digitalWrite(Pin9, LOW);
digitalWrite(Pin8, LOW);
digitalWrite(Pin7, HIGH);
digitalWrite (Play11, LOW); // Play the above four pin configuration
}
}
Comments (0)
You don't have permission to comment on this page.