Oscar Liao
/
Nucleo_pwm
pwm
main.cpp@0:b45c510cc04a, 2018-12-13 (annotated)
- Committer:
- OscarLiao
- Date:
- Thu Dec 13 09:47:44 2018 +0000
- Revision:
- 0:b45c510cc04a
pwm;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OscarLiao | 0:b45c510cc04a | 1 | #include "mbed.h" |
OscarLiao | 0:b45c510cc04a | 2 | |
OscarLiao | 0:b45c510cc04a | 3 | PwmOut mypwm(D6); |
OscarLiao | 0:b45c510cc04a | 4 | |
OscarLiao | 0:b45c510cc04a | 5 | DigitalOut myled(LED1); |
OscarLiao | 0:b45c510cc04a | 6 | |
OscarLiao | 0:b45c510cc04a | 7 | int main() { |
OscarLiao | 0:b45c510cc04a | 8 | |
OscarLiao | 0:b45c510cc04a | 9 | mypwm.period_us(15000); |
OscarLiao | 0:b45c510cc04a | 10 | mypwm.pulsewidth_us(2100); |
OscarLiao | 0:b45c510cc04a | 11 | |
OscarLiao | 0:b45c510cc04a | 12 | printf("pwm set to %.2f %%\n", mypwm.read() * 100); |
OscarLiao | 0:b45c510cc04a | 13 | |
OscarLiao | 0:b45c510cc04a | 14 | while(1) { |
OscarLiao | 0:b45c510cc04a | 15 | myled = !myled; |
OscarLiao | 0:b45c510cc04a | 16 | wait(1); |
OscarLiao | 0:b45c510cc04a | 17 | } |
OscarLiao | 0:b45c510cc04a | 18 | } |