Whitworth-EN173-2016
/
SmartRise_MBED
Alarm Clock
Fork of SmartRise_MBED by
Alarm.cpp@7:5412a6d7ef6d, 2016-01-26 (annotated)
- Committer:
- asloop18
- Date:
- Tue Jan 26 01:22:36 2016 +0000
- Revision:
- 7:5412a6d7ef6d
- Parent:
- 5:90f059fdc625
- Child:
- 8:edf5f23cb393
functions compiled;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pstephens18 | 5:90f059fdc625 | 1 | #include "mbed.h" |
pstephens18 | 5:90f059fdc625 | 2 | PwmOut buzzer1(p21); |
pstephens18 | 5:90f059fdc625 | 3 | PwmOut buzzer2(p22); |
pstephens18 | 5:90f059fdc625 | 4 | bool go = true; |
pstephens18 | 5:90f059fdc625 | 5 | |
pstephens18 | 5:90f059fdc625 | 6 | |
pstephens18 | 5:90f059fdc625 | 7 | void Sound_Alarm() |
pstephens18 | 5:90f059fdc625 | 8 | { |
pstephens18 | 5:90f059fdc625 | 9 | 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,/**/}; |
pstephens18 | 5:90f059fdc625 | 10 | 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/**/}; |
pstephens18 | 5:90f059fdc625 | 11 | 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}; |
pstephens18 | 5:90f059fdc625 | 12 | 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}; |
pstephens18 | 5:90f059fdc625 | 13 | |
pstephens18 | 5:90f059fdc625 | 14 | while(go) |
pstephens18 | 5:90f059fdc625 | 15 | { |
pstephens18 | 5:90f059fdc625 | 16 | for(int i=0; i<= 37;i++) |
pstephens18 | 5:90f059fdc625 | 17 | { |
pstephens18 | 5:90f059fdc625 | 18 | buzzer1.period(2/(frequency[i])); |
pstephens18 | 5:90f059fdc625 | 19 | buzzer2.period(2/(frequency[i])); |
pstephens18 | 5:90f059fdc625 | 20 | buzzer1 = 0.5; |
pstephens18 | 5:90f059fdc625 | 21 | buzzer2 = 0.5; |
pstephens18 | 5:90f059fdc625 | 22 | |
pstephens18 | 5:90f059fdc625 | 23 | wait(0.4*beat[i]); |
pstephens18 | 5:90f059fdc625 | 24 | if(beat[i]==0) |
pstephens18 | 5:90f059fdc625 | 25 | {wait(.05);} |
pstephens18 | 5:90f059fdc625 | 26 | |
pstephens18 | 5:90f059fdc625 | 27 | } |
pstephens18 | 5:90f059fdc625 | 28 | |
pstephens18 | 5:90f059fdc625 | 29 | for(int i=0; i<= 49;i++) |
pstephens18 | 5:90f059fdc625 | 30 | { |
pstephens18 | 5:90f059fdc625 | 31 | buzzer1.period(2/(frequency2[i])); |
pstephens18 | 5:90f059fdc625 | 32 | buzzer2.period(2/(frequency2[i])); |
pstephens18 | 5:90f059fdc625 | 33 | buzzer1 = 0.5; |
pstephens18 | 5:90f059fdc625 | 34 | buzzer2 = 0.5; |
pstephens18 | 5:90f059fdc625 | 35 | |
pstephens18 | 5:90f059fdc625 | 36 | wait(0.4*beat2[i]); |
pstephens18 | 5:90f059fdc625 | 37 | if(beat2[i]==0) |
pstephens18 | 5:90f059fdc625 | 38 | {wait(.05);} |
pstephens18 | 5:90f059fdc625 | 39 | |
pstephens18 | 5:90f059fdc625 | 40 | } |
pstephens18 | 5:90f059fdc625 | 41 | } |
pstephens18 | 5:90f059fdc625 | 42 | |
asloop18 | 7:5412a6d7ef6d | 43 | go=true; |
pstephens18 | 5:90f059fdc625 | 44 | } |
pstephens18 | 5:90f059fdc625 | 45 | |
pstephens18 | 5:90f059fdc625 | 46 | void turn_off() |
pstephens18 | 5:90f059fdc625 | 47 | { |
pstephens18 | 5:90f059fdc625 | 48 | go = !go; |
pstephens18 | 5:90f059fdc625 | 49 | } |