Rob Toulson
/
RealTimeLab04_Buzzer
Real Time Lab Program
main.cpp@0:4463987cbbfb, 2015-01-25 (annotated)
- Committer:
- robt
- Date:
- Sun Jan 25 16:27:11 2015 +0000
- Revision:
- 0:4463987cbbfb
Real Time Lab Program
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robt | 0:4463987cbbfb | 1 | #include "mbed.h" |
robt | 0:4463987cbbfb | 2 | PwmOut buzzer(p25); |
robt | 0:4463987cbbfb | 3 | |
robt | 0:4463987cbbfb | 4 | //frequency array |
robt | 0:4463987cbbfb | 5 | float frequency[]= {659,554,659,554,440,494,554,587,494,659,554,440}; |
robt | 0:4463987cbbfb | 6 | //beat array |
robt | 0:4463987cbbfb | 7 | float beat[]= {1,1,1,1,1,0.5,0.5,1,1,1,1,2}; |
robt | 0:4463987cbbfb | 8 | |
robt | 0:4463987cbbfb | 9 | |
robt | 0:4463987cbbfb | 10 | |
robt | 0:4463987cbbfb | 11 | int main() |
robt | 0:4463987cbbfb | 12 | { |
robt | 0:4463987cbbfb | 13 | while (1) { |
robt | 0:4463987cbbfb | 14 | for (int i=0; i<=11; i++) { |
robt | 0:4463987cbbfb | 15 | buzzer.period(1/(frequency[i])); // set PWM period |
robt | 0:4463987cbbfb | 16 | buzzer=0.5; // set duty cycle |
robt | 0:4463987cbbfb | 17 | wait(beat[i]); // hold for beat period |
robt | 0:4463987cbbfb | 18 | } |
robt | 0:4463987cbbfb | 19 | } |
robt | 0:4463987cbbfb | 20 | } |