Big Mouth Billy Bass player that takes raw wavefiles and decision list text files from an SD card

Dependencies:   SDFileSystem mbed BillyBass

Committer:
bikeNomad
Date:
Wed Jun 19 16:12:36 2013 +0000
Revision:
13:c13b3db9649b
Parent:
12:1206e56712d8
Child:
14:79b3fd23c7b5
added second bass; moved config.; works though outputs may be wrongly connected on my board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bikeNomad 5:5b846ef42702 1 #include "billybass.hpp"
bikeNomad 7:ce27f959813b 2 #include "SDFileSystem.h"
bikeNomad 5:5b846ef42702 3 #include "song.hpp"
bikeNomad 5:5b846ef42702 4 #include "player.hpp"
bikeNomad 5:5b846ef42702 5 #include "action.hpp"
bikeNomad 0:0944c3654ded 6
bikeNomad 13:c13b3db9649b 7 // tailPin, mouthPin, bodyPin inverted
bikeNomad 13:c13b3db9649b 8 // BillyBass testBass(LED_RED, LED_GREEN, LED_BLUE, true);
bikeNomad 0:0944c3654ded 9
bikeNomad 13:c13b3db9649b 10 // tailPin, mouthPin, bodyPin
bikeNomad 13:c13b3db9649b 11 BillyBass bass1(BASS1_TAIL, BASS1_MOUTH, BASS1_BODY);
bikeNomad 13:c13b3db9649b 12 // tailPin, mouthPin, bodyPin
bikeNomad 13:c13b3db9649b 13 BillyBass bass2(BASS2_TAIL, BASS2_MOUTH, BASS2_BODY);
bikeNomad 13:c13b3db9649b 14 DigitalIn button1(BASS1_BUTTON); // J3/4
bikeNomad 13:c13b3db9649b 15 DigitalIn button2(BASS2_BUTTON); // J3/2
bikeNomad 0:0944c3654ded 16
bikeNomad 0:0944c3654ded 17 // Analog:
bikeNomad 0:0944c3654ded 18 // GND J3/14
bikeNomad 0:0944c3654ded 19 // VrefH J3/16
bikeNomad 5:5b846ef42702 20 AnalogOut speaker(PTE30); // J10/11
bikeNomad 0:0944c3654ded 21
bikeNomad 13:c13b3db9649b 22 // MOSI, MISO, SCLK, CS, name
bikeNomad 13:c13b3db9649b 23 SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS, SD_NAME);
bikeNomad 0:0944c3654ded 24 Serial pc(USBTX, USBRX);
bikeNomad 0:0944c3654ded 25
bikeNomad 0:0944c3654ded 26 int main()
bikeNomad 0:0944c3654ded 27 {
bikeNomad 3:00b4c1aadd30 28 SongPlayer player;
bikeNomad 5:5b846ef42702 29 pc.baud(SERIAL_BAUD);
bikeNomad 13:c13b3db9649b 30 button1.mode(PullUp);
bikeNomad 13:c13b3db9649b 31 button2.mode(PullUp);
bikeNomad 7:ce27f959813b 32
bikeNomad 8:1dd2bb31dec6 33 fprintf(stderr, "*** REBOOT ***\r\n");
bikeNomad 3:00b4c1aadd30 34
bikeNomad 0:0944c3654ded 35 // read the directory
bikeNomad 7:ce27f959813b 36 DIR *bassDir = 0;
bikeNomad 7:ce27f959813b 37 while (!bassDir) {
bikeNomad 7:ce27f959813b 38 if ((bassDir = opendir(BASS_DIRECTORY)) != 0)
bikeNomad 7:ce27f959813b 39 break;
bikeNomad 7:ce27f959813b 40 pc.printf("Error opening " BASS_DIRECTORY "\r\n");
bikeNomad 7:ce27f959813b 41 wait(1.0);
bikeNomad 7:ce27f959813b 42 }
bikeNomad 7:ce27f959813b 43
bikeNomad 9:99213347474f 44 while (dirent *d = readdir(bassDir)) {
bikeNomad 9:99213347474f 45 Song *song = Song::newSong(d->d_name);
bikeNomad 9:99213347474f 46 if (song) {
bikeNomad 13:c13b3db9649b 47 fprintf(stderr, "Waiting to play %s\r\n", song->getSampleFileName());
bikeNomad 13:c13b3db9649b 48 while (!(!button1 || !button2))
bikeNomad 13:c13b3db9649b 49 wait(0.1);
bikeNomad 9:99213347474f 50 player.playEntireSong(song);
bikeNomad 13:c13b3db9649b 51 fprintf(stderr, "total length: %f done: %u\r\n", player.timeInSong, player.actionsDone);
bikeNomad 9:99213347474f 52 }
bikeNomad 9:99213347474f 53 }
bikeNomad 8:1dd2bb31dec6 54 closedir(bassDir);
bikeNomad 13:c13b3db9649b 55 fprintf(stderr, "Done.\r\n");
bikeNomad 0:0944c3654ded 56 }
bikeNomad 8:1dd2bb31dec6 57