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
00001 #include "mbed.h" 00002 #include "C12832.h" 00003 #include "pitches.h" 00004 00005 C12832 lcd(D11, D13, D12, D7, D10); //lcd = (MOSI, SCK, RESET, A0, nCS) 00006 PwmOut buzzer(PTA1); //buzzer = PTA1 00007 int length = 56; 00008 00009 float frequency[] = {NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_B5, NOTE_D6, NOTE_C6, NOTE_A5, 00010 NOTE_C5, NOTE_E5, NOTE_A5, NOTE_B5, 00011 NOTE_E5, NOTE_GS5, NOTE_B5, NOTE_C6, 00012 NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_DS6, NOTE_E6, NOTE_B5, NOTE_D6,NOTE_C6, NOTE_A5, 00013 NOTE_C5, NOTE_E5, NOTE_A5, NOTE_B5, 00014 NOTE_E5, NOTE_GS5, NOTE_B5, NOTE_C6, 00015 NOTE_B5, NOTE_C6, NOTE_D6, NOTE_E6, 00016 NOTE_G5, NOTE_F6, NOTE_E6, NOTE_D6, 00017 NOTE_F5, NOTE_E6, NOTE_D6, NOTE_C6, 00018 NOTE_E5, NOTE_D6, NOTE_C6, NOTE_B5, 00019 NOTE_E5, NOTE_E6}; 00020 float beat[] = {12,12,12,12,12,12,12,12,9, 00021 12,12,12,9, 00022 12,12,12,9, 00023 12,12,12,12,12,12,12,12,9, 00024 12,12,12,9, 00025 12,12,12,9, 00026 12,12,12,9, 00027 12,12,12,9, 00028 12,12,12,9, 00029 12,12,12,9, 00030 12,9}; 00031 00032 00033 int main() 00034 { 00035 lcd.cls(); 00036 lcd.locate(0,6); 00037 lcd.printf("Listen to speaker!"); 00038 lcd.locate(0,16); 00039 lcd.printf("For Elise~~~"); 00040 while(true) { 00041 for(int i = 0; i <= length; i++) { 00042 if(frequency[i] == 0) 00043 buzzer = 0.0; 00044 else { 00045 buzzer.period(1.0 / frequency[i]); //period = (1.0 / frequency) 00046 buzzer = 0.5; //duty cycle = 50% 00047 } 00048 thread_sleep_for(3500.0 / beat[i]); //duration = (C / beat)ms 00049 } 00050 } 00051 }
Generated on Mon Aug 8 2022 16:01:47 by
