![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Alarm Clock
Fork of SmartRise_MBED by
Alarm.cpp
- Committer:
- pstephens18
- Date:
- 2016-01-26
- Revision:
- 8:edf5f23cb393
- Parent:
- 7:5412a6d7ef6d
- Child:
- 11:be164273b969
File content as of revision 8:edf5f23cb393:
#include "mbed.h" PwmOut buzzer1(p21); PwmOut buzzer2(p22); DigitalOut led(LED1); bool go = true; float frequency[] = {262,0,262,0,262,0,349,0,523,0,466,0,440,0,392,0,698,0,523,0,466,0,440,0,392,0,698,0,523,0,466,0,440,0,466,0,392,0,/**/}; float beat[] = {.3,0,.3,0,.3,0,2,0,2,0,.3,0,.3,0,.3,0,2,0,1,0,.3,0,.3,0,.3,0,2,0,1,0,.3,0,.3,0,.3,0,2,0/**/}; float frequency2[] = {262,0,262,0,294,0,294,0,466,0,440,0,392,0,349,0,349,0,392,0,440,0,392,0,294,0,330,0,523,0,523,0,698,0,622,0,554,0,523,0,466,0,415,0,392,0,349,0,523,0}; float beat2[] = {.75,0,.25,0,1.5,0,.5,0,.5,0,.5,0,.5,0,.5,0,.3,0,.3,0,.3,0,1,0,.5,0,1,0,.75,0,.25,0,1,0,.5,0,1,0,.5,0,1,0,.5,0,1,0,.5,0,4,0}; void Sound_Alarm() { while(go) { led = !led; wait(.5); for(int i=0; i<= 37;i++) { buzzer1.period(2/(frequency[i])); buzzer2.period(2/(frequency[i])); buzzer1 = 0.5; buzzer2 = 0.5; if(!go){break;} wait(0.4*beat[i]); if(beat[i]==0) {wait(.05);} } for(int i=0; i<= 49;i++) { buzzer1.period(2/(frequency2[i])); buzzer2.period(2/(frequency2[i])); buzzer1 = 0.5; buzzer2 = 0.5; if(!go){break;} wait(0.4*beat2[i]); if(beat2[i]==0) {wait(.05);} } } go=true; } void turn_off() { go = !go; led =0; }