
This program is a simple version of an LED dimmer that allows the user to increase or decrease the on-board LED brightness using a keyboard.
Revision 0:9ac9735e14c3, committed 2015-01-22
- Comitter:
- 302Instructor
- Date:
- Thu Jan 22 19:55:25 2015 +0000
- Commit message:
- 1/22/2015
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 9ac9735e14c3 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 22 19:55:25 2015 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); +PwmOut led(LED1); + +float brightness = 0.0; + +int main() { + pc.printf("Press '+' to turn LED1 brightness up, '-' to turn it down \n\r"); + led.period(0.02); + while(1) { + char c = pc.getc(); + if ((c == '+') && (brightness > 0.0)) { + brightness -= 0.1; + led.write(brightness); + printf("%f",brightness); + printf("\n\rUP"); + } + if ((c == '-') && (brightness < 0.999)) { + brightness += 0.1; + led.write(brightness); + printf("%f",brightness); + printf("\n\rDOWN"); + } + } +} + \ No newline at end of file
diff -r 000000000000 -r 9ac9735e14c3 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jan 22 19:55:25 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89 \ No newline at end of file