Playing PWM music //Borrowed from Rob Toulson and Tim Wilmshurst: ARM mbed Course Material - PWM //Link: https://developer.mbed.org/cookbook/Course-Notes
Playing PWM music
Borrowed from Rob Toulson and Tim Wilmshurst: ARM mbed Course Material - PWM
Link: https://developer.mbed.org/cookbook/Course-Notes
main.cpp
- Committer:
- cspista
- Date:
- 2021-10-13
- Revision:
- 0:c805c9f396c1
File content as of revision 0:c805c9f396c1:
//Borrowed from Rob Toulson and Tim Wilmshurst: ARM mbed Course Material - PWM //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<12; i++) { buzzer.period(1/(frequency[i])); // set PWM period buzzer=0.5; // set duty cycle wait(0.5*beat[i]); // hold for beat period } } }