PWM Blinking LED example

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
zuko
Date:
Sun Jun 10 18:50:24 2012 +0000
Commit message:

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	Sun Jun 10 18:50:24 2012 +0000
@@ -0,0 +1,97 @@
+#include "mbed.h"
+
+PwmOut led1(LED1);
+PwmOut led2(LED2);
+PwmOut led3(LED3);
+PwmOut led4(LED4);
+
+
+int main() {
+    int a = -1;
+    float max = 1;
+    float medium = 0.2;
+    float low = 0.01;
+    
+    while(1) {
+        a += 1;
+        if (a == 12) {
+           a = 0;
+        } 
+        
+        wait(0.5);
+        switch(a){
+            case 0:
+            led1 = max;
+            led2 = 0;
+            led3 = 0;
+            led4 = 0;
+            break;
+            case 1:
+            led1 = medium;
+            led2 = max;
+            led3 = 0;
+            led4 = 0;
+            break;
+            case 2:
+            led1 = low;
+            led2 = medium;
+            led3 = max;
+            led4 = 0;
+            break;
+            case 3:
+            led1 = 0;
+            led2 = low;
+            led3 = medium;
+            led4 = max;
+            break;
+            case 4:
+            led1 = 0;
+            led2 = 0;
+            led3 = low;
+            led4 = max;
+            break;
+            case 5:
+            led1 = 0;
+            led2 = 0;
+            led3 = 0;
+            led4 = max;
+            break;
+            case 6:
+            led1 = 0;
+            led2 = 0;
+            led3 = 0;
+            led4 = max;
+            break;
+            case 7:
+            led1 = 0;
+            led2 = 0;
+            led3 = max;
+            led4 = medium;
+            break;
+            case 8:
+            led1 = 0;
+            led2 = max;
+            led3 = medium;
+            led4 = low;
+            break;
+            case 9:
+            led1 = max;
+            led2 = medium;
+            led3 = low;
+            led4 = 0;
+            break;
+            case 10:
+            led1 = max;
+            led2 = low;
+            led3 = 0;
+            led4 = 0;
+            break;
+            case 11:
+            led1 = max;
+            led2 = 0;
+            led3 = 0;
+            led4 = 0;
+            break;
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jun 10 18:50:24 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479