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

Dependencies:   SDFileSystem mbed BillyBass

main.cpp

Committer:
bikeNomad
Date:
2013-06-19
Revision:
13:c13b3db9649b
Parent:
12:1206e56712d8
Child:
14:79b3fd23c7b5

File content as of revision 13:c13b3db9649b:

#include "billybass.hpp"
#include "SDFileSystem.h"
#include "song.hpp"
#include "player.hpp"
#include "action.hpp"

//                 tailPin,  mouthPin, bodyPin   inverted
// BillyBass testBass(LED_RED, LED_GREEN, LED_BLUE, true);

//                 tailPin,        mouthPin,      bodyPin
BillyBass bass1(BASS1_TAIL,     BASS1_MOUTH,   BASS1_BODY);
//                 tailPin,        mouthPin,      bodyPin
BillyBass bass2(BASS2_TAIL,     BASS2_MOUTH,   BASS2_BODY);
DigitalIn button1(BASS1_BUTTON);    // J3/4
DigitalIn button2(BASS2_BUTTON);   // J3/2

// Analog:
// GND   J3/14
// VrefH J3/16
AnalogOut speaker(PTE30);              // J10/11

//                 MOSI,    MISO,    SCLK,    CS, name
SDFileSystem sd(SD_MOSI, SD_MISO, SD_SCLK, SD_CS, SD_NAME);
Serial pc(USBTX, USBRX);

int main()
{
    SongPlayer player;
    pc.baud(SERIAL_BAUD);
    button1.mode(PullUp);
    button2.mode(PullUp);

    fprintf(stderr, "*** REBOOT ***\r\n");

    // read the directory
    DIR *bassDir = 0;
    while (!bassDir) {
        if ((bassDir = opendir(BASS_DIRECTORY)) != 0)
            break;
        pc.printf("Error opening " BASS_DIRECTORY "\r\n");
        wait(1.0);
    }

    while (dirent *d = readdir(bassDir)) {
        Song *song = Song::newSong(d->d_name);
        if (song) {
            fprintf(stderr, "Waiting to play %s\r\n", song->getSampleFileName());
            while (!(!button1 || !button2))
                wait(0.1);
            player.playEntireSong(song);
            fprintf(stderr, "total length: %f done: %u\r\n", player.timeInSong, player.actionsDone);
        }
    }
    closedir(bassDir);
    fprintf(stderr, "Done.\r\n");
}