microSDカードからWaveファイルを再生するサンプルです。

Dependencies:   mbed FATFileSystem

main.cpp

Committer:
jksoft
Date:
2014-05-12
Revision:
0:e9f196d85a46

File content as of revision 0:e9f196d85a46:

#include "mbed.h"
#include "wave_player.h"
#include "SDFileSystem.h"

DigitalOut myled(LED1);
AnalogOut DACout(p18);
DigitalOut AMPEnable(p12);
DigitalIn SW1(p25);

wave_player waver(&DACout,&AMPEnable);
SDFileSystem sd(p5, p6, p7, p8, "sd");  //SD card

Ticker flipper;


void flip() {
    static int old_sw = 1;
    if((SW1 == 0)&&(old_sw == 1))
    {
        waver.set_s_stop();
    }
    old_sw = SW1;
}

void player(char* file_path)
{
    FILE *wave_file;
    
    wave_file=fopen(file_path,"r");
    waver.play(wave_file);
    fclose(wave_file);
}

int main() {
    SW1.mode(PullUp);
    wait(2.0);
    flipper.attach(&flip, 0.1);
    player("/sd/1.wav");
    wait(0.5);
    player("/sd/2.wav");
    wait(0.5);
    player("/sd/3.wav");
    wait(0.5);
    player("/sd/4.wav");
    wait(0.5);
    player("/sd/5.wav");
    wait(0.5);
    player("/sd/6.wav");
    wait(0.5);
    player("/sd/7.wav");
    wait(0.5);
    player("/sd/8.wav");
    wait(0.5);
    player("/sd/9.wav");
    wait(0.5);
    player("/sd/10.wav");
    wait(0.5);
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}