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:d3bf38c7423c, 2020-05-11 (annotated)
- Committer:
- namcheol
- Date:
- Mon May 11 13:42:59 2020 +0000
- Revision:
- 1:d3bf38c7423c
- Parent:
- 0:f31836d48420
lab05-app-shield-speaker
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dshin | 0:f31836d48420 | 1 | #include "mbed.h" |
| namcheol | 1:d3bf38c7423c | 2 | #include "C12832.h" |
| namcheol | 1:d3bf38c7423c | 3 | #include "pitches.h" |
| namcheol | 1:d3bf38c7423c | 4 | |
| namcheol | 1:d3bf38c7423c | 5 | C12832 lcd(D11, D13, D12, D7, D10); //lcd = (MOSI, SCK, RESET, A0, nCS) |
| namcheol | 1:d3bf38c7423c | 6 | PwmOut buzzer(PTA1); //buzzer = PTA1 |
| namcheol | 1:d3bf38c7423c | 7 | int length = 56; |
| dshin | 0:f31836d48420 | 8 | |
| namcheol | 1:d3bf38c7423c | 9 | float frequency[] = {NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_B5, NOTE_D6, NOTE_C6, NOTE_A5, |
| namcheol | 1:d3bf38c7423c | 10 | NOTE_C5, NOTE_E5, NOTE_A5, NOTE_B5, |
| namcheol | 1:d3bf38c7423c | 11 | NOTE_E5, NOTE_GS5, NOTE_B5, NOTE_C6, |
| namcheol | 1:d3bf38c7423c | 12 | NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_B5, NOTE_D6,NOTE_C6, NOTE_A5, |
| namcheol | 1:d3bf38c7423c | 13 | NOTE_C5, NOTE_E5, NOTE_A5, NOTE_B5, |
| namcheol | 1:d3bf38c7423c | 14 | NOTE_E5, NOTE_GS5, NOTE_B5, NOTE_C6, |
| namcheol | 1:d3bf38c7423c | 15 | NOTE_B5, NOTE_C6, NOTE_D6, NOTE_E6, |
| namcheol | 1:d3bf38c7423c | 16 | NOTE_G5, NOTE_F6, NOTE_E6, NOTE_D6, |
| namcheol | 1:d3bf38c7423c | 17 | NOTE_F5, NOTE_E6, NOTE_D6, NOTE_C6, |
| namcheol | 1:d3bf38c7423c | 18 | NOTE_E5, NOTE_D6, NOTE_C6, NOTE_B5, |
| namcheol | 1:d3bf38c7423c | 19 | NOTE_E5, NOTE_E6}; |
| namcheol | 1:d3bf38c7423c | 20 | float beat[] = {12,12,12,12,12,12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 21 | 12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 22 | 12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 23 | 12,12,12,12,12,12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 24 | 12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 25 | 12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 26 | 12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 27 | 12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 28 | 12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 29 | 12,12,12,9, |
| namcheol | 1:d3bf38c7423c | 30 | 12,9}; |
| dshin | 0:f31836d48420 | 31 | |
| dshin | 0:f31836d48420 | 32 | |
| dshin | 0:f31836d48420 | 33 | int main() |
| dshin | 0:f31836d48420 | 34 | { |
| namcheol | 1:d3bf38c7423c | 35 | lcd.cls(); |
| namcheol | 1:d3bf38c7423c | 36 | lcd.locate(0,6); |
| namcheol | 1:d3bf38c7423c | 37 | lcd.printf("Listen to speaker!"); |
| namcheol | 1:d3bf38c7423c | 38 | lcd.locate(0,16); |
| namcheol | 1:d3bf38c7423c | 39 | lcd.printf("For Elise~~~"); |
| namcheol | 1:d3bf38c7423c | 40 | while(true) { |
| namcheol | 1:d3bf38c7423c | 41 | for(int i = 0; i <= length; i++) { |
| namcheol | 1:d3bf38c7423c | 42 | if(frequency[i] == 0) |
| namcheol | 1:d3bf38c7423c | 43 | buzzer = 0.0; |
| namcheol | 1:d3bf38c7423c | 44 | else { |
| namcheol | 1:d3bf38c7423c | 45 | buzzer.period(1.0 / frequency[i]); //period = (1.0 / frequency) |
| namcheol | 1:d3bf38c7423c | 46 | buzzer = 0.5; //duty cycle = 50% |
| namcheol | 1:d3bf38c7423c | 47 | } |
| namcheol | 1:d3bf38c7423c | 48 | thread_sleep_for(3500.0 / beat[i]); //duration = (C / beat)ms |
| namcheol | 1:d3bf38c7423c | 49 | } |
| dshin | 0:f31836d48420 | 50 | } |
| dshin | 0:f31836d48420 | 51 | } |