Nathan Yonkee
/
Nucleo_pwm_copy
pwm example
main.cpp@0:cf7d80e6c73e, 2017-03-15 (annotated)
- Committer:
- tulanthoar
- Date:
- Wed Mar 15 18:03:58 2017 +0000
- Revision:
- 0:cf7d80e6c73e
pwm example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tulanthoar | 0:cf7d80e6c73e | 1 | #include "mbed.h" |
tulanthoar | 0:cf7d80e6c73e | 2 | |
tulanthoar | 0:cf7d80e6c73e | 3 | PwmOut mypwm(PWM_OUT); |
tulanthoar | 0:cf7d80e6c73e | 4 | |
tulanthoar | 0:cf7d80e6c73e | 5 | DigitalOut myled(LED1); |
tulanthoar | 0:cf7d80e6c73e | 6 | |
tulanthoar | 0:cf7d80e6c73e | 7 | int main() { |
tulanthoar | 0:cf7d80e6c73e | 8 | |
tulanthoar | 0:cf7d80e6c73e | 9 | mypwm.period_ms(2); |
tulanthoar | 0:cf7d80e6c73e | 10 | mypwm.pulsewidth_ms(1); |
tulanthoar | 0:cf7d80e6c73e | 11 | mypwm.write(0.9); |
tulanthoar | 0:cf7d80e6c73e | 12 | printf("pwm set to %.2f %%\n", mypwm.read() * 100); |
tulanthoar | 0:cf7d80e6c73e | 13 | |
tulanthoar | 0:cf7d80e6c73e | 14 | while(1) { |
tulanthoar | 0:cf7d80e6c73e | 15 | myled = !myled; |
tulanthoar | 0:cf7d80e6c73e | 16 | wait(0.5); |
tulanthoar | 0:cf7d80e6c73e | 17 | } |
tulanthoar | 0:cf7d80e6c73e | 18 | } |