BRANDON GARCIA / Mbed OS PwmOut_HelloWorld_Test
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 PwmOut led(LED1);
00004 DigitalOut pa8(PA_8);
00005 DigitalOut pa9(PA_9);
00006 /*
00007 * For additional pins you can declare whichever you want except the PA5 pin.
00008 * Respect the nomenclature used.
00009 //DigitalOut pb6(PB_6);
00010 //DigitalOut pc7(PC_7);
00011 */
00012 
00013 int main() {
00014     // specify period first
00015     pa8.write(1);
00016     pa9.write(0);
00017     //pb6.write(0);        //Depending if you want CW or CCW is the pin you'll have to 
00018     //pc7.write(0);        //turn ON (1) or OFF(0)
00019     
00020     led.period(4.0f);      // 4 second period
00021     led.write(0.50f);      // 50% duty cycle, relative to period
00022     //led = 0.5f;          // shorthand for led.write()
00023     //led.pulsewidth(2);   // alternative to led.write, set duty cycle time in seconds
00024     while(1);
00025 }