My first program to create a chase pattern with the on-board LEDs, but this uses the concept of a rotating phasor and pulse width modulation to dim the LEDs.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
dminear
Date:
Tue Nov 30 15:05:44 2010 +0000
Commit message:
Initial release

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 cf65b0672fcd main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 30 15:05:44 2010 +0000
@@ -0,0 +1,43 @@
+/* Chase pattern using a rotating phasor
+ * Dan Minear
+ * 2010-11-20
+*/
+
+#include "mbed.h"
+#include "math.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+PwmOut led1(LED1);
+PwmOut led2(LED2);
+PwmOut led3(LED3);
+PwmOut led4(LED4);
+
+float brightness = 0.0;
+float factor = 0.01;
+
+int main() {
+    pc.printf("\nPress 'u' or 'd'\n");
+    char c;
+    float angle = 0;
+    float factor = 0.01;
+    
+    while(1) {
+        if (pc.readable()) {
+            c = pc.getc();
+            if (c == 'u') { factor += 0.01; }
+            if (c =='d') { factor -= 0.01; }
+        }
+        angle += factor;
+        if (angle > 2 * 3.14159 ) { angle = 0; }
+        
+        led1 = (sin(angle) / 2)/2;
+        led2 = (sin(angle + 3.1416 / 4))/2;
+        led3 = (sin(angle + 3.1416 / 2))/2;
+        led4 = (sin(angle + 3.1416 * 3 / 4))/2;
+        
+        wait(0.01);
+    }
+}
+
+
+
diff -r 000000000000 -r cf65b0672fcd mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 30 15:05:44 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e