by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"
Diff: main.cpp
- Revision:
- 0:1b9092423ff2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Aug 31 16:08:26 2012 +0000 @@ -0,0 +1,19 @@ +/*Program Example 4.7: Plays the tune "Oranges and Lemons" on a piezo buzzer, using PWM + */ +#include "mbed.h" +PwmOut buzzer(p21); + +//frequency array +float frequency[]= {659,554,659,554,440,494,554,587,494,659,554,440}; +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/(2*frequency[i])); // set PWM period + buzzer=0.5; // set duty cycle + wait(0.4*beat[i]); // hold for beat period + } + } +} +