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

Dependencies:   mbed FATFileSystem

Fork of JBB_WavePlayer_test by Jksoft Blue mbed Board Developer

Committer:
jksoft
Date:
Mon May 12 14:45:42 2014 +0000
Revision:
0:e9f196d85a46
Child:
1:9681a1526ecb
First edition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:e9f196d85a46 1 #include "mbed.h"
jksoft 0:e9f196d85a46 2 #include "wave_player.h"
jksoft 0:e9f196d85a46 3 #include "SDFileSystem.h"
jksoft 0:e9f196d85a46 4
jksoft 0:e9f196d85a46 5 DigitalOut myled(LED1);
jksoft 0:e9f196d85a46 6 AnalogOut DACout(p18);
jksoft 0:e9f196d85a46 7 DigitalOut AMPEnable(p12);
jksoft 0:e9f196d85a46 8 DigitalIn SW1(p25);
jksoft 0:e9f196d85a46 9
jksoft 0:e9f196d85a46 10 wave_player waver(&DACout,&AMPEnable);
jksoft 0:e9f196d85a46 11 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
jksoft 0:e9f196d85a46 12
jksoft 0:e9f196d85a46 13 Ticker flipper;
jksoft 0:e9f196d85a46 14
jksoft 0:e9f196d85a46 15
jksoft 0:e9f196d85a46 16 void flip() {
jksoft 0:e9f196d85a46 17 static int old_sw = 1;
jksoft 0:e9f196d85a46 18 if((SW1 == 0)&&(old_sw == 1))
jksoft 0:e9f196d85a46 19 {
jksoft 0:e9f196d85a46 20 waver.set_s_stop();
jksoft 0:e9f196d85a46 21 }
jksoft 0:e9f196d85a46 22 old_sw = SW1;
jksoft 0:e9f196d85a46 23 }
jksoft 0:e9f196d85a46 24
jksoft 0:e9f196d85a46 25 void player(char* file_path)
jksoft 0:e9f196d85a46 26 {
jksoft 0:e9f196d85a46 27 FILE *wave_file;
jksoft 0:e9f196d85a46 28
jksoft 0:e9f196d85a46 29 wave_file=fopen(file_path,"r");
jksoft 0:e9f196d85a46 30 waver.play(wave_file);
jksoft 0:e9f196d85a46 31 fclose(wave_file);
jksoft 0:e9f196d85a46 32 }
jksoft 0:e9f196d85a46 33
jksoft 0:e9f196d85a46 34 int main() {
jksoft 0:e9f196d85a46 35 SW1.mode(PullUp);
jksoft 0:e9f196d85a46 36 wait(2.0);
jksoft 0:e9f196d85a46 37 flipper.attach(&flip, 0.1);
jksoft 0:e9f196d85a46 38 player("/sd/1.wav");
jksoft 0:e9f196d85a46 39 wait(0.5);
jksoft 0:e9f196d85a46 40 player("/sd/2.wav");
jksoft 0:e9f196d85a46 41 wait(0.5);
jksoft 0:e9f196d85a46 42 player("/sd/3.wav");
jksoft 0:e9f196d85a46 43 wait(0.5);
jksoft 0:e9f196d85a46 44 player("/sd/4.wav");
jksoft 0:e9f196d85a46 45 wait(0.5);
jksoft 0:e9f196d85a46 46 player("/sd/5.wav");
jksoft 0:e9f196d85a46 47 wait(0.5);
jksoft 0:e9f196d85a46 48 player("/sd/6.wav");
jksoft 0:e9f196d85a46 49 wait(0.5);
jksoft 0:e9f196d85a46 50 player("/sd/7.wav");
jksoft 0:e9f196d85a46 51 wait(0.5);
jksoft 0:e9f196d85a46 52 player("/sd/8.wav");
jksoft 0:e9f196d85a46 53 wait(0.5);
jksoft 0:e9f196d85a46 54 player("/sd/9.wav");
jksoft 0:e9f196d85a46 55 wait(0.5);
jksoft 0:e9f196d85a46 56 player("/sd/10.wav");
jksoft 0:e9f196d85a46 57 wait(0.5);
jksoft 0:e9f196d85a46 58 while(1) {
jksoft 0:e9f196d85a46 59 myled = 1;
jksoft 0:e9f196d85a46 60 wait(0.2);
jksoft 0:e9f196d85a46 61 myled = 0;
jksoft 0:e9f196d85a46 62 wait(0.2);
jksoft 0:e9f196d85a46 63 }
jksoft 0:e9f196d85a46 64 }