エレキジャック Web版 mbedで初めてのマイコン開発 メモリカードを使ったデータの読み書き<2/3> 音符データをSDから読み込んで音楽を鳴らすプログラムです。 音楽データはエレキジャックのサイトに置いてあります。 music.txt http://www.eleki-jack.com/arm/2010/12/mbed-6.html

Dependencies:   TextLCD mbed SDFileSystem

main.cpp

Committer:
sunifu
Date:
2011-02-04
Revision:
0:f0cd2b9de695

File content as of revision 0:f0cd2b9de695:

#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) ;
}