Eray Ozturk / Mbed 2 deprecated QuadBrightness

Dependencies:   mbed

Revision:
2:d955fe04abd9
Parent:
1:8012a60a982d
--- a/main.cpp	Fri Oct 22 09:10:35 2010 +0000
+++ b/main.cpp	Fri Oct 22 12:23:34 2010 +0000
@@ -20,6 +20,8 @@
 PwmOut led3(LED3);
 PwmOut led4(LED4);
 
+#define PWM_MAX 0.5
+
 float brightness = 0.0;
 float brigh_bckp;
 
@@ -27,9 +29,14 @@
 int Selec_bckp;
 
 void callback() {
+    if (brightness>PWM_MAX) // limiter
+        brightness = PWM_MAX;
+
+    if (brightness<0.0)     // limiter
+        brightness = 0.0;
+
     if (Selec_bckp!=SelectedLED || brigh_bckp!=brightness) {
-        pc.printf("*brightness%u=%f\n",SelectedLED,brightness);
-
+        pc.printf("*Led%u : %5.1f%%\n",SelectedLED,brightness*100.0/PWM_MAX);
         Selec_bckp = SelectedLED;
         brigh_bckp = brightness;
     }
@@ -64,33 +71,31 @@
     while (true) {
         if (pc.readable()) {
             char c = pc.getc();
-            if ((c == '+') && (brightness < 0.5)) {
+
+            if ((c == '+') && (brightness < PWM_MAX)) {
                 brightness += 0.01;
                 SetBright();
-            }
-            if ((c == '-') && (brightness > 0.0)) {
+            } else if ((c == '-') && (brightness > 0.0)) {
                 brightness -= 0.01;
                 SetBright();
-            }
-            if (c == '1') {
+            } else if (c == '1') {
                 pc.printf("Led1 selected\n");
                 SelectedLED = 1;
                 brightness = 0.0;
-            }
-            if (c == '2') {
+            } else if (c == '2') {
                 pc.printf("Led2 selected\n");
                 SelectedLED = 2;
                 brightness = 0.0;
-            }
-            if (c == '3') {
+            } else if (c == '3') {
                 pc.printf("Led3 selected\n");
                 SelectedLED = 3;
                 brightness = 0.0;
-            }
-            if (c == '4') {
+            } else if (c == '4') {
                 pc.printf("Led4 selected\n");
                 SelectedLED = 4;
                 brightness = 0.0;
+            } else if (c == 'a') {
+                pc.printf("Author: Eray Ozturk\n");
             }
         }
     }