A demo for serial, switch/case and for loops

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ethanharstad
Date:
Fri Jun 13 19:54:36 2014 +0000
Commit message:
Initial commit

Changed in this revision

RemoteControl.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 2616ded45fd4 RemoteControl.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RemoteControl.cpp	Fri Jun 13 19:54:36 2014 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+DigitalOut out(LED1);
+
+void handleInput(char in);
+void sing();
+
+int main() {
+    pc.printf("Ready!\n");
+    while(true) {
+        if(pc.readable()) {
+            char in = pc.getc();
+            handleInput(in);
+        }
+    }
+}
+
+void handleInput(char in) {
+    switch(in) {
+        case 'h':
+        case 'H':
+            out = 1;
+            break;
+        case 'l':
+        case 'L':
+            out = 0;
+            break;
+        case 's':
+        case 'S':
+            sing();
+            break;
+        default:
+            pc.printf("I don't know: \"%c\"\n", in);
+    }
+}
+
+void sing() {
+    for(int i = 'a'; i <= 'z'; i++) {   // Loop through the alphabet
+        pc.printf("%c", i);             // Say the letter
+        wait(0.1);                      // Wait a bit
+    }                                   // End the for loop
+    pc.printf("\n");                    // Print a new line
+}
\ No newline at end of file
diff -r 000000000000 -r 2616ded45fd4 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 13 19:54:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721
\ No newline at end of file