richard tsai / Mbed 2 deprecated Nucleo_pwm

Dependencies:   mbed

main.cpp

Committer:
hungkait
Date:
2014-08-12
Revision:
1:5ed69f730858
Parent:
0:77f33d7dfcb8
Child:
2:95aadb46a806

File content as of revision 1:5ed69f730858:

#include "mbed.h"
 
Ticker flipper;
PwmOut mypwm(PWM_OUT);
DigitalOut led1(LED1);
DigitalOut led2(LED2);

//DigitalOut myled(LED1);

void flip() {
    led2 = !led2;
}
 
int main() {
    
    mypwm.period_ms(10);
    mypwm.pulsewidth_ms(1);
    
    flipper.attach(&flip, 5.0); // the address of the function to be attached (flip) and the interval (2 seconds)
  
    printf("pwm set to %.2f %%\n", mypwm.read() * 100);
    
    // spin in a main loop. flipper will interrupt it to call flip
    while(1) {
        led1 = !led1;
        wait(0.2);
    }
}