pwm example

Committer:
tulanthoar
Date:
Fri Apr 21 16:10:07 2017 +0000
Revision:
1:c02f888c2d79
Parent:
0:cf7d80e6c73e
switch to mbed-os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tulanthoar 0:cf7d80e6c73e 1 #include "mbed.h"
tulanthoar 0:cf7d80e6c73e 2
tulanthoar 0:cf7d80e6c73e 3 PwmOut mypwm(PWM_OUT);
tulanthoar 0:cf7d80e6c73e 4
tulanthoar 0:cf7d80e6c73e 5 DigitalOut myled(LED1);
tulanthoar 0:cf7d80e6c73e 6
tulanthoar 0:cf7d80e6c73e 7 int main() {
tulanthoar 0:cf7d80e6c73e 8
tulanthoar 0:cf7d80e6c73e 9 mypwm.period_ms(2);
tulanthoar 0:cf7d80e6c73e 10 mypwm.pulsewidth_ms(1);
tulanthoar 0:cf7d80e6c73e 11 mypwm.write(0.9);
tulanthoar 0:cf7d80e6c73e 12 printf("pwm set to %.2f %%\n", mypwm.read() * 100);
tulanthoar 0:cf7d80e6c73e 13
tulanthoar 0:cf7d80e6c73e 14 while(1) {
tulanthoar 0:cf7d80e6c73e 15 myled = !myled;
tulanthoar 0:cf7d80e6c73e 16 wait(0.5);
tulanthoar 0:cf7d80e6c73e 17 }
tulanthoar 0:cf7d80e6c73e 18 }