...
Dependencies: PWM_Tone_Library mbed
Fork of PiezoBuzzer_HelloWorld_WIZwiki-W7500 by
main.cpp@0:9d311e74ad13, 2015-07-24 (annotated)
- Committer:
- justinkim
- Date:
- Fri Jul 24 05:12:14 2015 +0000
- Revision:
- 0:9d311e74ad13
- Child:
- 1:42c374d89303
PiezoBuzzer_HelloWorld_WIZwiki-W7500
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
justinkim | 0:9d311e74ad13 | 1 | /* Includes ------------------------------------------------------------------*/ |
justinkim | 0:9d311e74ad13 | 2 | #include "mbed.h" |
justinkim | 0:9d311e74ad13 | 3 | #include "pwm_tone.h" |
justinkim | 0:9d311e74ad13 | 4 | |
justinkim | 0:9d311e74ad13 | 5 | /* Private typedef -----------------------------------------------------------*/ |
justinkim | 0:9d311e74ad13 | 6 | /* Private define ------------------------------------------------------------*/ |
justinkim | 0:9d311e74ad13 | 7 | /* Private variables ---------------------------------------------------------*/ |
justinkim | 0:9d311e74ad13 | 8 | PwmOut Buzzer(D5); |
justinkim | 0:9d311e74ad13 | 9 | |
justinkim | 0:9d311e74ad13 | 10 | float C_3 = 1000000/Do3, |
justinkim | 0:9d311e74ad13 | 11 | Cs_3 = 1000000/Do3s, |
justinkim | 0:9d311e74ad13 | 12 | D_3 = 1000000/Re3, |
justinkim | 0:9d311e74ad13 | 13 | Ds_3 = 1000000/Re3s, |
justinkim | 0:9d311e74ad13 | 14 | E_3 = 1000000/Mi3, |
justinkim | 0:9d311e74ad13 | 15 | F_3 = 1000000/Fa3, |
justinkim | 0:9d311e74ad13 | 16 | Fs_3 = 1000000/Fa3s, |
justinkim | 0:9d311e74ad13 | 17 | G_3 = 1000000/So3, |
justinkim | 0:9d311e74ad13 | 18 | Gs_3 = 1000000/So3s, |
justinkim | 0:9d311e74ad13 | 19 | A_3 = 1000000/La3, |
justinkim | 0:9d311e74ad13 | 20 | As_3 = 1000000/La3s, |
justinkim | 0:9d311e74ad13 | 21 | B_3 = 1000000/Ti3, |
justinkim | 0:9d311e74ad13 | 22 | C_4 = 1000000/Do4, |
justinkim | 0:9d311e74ad13 | 23 | Cs_4 = 1000000/Do4s, |
justinkim | 0:9d311e74ad13 | 24 | D_4 = 1000000/Re4, |
justinkim | 0:9d311e74ad13 | 25 | Ds_4 = 1000000/Re4s, |
justinkim | 0:9d311e74ad13 | 26 | E_4 = 1000000/Mi4, |
justinkim | 0:9d311e74ad13 | 27 | F_4 = 1000000/Fa4, |
justinkim | 0:9d311e74ad13 | 28 | Fs_4 = 1000000/Fa4s, |
justinkim | 0:9d311e74ad13 | 29 | G_4 = 1000000/So4, |
justinkim | 0:9d311e74ad13 | 30 | Gs_4 = 1000000/So4s, |
justinkim | 0:9d311e74ad13 | 31 | A_4 = 1000000/La4, |
justinkim | 0:9d311e74ad13 | 32 | As_4 = 1000000/La4s, |
justinkim | 0:9d311e74ad13 | 33 | B_4 = 1000000/Ti4, |
justinkim | 0:9d311e74ad13 | 34 | C_5 = 1000000/Do5, |
justinkim | 0:9d311e74ad13 | 35 | Cs_5 = 1000000/Do5s, |
justinkim | 0:9d311e74ad13 | 36 | D_5 = 1000000/Re5, |
justinkim | 0:9d311e74ad13 | 37 | Ds_5 = 1000000/Re5s, |
justinkim | 0:9d311e74ad13 | 38 | E_5 = 1000000/Mi5, |
justinkim | 0:9d311e74ad13 | 39 | F_5 = 1000000/Fa5, |
justinkim | 0:9d311e74ad13 | 40 | Fs_5 = 1000000/Fa5s, |
justinkim | 0:9d311e74ad13 | 41 | G_5 = 1000000/So5, |
justinkim | 0:9d311e74ad13 | 42 | Gs_5 = 1000000/So5s, |
justinkim | 0:9d311e74ad13 | 43 | A_5 = 1000000/La5, |
justinkim | 0:9d311e74ad13 | 44 | As_5 = 1000000/La5s, |
justinkim | 0:9d311e74ad13 | 45 | B_5 = 1000000/Ti5; |
justinkim | 0:9d311e74ad13 | 46 | |
justinkim | 0:9d311e74ad13 | 47 | int tones[] = {E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0, D_4, D_4, D_4, 0, E_4, G_4, G_4, 0, |
justinkim | 0:9d311e74ad13 | 48 | E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0, D_4, D_4, E_4, D_4, C_4, 0, 0, 0}; |
justinkim | 0:9d311e74ad13 | 49 | int tones_num = 32; |
justinkim | 0:9d311e74ad13 | 50 | |
justinkim | 0:9d311e74ad13 | 51 | /* Private functions ---------------------------------------------------------*/ |
justinkim | 0:9d311e74ad13 | 52 | /** |
justinkim | 0:9d311e74ad13 | 53 | * @brief Main Function |
justinkim | 0:9d311e74ad13 | 54 | * @param None |
justinkim | 0:9d311e74ad13 | 55 | * @retval None |
justinkim | 0:9d311e74ad13 | 56 | */ |
justinkim | 0:9d311e74ad13 | 57 | int main(void) |
justinkim | 0:9d311e74ad13 | 58 | { |
justinkim | 0:9d311e74ad13 | 59 | Tune(Buzzer, C_4, 4); //4 Octave C beat 4/16 |
justinkim | 0:9d311e74ad13 | 60 | wait_ms(250); |
justinkim | 0:9d311e74ad13 | 61 | Tune(Buzzer, D_4, 4); //4 Octave D beat 4/16 |
justinkim | 0:9d311e74ad13 | 62 | wait_ms(250); |
justinkim | 0:9d311e74ad13 | 63 | Tune(Buzzer, E_4, 4); //4 Octave E beat 4/16 |
justinkim | 0:9d311e74ad13 | 64 | wait_ms(250); |
justinkim | 0:9d311e74ad13 | 65 | |
justinkim | 0:9d311e74ad13 | 66 | int i; |
justinkim | 0:9d311e74ad13 | 67 | |
justinkim | 0:9d311e74ad13 | 68 | for(i=0; i<tones_num; i++) |
justinkim | 0:9d311e74ad13 | 69 | { |
justinkim | 0:9d311e74ad13 | 70 | Auto_tunes(Buzzer, tones[i], 4); // Auto performance |
justinkim | 0:9d311e74ad13 | 71 | Stop_tunes(Buzzer); |
justinkim | 0:9d311e74ad13 | 72 | } |
justinkim | 0:9d311e74ad13 | 73 | } |