エレキジャック Web版 mbedで初めてのマイコン開発 メモリカードを使ったデータの読み書き<2/3> 音符データをSDから読み込んで音楽を鳴らすプログラムです。 音楽データはエレキジャックのサイトに置いてあります。 music.txt http://www.eleki-jack.com/arm/2010/12/mbed-6.html
Dependencies: TextLCD mbed SDFileSystem
Diff: main.cpp
- Revision:
- 0:f0cd2b9de695
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 04 15:09:01 2011 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h" +#include "TextLCD.h" +#include "SDFileSystem.h" +#include "MySound.h" + +TextLCD lcd(p24, p26, p27, p28, p29, p30); +SDFileSystem sd(p5, p6, p7, p8, "sd") ; +MySound music(p21) ; + + +int main() { + char pitch ; + int scale; + char ln; + FILE *fp; + int n; + + if ( (fp = fopen("/sd/music.txt","r")) == NULL ) { + printf("Open Failed. \n") ; + return -1; + } + lcd.printf("Silent Night"); + + while( (n = fscanf(fp,"%c %d %c ",&pitch,&scale,&ln)) != EOF ){ + printf("%d %c %d %c\n",n,pitch,scale,ln); + music.play(pitch, scale, ln) ; + } + + fclose(fp) ; +}