![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
PwmBeepライブラリのデモプログラムです。
main.cpp@0:b9598f69d256, 2020-05-22 (annotated)
- Committer:
- hmizuno
- Date:
- Fri May 22 08:40:07 2020 +0000
- Revision:
- 0:b9598f69d256
first release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hmizuno | 0:b9598f69d256 | 1 | #include "mbed.h" |
hmizuno | 0:b9598f69d256 | 2 | #include "PwmBeep.h" |
hmizuno | 0:b9598f69d256 | 3 | |
hmizuno | 0:b9598f69d256 | 4 | //ポートには数キロΩの抵抗を通して圧電スピーカーを接続してください。 |
hmizuno | 0:b9598f69d256 | 5 | PwmBeep beep(p22); |
hmizuno | 0:b9598f69d256 | 6 | |
hmizuno | 0:b9598f69d256 | 7 | int main() { |
hmizuno | 0:b9598f69d256 | 8 | while(1) { |
hmizuno | 0:b9598f69d256 | 9 | beep.turnOn(); |
hmizuno | 0:b9598f69d256 | 10 | wait(1.0); |
hmizuno | 0:b9598f69d256 | 11 | beep.turnOff(); |
hmizuno | 0:b9598f69d256 | 12 | wait(1.0); |
hmizuno | 0:b9598f69d256 | 13 | |
hmizuno | 0:b9598f69d256 | 14 | beep.setFreq(1250); |
hmizuno | 0:b9598f69d256 | 15 | |
hmizuno | 0:b9598f69d256 | 16 | //別の処理が進む |
hmizuno | 0:b9598f69d256 | 17 | beep.NshotOn(2, 0.4, 0.1); |
hmizuno | 0:b9598f69d256 | 18 | wait(0.2); |
hmizuno | 0:b9598f69d256 | 19 | |
hmizuno | 0:b9598f69d256 | 20 | beep.setFreq(1500); //NshotOnの途中で実行される |
hmizuno | 0:b9598f69d256 | 21 | wait(1.0); |
hmizuno | 0:b9598f69d256 | 22 | |
hmizuno | 0:b9598f69d256 | 23 | beep.setFreq(1250); |
hmizuno | 0:b9598f69d256 | 24 | |
hmizuno | 0:b9598f69d256 | 25 | //別の処理が止まる |
hmizuno | 0:b9598f69d256 | 26 | beep.NshotOnwithWait(2, 0.4, 0.1); |
hmizuno | 0:b9598f69d256 | 27 | wait(0.2); |
hmizuno | 0:b9598f69d256 | 28 | |
hmizuno | 0:b9598f69d256 | 29 | beep.setFreq(2000); //NshotOnwithWait終了後実行される |
hmizuno | 0:b9598f69d256 | 30 | |
hmizuno | 0:b9598f69d256 | 31 | beep.oneshotOn(0.1); |
hmizuno | 0:b9598f69d256 | 32 | wait(0.2); |
hmizuno | 0:b9598f69d256 | 33 | |
hmizuno | 0:b9598f69d256 | 34 | beep.setFreq(1000); |
hmizuno | 0:b9598f69d256 | 35 | } |
hmizuno | 0:b9598f69d256 | 36 | } |