Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of Fade by
Revision 2:819a248bbe75, committed 2017-09-13
- Comitter:
- CSTritt
- Date:
- Wed Sep 13 18:33:44 2017 +0000
- Parent:
- 1:3efb8a158c32
- Commit message:
- Initial version. Demonstrates PwmOut.
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 |
--- a/main.cpp Fri Sep 08 15:13:21 2017 +0000 +++ b/main.cpp Wed Sep 13 18:33:44 2017 +0000 @@ -1,48 +1,38 @@ /* - Fade + Project: Fade + File: main.cpp + Last revised by: Dr. C. S. Tritt + Revision date: 9/13/17 (v. 1.0) - This example shows how to fade an LED on pin 9 - using PWM. + This example shows how to fade an LED on pin D15 using PWM. This example code is in the public domain. */ - #include "mbed.h" - // Similar to DigitalOut, you can declare a pin to flicker on and off // at a desired frequency and duty cycle using PwmOut. - -PwmOut my_LED(D9); +PwmOut my_LED(D15); // Construct my PwmOut object. -// Create variables to control the fading: - +// Create variables to control brightness and fading: float fadeAmount = 0.05; float brightness = 0; int main() { - - while(1) { + while(true) { + + // The LED brightness is set by writing a value between 0.0 and 1.0. + // This sets the duty cycle (0.5 = 50%, etc.). - // Set the brightness of the LED by writing a value between 0 and 1 - // to my_LED. This sets the duty cycle (0.5 = 50%, etc.) - - my_LED = brightness; - - // Change the brightness for next time through the loop: - - brightness = brightness + fadeAmount; - + my_LED = brightness; // Set brightness. + brightness = brightness + fadeAmount; // Change for next time through. + // Reverse the direction of the fading at the ends of the fade. // It's hard for floats to be exactly equal, so reverse if we hit // or go past full dark or full bright. - - if (brightness <= 0 || brightness >= 1) { - fadeAmount = -fadeAmount ; - } - // Wait for 30 milliseconds to see the dimming effect - - wait(0.03); - + if (brightness <= 0 || brightness >= 1) { // Reverse at limits. + fadeAmount = -fadeAmount ; // Reverse fade direction. + } + wait(0.03); // Wait for 30 milliseconds to see the dimming effect . } -} +} \ No newline at end of file
--- a/mbed.bld Fri Sep 08 15:13:21 2017 +0000 +++ b/mbed.bld Wed Sep 13 18:33:44 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/fd96258d940d \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec \ No newline at end of file