Istvan Cserny
/
03_pwm_music
Pulse Width Modulation
/ 03_pwm_music
- This program plays the Oranges and Lemons music
- on a piezo buzzer tied between D3 (PTA12) pin and GND
- Hardware requirements:
- - FRDM-KL25Z board
- - Piezo buzzer tied between D3 (PTA12) pin and GND
- Note: The + pin of the buzzer connects to D3, of course...
- This is an example program borrowed from the
- Pulse Width Modulation section of ARM mbed Course Material
- Authors: Rob Toulson and Tim Wilmshurst
- Link: https://developer.mbed.org/cookbook/Course-Notes
- /
Revision 0:7d30529dcdc6, committed 2015-10-21
- Comitter:
- icserny
- Date:
- Wed Oct 21 11:51:16 2015 +0000
- Commit message:
- First version
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 7d30529dcdc6 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Oct 21 11:51:16 2015 +0000 @@ -0,0 +1,28 @@ +/** 03_pwm_music + * This program plays the Oranges and Lemons music + * on a piezo buzzer tied between D3 (PTA12) pin and GND + * + * Hardware requirements: + * - FRDM-KL25Z board + * - Piezo buzzer tied between D3 (PTA12) pin and GND + * Note: The + pin of the buzzer connects to D3, of course... + * + * This is an example program borrowed from the + * Pulse Width Modulation section of ARM mbed Course Material + * Authors: Rob Toulson and Tim Wilmshurst + * Link: https://developer.mbed.org/cookbook/Course-Notes + */ +#include "mbed.h" +PwmOut buzzer(D3); +float frequency[]={659,554,659,554,550,494,554,587,494,659,554,440}; //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])); // set PWM period + buzzer=0.5; // set duty cycle + wait(0.5*beat[i]); // hold for beat period + } + } +} \ No newline at end of file
diff -r 000000000000 -r 7d30529dcdc6 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Oct 21 11:51:16 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file