Jan Boerman
/
ButtonBrightness
brightness of the led controlled by two buttons
Revision 0:19aacd50bf59, committed 2016-09-26
- Comitter:
- Jankoekenpan
- Date:
- Mon Sep 26 09:46:00 2016 +0000
- Commit message:
- led brightness using buttons
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 19aacd50bf59 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 26 09:46:00 2016 +0000 @@ -0,0 +1,25 @@ +#include "mbed.h" + +PwmOut led(D3); + +InterruptIn but1(D5); +InterruptIn but2(D4); + +volatile float brightness = 0.0f; + +void increaseBrightness() { + brightness = brightness + 0.1f > 1.0f ? 1.0f : brightness + 0.1f; + led.write(brightness); +} + +void decreaseBrightness() { + brightness = brightness - 0.1f < 0.0f ? 0.0f : brightness - 0.1f; + led.write(brightness); +} + +int main() +{ + but1.fall(increaseBrightness); + but2.fall(decreaseBrightness); + while (true); +} \ No newline at end of file
diff -r 000000000000 -r 19aacd50bf59 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 26 09:46:00 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/abea610beb85 \ No newline at end of file