buzzer
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:72ee6ba483f8
- Child:
- 1:f6f3187e44c5
diff -r 000000000000 -r 72ee6ba483f8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jun 09 10:12:11 2016 +0000 @@ -0,0 +1,80 @@ +#include "mbed.h" +PwmOut buzzer(p23); + +// red light +while (flag = 1); +{ + + int main() { + + + + speaker.period_ms(1); //1ms period 1k Hz // + + speaker = 0.5; //50% duty cycle // + } + +} + + +// yellow light + +while (flag = 2); + +{ + float frequency[]= {659,554,659,554,550,494,554,587,494,659,554,440}; //music frequency array + + + float beat[]= {1,1,1,1,1,0.5,0.5,1,1,1,1,2}; //beat array + int + main() + { + while (1) { + for ( + int + i=0; + i<=11; + i++) {buzzer.period(1/(frequency[i])); // PMW period 1/frequency + buzzer=0.5; //50% duty cycle + wait(0.5*beat[i]); //hold for beat period + } + } + } +} + + + + +//green light + +while (flag = 3); + +{ + + int main() { + + speaker.period_ms(1); //1ms period 1k Hz // + + speaker = 0; //0% duty cycle // + +} + + + + + + + + + + + + + + + + + + + +