Dersler / Mbed 2 deprecated Nucleo_pwm

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 PwmOut mypwm(PA_7);
00004 
00005 DigitalOut myled(LED1);
00006 
00007 Serial pc(SERIAL_TX, SERIAL_RX);
00008 
00009 int pwm_val = 1;
00010 
00011 int main() {
00012     
00013     mypwm.period_ms(10);
00014     mypwm.pulsewidth_us(100);
00015   
00016     pc.printf("pwm set to %.2f %%\n", mypwm.read() * 100);
00017     
00018     while(1) {
00019         myled = !myled;
00020         
00021     pc.printf("pwm set to %.2f %%\n", mypwm.read() * 100);
00022     
00023           mypwm.pulsewidth_us(pwm_val+=100);
00024           if(pwm_val > 10000)
00025           {
00026               pwm_val = 0;
00027               }
00028         
00029         wait(0.001);
00030     }
00031 }