mbed/ARM 活用事例 第3章 SDカードを使ってファイルを操作するプログラムを作る
Dependencies: TextLCD mbed SDFileSystem
Revision 0:c743b6678d88, committed 2011-10-04
- Comitter:
- sunifu
- Date:
- Tue Oct 04 12:59:42 2011 +0000
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FATFileSystem.lib Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_unsupported/code/fatfilesystem/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MySound.cpp Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,125 @@ +// --- MySound.cpp --- +#include "MySound.h" + +MySound::MySound(PinName out) : _out(out){ + +} + +void MySound::play(char pn,int s, char l) +{ + double freq,f; + float length ; + int scale ; + int begin; + + switch(l){ + case 'W': + length = 4 ; + break ; + case 't': + length = 3; + break ; + case 'D': + length = 2 ; + break; + case 'Q': + length = 1; + break; + case 'q': + length = 1.5; + break; + case 'E': + length = 0.5; + break; + case 'S': + length = 0.25; + break; + case 'T': + length = 0.125; + break; + default: + length = 1; + } + + switch(pn){ + case 'a': + freq = 415.30469 ; + break; + case 'A': + freq = 440.0; + break ; + case 'b': + freq = 466.16876; + break; + case 'B': + freq = 493.88330; + break ; + case 'C': + freq = 261.62556; + break ; + case 'd': + freq = 277.18263; + break ; + case 'D': + freq = 293.66476; + break; + case 'e': + freq = 311.12698; + break ; + case 'E': + freq = 329.62755; + break ; + case 'F': + freq = 349.22823; + break; + case 'g': + freq = 369.99442; + break ; + case 'G': + freq = 391.99543; + break ; + case 'R': + freq = 0.0; + break ; + default: + freq = 440; + } + + switch ( s ){ + case 6: + f = freq * 4 ; + break; + case 5: + f = freq * 2 ; + break; + case 4: + f = freq; + break; + case 3: + f = freq / 2 ; + break; + case 2: + f = freq / 4; + break; + default: + f = freq ; + break ; + } + + scale = (int)((1.0/f)*1e6) ; + _out.period_us(scale); + + t.start(); + begin = t.read_ms() ; + if ( pn != 'R' ){ + while(t.read_ms()-begin < (int)(500 * length) ){ + _out.write(0.5f); + } + }else{ + while(t.read_ms()-begin < (int)(500 * length) ){ + _out.write(0.0f); + } + } + t.stop(); + t.reset(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MySound.h Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,20 @@ +// --- MySound.h --- +#ifndef MBED_MY__SOUND_H +#define MBED_MY__SOUND_H + +#include "mbed.h" + +class MySound { + +public : + MySound(PinName out); + + void play(char,int,char); + +protected: + PwmOut _out; + Timer t; +}; + +#endif +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/SDFileSystem/#b1ddfc9a9b25
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,40 @@ +#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 , ln; + int scale; + FILE *fp; + int n; + + lcd.cls(); + if ( (fp = fopen("/sd/summer.txt","r")) == NULL ) { + lcd.printf("Open Failed.") ; + return -1; + } + + lcd.locate(2,0); + lcd.putc(0xC5); + lcd.putc(0xC2); + lcd.putc(0xC9); + lcd.putc(0xB5); + lcd.putc(0xD3); + lcd.putc(0xB2); + lcd.putc(0xC3); + lcd.putc(0xDE); + + while( (n = fscanf(fp,"%c %d %c ",&pitch,&scale,&ln)) != EOF ){ + printf("%d %c %d %c \r\n",n,pitch,scale,ln); + music.play(pitch, scale, ln) ; + } + fclose(fp) ; + + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/silentnight.h Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,48 @@ +G 4 q +A 4 E +G 4 Q +E 4 t +G 4 q +A 4 E +G 4 Q +E 4 t +D 5 D +D 5 Q +B 4 t +C 5 D +C 5 Q +G 4 t +A 4 D +A 4 Q +C 5 q +B 4 E +A 4 Q +G 4 q +A 4 E +G 4 Q +E 4 t +A 4 D +A 4 Q +C 5 q +B 4 E +A 4 Q +G 4 q +A 4 E +G 4 Q +E 4 t +D 5 D +D 5 Q +F 5 q +D 5 E +B 4 Q +C 5 t +E 5 t +C 5 Q +G 4 Q +E 4 Q +G 4 q +F 4 E +D 4 Q +C 4 t +C 4 t +R 4 Q
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/summer.h Tue Oct 04 12:59:42 2011 +0000 @@ -0,0 +1,104 @@ +E 4 E +E 4 E +F 4 E +G 4 Q +F 4 E +E 4 E +D 4 E +D 4 E +D 4 E +E 4 E +F 4 Q +R 4 Q +E 4 E +E 4 E +E 4 E +F 4 E +G 4 E +F 4 E +F 4 Q +E 4 Q +D 4 E +D 4 E +C 4 Q +R 4 Q +E 4 E +E 4 E +F 4 E +G 4 Q +F 4 E +E 4 E +D 4 E +D 4 E +D 4 E +E 4 E +F 4 Q +R 4 Q +E 4 E +E 4 E +E 4 E +F 4 E +G 4 E +F 4 E +F 4 Q +E 4 E +E 4 E +D 4 E +D 4 E +C 4 q +R 4 Q +A 5 E +A 5 E +A 5 E +B 5 E +C 5 Q +B 5 E +A 5 E +B 5 E +G 4 E +R 5 Q +G 4 E +A 5 E +F 4 E +R 4 D +G 4 E +G 4 E +G 4 E +G 4 E +G 4 S +G 4 S +G 4 S +F 4 E +E 4 E +F 4 Q +F 4 E +E 4 E +D 4 E +E 4 E +F 4 Q +R 4 Q +E 4 E +E 4 E +E 4 E +F 4 E +G 4 Q +F 4 E +E 4 E +D 4 E +D 4 E +D 4 E +E 4 E +F 4 q +R 4 Q +E 4 E +E 4 E +E 4 E +G 4 E +B 5 E +A 5 E +A 5 Q +A 4 Q +B 4 E +D 4 E +C 4 D +R 4 Q