スイッチを押すと0001.mp3が再生されます
Dependencies: mbed DFPlayerMini
main.cpp@1:ecebe54ee6e1, 2021-06-17 (annotated)
- Committer:
- kohacraft
- Date:
- Thu Jun 17 23:48:24 2021 +0000
- Revision:
- 1:ecebe54ee6e1
- Parent:
- 0:b28d453ebc93
ver1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kohacraft | 0:b28d453ebc93 | 1 | #include "mbed.h" |
kohacraft | 0:b28d453ebc93 | 2 | #include "DFPlayerMini.h" |
kohacraft | 0:b28d453ebc93 | 3 | |
kohacraft | 0:b28d453ebc93 | 4 | DigitalOut myled(LED1); //LED |
kohacraft | 0:b28d453ebc93 | 5 | DigitalIn sw(dp1); //再生ボタン |
kohacraft | 0:b28d453ebc93 | 6 | |
kohacraft | 0:b28d453ebc93 | 7 | DFPlayerMini mp3(dp16, dp15); |
kohacraft | 0:b28d453ebc93 | 8 | DigitalIn busy(dp17); //DFPlayerMiniのBUSYと接続する |
kohacraft | 0:b28d453ebc93 | 9 | |
kohacraft | 0:b28d453ebc93 | 10 | int main() { |
kohacraft | 0:b28d453ebc93 | 11 | mp3.mp3_set_volume(30); //再生音量を設定する30が最大 |
kohacraft | 0:b28d453ebc93 | 12 | |
kohacraft | 0:b28d453ebc93 | 13 | while(1) |
kohacraft | 0:b28d453ebc93 | 14 | { |
kohacraft | 0:b28d453ebc93 | 15 | if( sw == 1 ) |
kohacraft | 0:b28d453ebc93 | 16 | { |
kohacraft | 0:b28d453ebc93 | 17 | myled = 1; //LED点灯 |
kohacraft | 0:b28d453ebc93 | 18 | mp3.mp3_play(0001); //0001.mp3を再生 |
kohacraft | 0:b28d453ebc93 | 19 | wait(0.1); |
kohacraft | 0:b28d453ebc93 | 20 | |
kohacraft | 0:b28d453ebc93 | 21 | //再生が終わるまで待つ |
kohacraft | 0:b28d453ebc93 | 22 | while( busy == 0 ) |
kohacraft | 0:b28d453ebc93 | 23 | { |
kohacraft | 0:b28d453ebc93 | 24 | wait(0.1); |
kohacraft | 0:b28d453ebc93 | 25 | } |
kohacraft | 0:b28d453ebc93 | 26 | } |
kohacraft | 0:b28d453ebc93 | 27 | |
kohacraft | 0:b28d453ebc93 | 28 | //LEDを点滅させる |
kohacraft | 0:b28d453ebc93 | 29 | myled = !myled; |
kohacraft | 0:b28d453ebc93 | 30 | wait(0.2); |
kohacraft | 0:b28d453ebc93 | 31 | } |
kohacraft | 0:b28d453ebc93 | 32 | } |