working
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 PwmOut buzzer(p21); 00004 BusOut led(LED1,LED2,LED3,LED4); 00005 float frequency[] = {622,0,784,0,880,0,622,0,784,0,923,880,0,622,0,784,0,880,0,784,0,622,0}; 00006 float beat[] = {.5,0,.5,0,1.25,0,.5,0,.5,0,.5,1.5,0,.5,0,.5,0,1,0,.5,0,1.5,0}; 00007 00008 int main() { 00009 while(1) 00010 { 00011 for(int i=0; i<= 23;i++) 00012 { 00013 buzzer.period(4/(frequency[i])); 00014 buzzer = 0.5; 00015 if(frequency[i]== 622){led =1;} 00016 if(frequency[i]== 784){led =2;} 00017 if(frequency[i]== 880){led =4;} 00018 if(frequency[i]== 923){led = 8;} 00019 00020 wait(0.4*beat[i]); 00021 00022 if(beat[i]==0) 00023 {wait(.15);} 00024 00025 } 00026 } 00027 }
Generated on Thu Aug 4 2022 08:15:17 by
1.7.2
