Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:45d0e3e16b3a, 2020-04-21 (annotated)
- Committer:
- namcheol
- Date:
- Tue Apr 21 12:19:09 2020 +0000
- Revision:
- 1:45d0e3e16b3a
- Parent:
- 0:f31836d48420
lab03-pwm-music
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dshin | 0:f31836d48420 | 1 | #include "mbed.h" |
namcheol | 1:45d0e3e16b3a | 2 | #include "pitches.h" |
dshin | 0:f31836d48420 | 3 | |
namcheol | 1:45d0e3e16b3a | 4 | PwmOut buzzer(PTA1); //buzzer = PTA1 |
namcheol | 1:45d0e3e16b3a | 5 | int length = 56; |
namcheol | 1:45d0e3e16b3a | 6 | float frequency[] = {NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_B5, NOTE_D6, NOTE_C6, NOTE_A5, |
namcheol | 1:45d0e3e16b3a | 7 | NOTE_C5, NOTE_E5, NOTE_A5, NOTE_B5, |
namcheol | 1:45d0e3e16b3a | 8 | NOTE_E5, NOTE_GS5, NOTE_B5, NOTE_C6, |
namcheol | 1:45d0e3e16b3a | 9 | NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_B5, NOTE_D6,NOTE_C6, NOTE_A5, |
namcheol | 1:45d0e3e16b3a | 10 | NOTE_C5, NOTE_E5, NOTE_A5, NOTE_B5, |
namcheol | 1:45d0e3e16b3a | 11 | NOTE_E5, NOTE_GS5, NOTE_B5, NOTE_C6, |
namcheol | 1:45d0e3e16b3a | 12 | NOTE_B5, NOTE_C6, NOTE_D6, NOTE_E6, |
namcheol | 1:45d0e3e16b3a | 13 | NOTE_G5, NOTE_F6, NOTE_E6, NOTE_D6, |
namcheol | 1:45d0e3e16b3a | 14 | NOTE_F5, NOTE_E6, NOTE_D6, NOTE_C6, |
namcheol | 1:45d0e3e16b3a | 15 | NOTE_E5, NOTE_D6, NOTE_C6, NOTE_B5, |
namcheol | 1:45d0e3e16b3a | 16 | NOTE_E5, NOTE_E6}; |
namcheol | 1:45d0e3e16b3a | 17 | float beat[] = {12,12,12,12,12,12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 18 | 12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 19 | 12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 20 | 12,12,12,12,12,12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 21 | 12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 22 | 12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 23 | 12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 24 | 12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 25 | 12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 26 | 12,12,12,9, |
namcheol | 1:45d0e3e16b3a | 27 | 12,9}; |
dshin | 0:f31836d48420 | 28 | |
dshin | 0:f31836d48420 | 29 | |
dshin | 0:f31836d48420 | 30 | int main() |
dshin | 0:f31836d48420 | 31 | { |
namcheol | 1:45d0e3e16b3a | 32 | while(true) { |
namcheol | 1:45d0e3e16b3a | 33 | for(int i = 0; i <= length; i++) { |
namcheol | 1:45d0e3e16b3a | 34 | if(frequency[i] == 0) |
namcheol | 1:45d0e3e16b3a | 35 | buzzer = 0.0; |
namcheol | 1:45d0e3e16b3a | 36 | else { |
namcheol | 1:45d0e3e16b3a | 37 | buzzer.period(1.0 / frequency[i]); //period = (1.0 / frequency) |
namcheol | 1:45d0e3e16b3a | 38 | buzzer = 0.5; //duty cycle = 50% |
namcheol | 1:45d0e3e16b3a | 39 | } |
namcheol | 1:45d0e3e16b3a | 40 | thread_sleep_for(3500.0 / beat[i]); //duration = (C / beat)ms |
namcheol | 1:45d0e3e16b3a | 41 | } |
dshin | 0:f31836d48420 | 42 | } |
dshin | 0:f31836d48420 | 43 | } |