Program pulses the board LED from 0% to 100% and back using soft PWM. Tested on Nucleo F030R8.

Dependencies:   mbed

main.cpp

Committer:
TRodziewicz
Date:
2014-05-27
Revision:
0:ee3ee6288b15

File content as of revision 0:ee3ee6288b15:

#include "mbed.h"

#define PWM_STEPS   100
#define PWM_SPEED   50
#define LED_ON      1
#define LED_OFF     0

DigitalOut myled(LED1);

void blink_led(int from, int to) 
{
    for (int i = 0; i < PWM_STEPS; i++) { 
        myled = from;
        wait_us(i * PWM_SPEED);
        
        myled = to;
        wait_us((PWM_STEPS - i) * PWM_SPEED);
    }
}

int main() {
    while (1) {    
        blink_led(LED_ON, LED_OFF);
        blink_led(LED_OFF, LED_ON);
    }
}