AUP_Lab6_Music
Dependencies: C12832 MMA7660 mbed
Fork of AUP_Lab5_MMA7660 by
Diff: main.cpp
- Revision:
- 3:640558c1c0d3
- Parent:
- 2:09ee85ab1717
diff -r 09ee85ab1717 -r 640558c1c0d3 main.cpp --- a/main.cpp Wed Jul 08 00:05:05 2015 +0000 +++ b/main.cpp Wed Jul 08 00:09:57 2015 +0000 @@ -1,17 +1,27 @@ #include "mbed.h" #include "C12832.h" +#include "MMA7660.h" -// 添加MMA7660库文件 -#include "MMA7660.h" +// 添加旋律播放相关文件 +#include "SongPlayer.h" + +// 旋律数据 +float note[18]= {1568.0,1396.9,1244.5,1244.5,1396.9,1568.0,1568.0,1568.0,1396.9, + 1244.5,1396.9,1568.0,1396.9,1244.5,1174.7,1244.5,1244.5, 0.0 + }; +float duration[18]= {0.48,0.24,0.72,0.48,0.24,0.48,0.24,0.24,0.24, + 0.24,0.24,0.24,0.24,0.48,0.24,0.48,0.48, 0.0 + }; PwmOut led(D5); DigitalIn button_up(A2); DigitalIn button_center(D4); DigitalIn button_down(A3); C12832 lcd(D11, D13, D12, D7, D10); +MMA7660 MMA(D14, D15); -// 初始化MMA7660 -MMA7660 MMA(D14, D15); +// 初始化D6引脚作为PWM用于驱动扬声器 +SongPlayer mySpeaker(D6); double brightness = 1.0; double brightness_inc = 0.1; @@ -21,7 +31,10 @@ int bt_flag = 0; lcd.cls(); led.write(brightness); - + + // 播放旋律 + mySpeaker.PlaySong(note,duration,0.05); + while (1) { bt_flag = 1; if(button_up==1) @@ -40,8 +53,6 @@ } lcd.locate(0, 0); lcd.printf("Brightness = %.1f\r\n", 1.0 - brightness); - - // 显示加速度计的测量结果 lcd.printf("x=%.2f y=%.2f z=%.2f", MMA.x(), MMA.y(), MMA.z()); wait(0.2); }