Jose Rios
/
Nucleo_Fade
Fading a led (A basic example of PWM out)
Revision 0:6a5b7fc7aa18, committed 2014-09-08
- Comitter:
- jose_23991
- Date:
- Mon Sep 08 19:49:11 2014 +0000
- Commit message:
- Version 1.0
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 6a5b7fc7aa18 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 08 19:49:11 2014 +0000 @@ -0,0 +1,18 @@ +#include "mbed.h" + +int main() +{ + PwmOut led(LED1); // Create the LED object + float brightness = 0.0; // How bright the LED is + float fadeAmount = 0.02; // How many points to fade the LED by + + while(1) + { + led.write(brightness); // Write a PWM analog brightness value on LED + wait_ms(30); // wait for 30ms to see the dimming effect + brightness = brightness + fadeAmount; // Increase the brightness + + if((int)brightness == 1.0f) // Turn brightness to 0 at the ends of the fade (f is for literal float - Delete the warning) + brightness = 0; + } +}
diff -r 000000000000 -r 6a5b7fc7aa18 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 08 19:49:11 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file