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
- Committer:
- namcheol
- Date:
- 2020-04-21
- Revision:
- 1:45d0e3e16b3a
- Parent:
- 0:f31836d48420
File content as of revision 1:45d0e3e16b3a:
#include "mbed.h" #include "pitches.h" PwmOut buzzer(PTA1); //buzzer = PTA1 int length = 56; float frequency[] = {NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_B5, NOTE_D6, NOTE_C6, NOTE_A5, NOTE_C5, NOTE_E5, NOTE_A5, NOTE_B5, NOTE_E5, NOTE_GS5, NOTE_B5, NOTE_C6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_B5, NOTE_D6,NOTE_C6, NOTE_A5, NOTE_C5, NOTE_E5, NOTE_A5, NOTE_B5, NOTE_E5, NOTE_GS5, NOTE_B5, NOTE_C6, NOTE_B5, NOTE_C6, NOTE_D6, NOTE_E6, NOTE_G5, NOTE_F6, NOTE_E6, NOTE_D6, NOTE_F5, NOTE_E6, NOTE_D6, NOTE_C6, NOTE_E5, NOTE_D6, NOTE_C6, NOTE_B5, NOTE_E5, NOTE_E6}; float beat[] = {12,12,12,12,12,12,12,12,9, 12,12,12,9, 12,12,12,9, 12,12,12,12,12,12,12,12,9, 12,12,12,9, 12,12,12,9, 12,12,12,9, 12,12,12,9, 12,12,12,9, 12,12,12,9, 12,9}; int main() { while(true) { for(int i = 0; i <= length; i++) { if(frequency[i] == 0) buzzer = 0.0; else { buzzer.period(1.0 / frequency[i]); //period = (1.0 / frequency) buzzer = 0.5; //duty cycle = 50% } thread_sleep_for(3500.0 / beat[i]); //duration = (C / beat)ms } } }