Whitworth-EN173-2016
/
SmartRise_MBED
Alarm Clock
Fork of SmartRise_MBED by
Alarm.cpp@8:edf5f23cb393, 2016-01-26 (annotated)
- Committer:
- pstephens18
- Date:
- Tue Jan 26 01:49:16 2016 +0000
- Revision:
- 8:edf5f23cb393
- Parent:
- 7:5412a6d7ef6d
- Child:
- 11:be164273b969
Off switch working with alarm. All parts together.
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 | 8:edf5f23cb393 | 4 | DigitalOut led(LED1); |
pstephens18 | 5:90f059fdc625 | 5 | bool go = true; |
pstephens18 | 5:90f059fdc625 | 6 | |
pstephens18 | 5:90f059fdc625 | 7 | 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 | 8 | 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 | 9 | 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 | 10 | 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 | 11 | |
pstephens18 | 8:edf5f23cb393 | 12 | |
pstephens18 | 8:edf5f23cb393 | 13 | void Sound_Alarm() |
pstephens18 | 8:edf5f23cb393 | 14 | { |
pstephens18 | 8:edf5f23cb393 | 15 | |
pstephens18 | 5:90f059fdc625 | 16 | while(go) |
pstephens18 | 5:90f059fdc625 | 17 | { |
pstephens18 | 8:edf5f23cb393 | 18 | led = !led; |
pstephens18 | 8:edf5f23cb393 | 19 | wait(.5); |
pstephens18 | 8:edf5f23cb393 | 20 | |
pstephens18 | 5:90f059fdc625 | 21 | for(int i=0; i<= 37;i++) |
pstephens18 | 5:90f059fdc625 | 22 | { |
pstephens18 | 5:90f059fdc625 | 23 | buzzer1.period(2/(frequency[i])); |
pstephens18 | 5:90f059fdc625 | 24 | buzzer2.period(2/(frequency[i])); |
pstephens18 | 5:90f059fdc625 | 25 | buzzer1 = 0.5; |
pstephens18 | 5:90f059fdc625 | 26 | buzzer2 = 0.5; |
pstephens18 | 8:edf5f23cb393 | 27 | if(!go){break;} |
pstephens18 | 5:90f059fdc625 | 28 | |
pstephens18 | 5:90f059fdc625 | 29 | wait(0.4*beat[i]); |
pstephens18 | 5:90f059fdc625 | 30 | if(beat[i]==0) |
pstephens18 | 5:90f059fdc625 | 31 | {wait(.05);} |
pstephens18 | 5:90f059fdc625 | 32 | |
pstephens18 | 5:90f059fdc625 | 33 | } |
pstephens18 | 5:90f059fdc625 | 34 | |
pstephens18 | 5:90f059fdc625 | 35 | for(int i=0; i<= 49;i++) |
pstephens18 | 5:90f059fdc625 | 36 | { |
pstephens18 | 5:90f059fdc625 | 37 | buzzer1.period(2/(frequency2[i])); |
pstephens18 | 5:90f059fdc625 | 38 | buzzer2.period(2/(frequency2[i])); |
pstephens18 | 5:90f059fdc625 | 39 | buzzer1 = 0.5; |
pstephens18 | 5:90f059fdc625 | 40 | buzzer2 = 0.5; |
pstephens18 | 5:90f059fdc625 | 41 | |
pstephens18 | 8:edf5f23cb393 | 42 | if(!go){break;} |
pstephens18 | 8:edf5f23cb393 | 43 | |
pstephens18 | 5:90f059fdc625 | 44 | wait(0.4*beat2[i]); |
pstephens18 | 5:90f059fdc625 | 45 | if(beat2[i]==0) |
pstephens18 | 5:90f059fdc625 | 46 | {wait(.05);} |
pstephens18 | 5:90f059fdc625 | 47 | |
pstephens18 | 5:90f059fdc625 | 48 | } |
pstephens18 | 8:edf5f23cb393 | 49 | |
pstephens18 | 5:90f059fdc625 | 50 | } |
pstephens18 | 5:90f059fdc625 | 51 | |
asloop18 | 7:5412a6d7ef6d | 52 | go=true; |
pstephens18 | 5:90f059fdc625 | 53 | } |
pstephens18 | 5:90f059fdc625 | 54 | |
pstephens18 | 5:90f059fdc625 | 55 | void turn_off() |
pstephens18 | 5:90f059fdc625 | 56 | { |
pstephens18 | 8:edf5f23cb393 | 57 | go = !go; |
pstephens18 | 8:edf5f23cb393 | 58 | led =0; |
pstephens18 | 5:90f059fdc625 | 59 | } |