A flickering 27-way LED light program

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Jankoekenpan
Date:
Mon Sep 12 11:13:22 2016 +0000
Commit message:
toggle leds :D

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 51ca5dbf6087 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Sep 12 11:13:22 2016 +0000
@@ -0,0 +1,49 @@
+#include "mbed.h"
+
+//Appearantly I cannot declare leds as volatile. I whish I could.
+DigitalOut ledRed(LED_RED);
+DigitalOut ledBlue(LED_BLUE);
+DigitalOut ledGreen(LED_GREEN);
+
+Serial pc(USBTX, USBRX, "YOLO");
+
+Ticker ticker;
+
+volatile bool red = false;
+volatile bool green = false;
+volatile bool blue = false;
+
+void tick() {
+    if (red) {
+        ledRed = !ledRed;
+    }
+    if (green) {
+        ledGreen = !ledGreen;
+    }
+    if (blue) {
+        ledBlue = !ledBlue;
+    }
+}
+
+int main()
+{    
+    ticker.attach(&tick, 1); //schedule the tick function to be executed every second.
+    
+    pc.baud(115200);
+    pc.printf("Press 'r', 'g' or 'b' to toggle the RGB LEDs \r\n");
+    
+    while (true) {
+        char c = pc.getc();
+        switch(c) {
+        case 'r':
+            red = !red;
+            break;
+        case 'b':
+            blue = !blue;
+            break;
+        case 'g':
+            green = !green;
+            break;
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 51ca5dbf6087 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Sep 12 11:13:22 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897
\ No newline at end of file