/** 03_pwm_led * This program controls the duty cycle of * a PWM output connected to LED1 (LED_RED) * through the serial connection. * * Valid commands: '1', '5', '9' * Corresponding duty cycle: 10%, 50%, 90% * Period: 2000 ms * * Hardware requirements: * - FRDM-KL25Z board */
/ 03_pwm_led
- This program controls the duty cycle of
- a PWM output connected to LED1 (LED_RED)
- through the serial connection.
- Valid commands: '1', '5', '9'
- Corresponding duty cycle: 10%, 50%, 90%
- Period: 2000 ms
- Hardware requirements:
- - FRDM-KL25Z board
- /
Revision 0:68ad188ca8c4, committed 2015-10-21
- Comitter:
- icserny
- Date:
- Wed Oct 21 12:31:41 2015 +0000
- Commit message:
- First version
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 68ad188ca8c4 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Oct 21 12:31:41 2015 +0000 @@ -0,0 +1,41 @@ +/** 03_pwm_led + * This program controls the duty cycle of + * a PWM output connected to LED1 (LED_RED) + * through the serial connection. + * + * Valid commands: '1', '5', '9' + * Corresponding duty cycle: 10%, 50%, 90% + * Period: 2000 ms + * + * Hardware requirements: + * - FRDM-KL25Z board + */ + +#include "mbed.h" + +PwmOut myled(LED1); +Serial pc(USBTX, USBRX); // tx, rx + +int main() { + myled.period_ms(20); //Period = 20 ms + myled.write(1.0); //Led off at start + pc.printf("\r\n03_pwm_led: this program controls the duty cycle of a \r\nPWM output connected to LED1 (LED_RED) through the serial connection.\r\n"); + pc.printf("Period: 20 ms, Valid commands are: '1', '5', '9'\r\nThe corresponding duty cycle are: 1%, 50%, 99%\r\n"); + + while(1) { + char c = pc.getc(); //read next character + if(c=='1') { + myled = 0.99f; //LED has negative logic! + pc.printf("Duty cycle = 0.01\r\n"); + } + else if(c=='5') { + myled = 0.5f; + pc.printf("Duty cycle = 0.5\r\n"); + } + else if(c=='9') { + myled = 0.01f; //LED has negative logic! + pc.printf("Duty cycle = 0.99\r\n"); + } + wait(0.2); + } +}
diff -r 000000000000 -r 68ad188ca8c4 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Oct 21 12:31:41 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file