Control an LED from a computer via the serial port

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ethanharstad
Date:
Fri Jun 06 19:21:27 2014 +0000
Parent:
0:da809d54f2ce
Commit message:
Add comments

Changed in this revision

PhysicalPixel.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/PhysicalPixel.cpp	Sun Jun 01 03:41:48 2014 +0000
+++ b/PhysicalPixel.cpp	Fri Jun 06 19:21:27 2014 +0000
@@ -1,27 +1,27 @@
 #include "mbed.h"
 
 // Global variables
-DigitalOut led(LED1);
-Serial pc(USBTX, USBRX);
+DigitalOut led(LED1);           // LED output
+Serial pc(USBTX, USBRX);        // Computer serial port
 
 // Function prototypes
 void handleInput(char in);
 
 // Main function
 int main() {
-    while(true) {
-        if(pc.readable()) {
-            char c = pc.getc();
-            handleInput(c);
+    while(true) {               // Main loop
+        if(pc.readable()) {     // Can we read?
+            char c = pc.getc(); // Read a character
+            handleInput(c);     // Handle the input
         }
-    }
+    }                           // Repeat
 }
 
 // Input handler
 void handleInput(char in) {
-    if(in == 'H') {
-        led = 1;
-    } else if(in == 'L') {
-        led = 0;
+    if(in == 'H') {             // Is input H?
+        led = 1;                // Turn on LED
+    } else if(in == 'L') {      // Is input L?
+        led = 0;                // Turn off LED
     }
 }
\ No newline at end of file