Josh Blackann / Mbed 2 deprecated DISCO_SMT32L4_pwm_PB3

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(PWM_OUT);
00004 
00005 DigitalOut myled(LED1);
00006 
00007 #define UP 1
00008 #define DOWN 2
00009 
00010 int main() {
00011     
00012     uint8_t i; 
00013     uint8_t count_dir;
00014     
00015     
00016     mypwm.period_ms(10);
00017     mypwm.pulsewidth_ms(1);
00018   
00019     printf("pwm set to %.2f %%\n", mypwm.read() * 100);
00020     
00021     count_dir = UP;
00022     while(1) {
00023         myled = !myled;
00024         for(i = 0; i < 10; i++ )
00025         {
00026             wait(0.1);
00027             if(count_dir == UP)
00028             {
00029                 mypwm = mypwm + 0.01;
00030                 if(mypwm == 1.00) // if hit one, start counting down
00031                 {
00032                     count_dir = DOWN;
00033                 }
00034             }
00035             else if(count_dir == DOWN)
00036             {
00037                 mypwm = mypwm - 0.01;
00038                 if(mypwm == 0.0)    // if hit zero, start counting up
00039                 {
00040                     count_dir = UP;
00041                 }
00042             }
00043             
00044         }
00045         printf("pwm set to %.2f %%\n\r", mypwm.read() * 100);
00046     }
00047 }