brightness of the led controlled by two buttons

Dependencies:   mbed

Files at this revision

API Documentation at this revision

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
--- /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
--- /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