buzzer
Dependencies: mbed
main.cpp
- Committer:
- xiaohonglv
- Date:
- 2016-06-09
- Revision:
- 1:f6f3187e44c5
- Parent:
- 0:72ee6ba483f8
File content as of revision 1:f6f3187e44c5:
#include "mbed.h" PwmOut buzzer(p23); // red light float frequency[]= {500,0,500,0,500,0,500,0,500,0} ;//alarm frequency array float beat[]= {1,1,1,1,1,1,1,1,1,1}; //beat array int main() { while (1) { for ( int i=0; i<=9 ; 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 } } } // 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() { buzzer.period_ms(1); //1ms period 1k Hz // buzzer = 0; //0% duty cycle // }