NUCLEO-F042K6 Simple demo blinking LED using PWM
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:458a648ecbde
- Parent:
- 0:b2a1f2577916
--- a/main.cpp Wed Jan 31 20:17:00 2018 +0000 +++ b/main.cpp Wed Jan 31 20:23:08 2018 +0000 @@ -1,12 +1,23 @@ -#include "mbed.h" +#include "mbed.h" // import of mbed library (required) -PwmOut PWM(PA_8); +/******************************************************************************* + + EXAMPLE DESCRIPTION -int main() { - + Sets PWM out on pin PA_8 with f=2 Hz and duty cycle = 0.5. The best use is to + connect LED to pin PA_8 (using wiring with transitor) to see effect of PWM. + +*******************************************************************************/ + +PwmOut PWM(PA_8); // definition of PWM pin + +int main() +{ + PWM.period_ms(500); // period of PWM - f=1/T -> f=1/0.5=2 Hz - PWM.pulsewidth_ms(250); // duration of active pulse - sets duty cycle - duty cycle = pulsewidth/period - + PWM.pulsewidth_ms(250); // duration of active pulse + //sets duty cycle - duty cycle = pulsewidth/period + while(1) { wait_ms(1000); }