![](/media/cache/profiles/d3b154a6afe99c7d4f2b3fa23962a134.jpg.50x50_q85.png)
Testing PWM with a speaker
main.cpp
- Committer:
- bcostm
- Date:
- 2014-02-20
- Revision:
- 0:b82c05c12d48
- Child:
- 1:aa7cd19c6a4f
File content as of revision 0:b82c05c12d48:
#include "mbed.h" DigitalOut my_led(LED1); InterruptIn my_button(USER_BUTTON); PwmOut my_pwm(PB_3); void pressed() { if (my_pwm.read() == 0.25) { my_pwm.write(0.75); } else { my_pwm.write(0.25); } } int main() { // Set PWM my_pwm.period_ms(10); my_pwm.write(0.5); // Set button my_button.fall(&pressed); while (1) { my_led = !my_led; wait(0.5); // 500 ms } }