Demonstrate digital input and for loops

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ethanharstad
Date:
Fri Jun 06 20:42:01 2014 +0000
Parent:
0:93dd561b0067
Commit message:
Comments

Changed in this revision

abcs.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 93dd561b0067 -r 304bb8817c1d abcs.cpp
--- a/abcs.cpp	Sun Jun 01 22:01:18 2014 +0000
+++ b/abcs.cpp	Fri Jun 06 20:42:01 2014 +0000
@@ -1,16 +1,17 @@
 #include "mbed.h"
 
-Serial pc(USBTX, USBRX);
-DigitalIn btn(USER_BUTTON);
+Serial pc(USBTX, USBRX);                    // Computer serial port
+DigitalIn btn(USER_BUTTON);                 // Button input
 
+// Main function
 int main() {
-    while(true) {
-        pc.printf("Press the button.\n");
-        while(btn != 0);
-        for(int i = 'a'; i <= 'z'; i++) {
-            pc.printf("%c", i);
-            wait(0.1);
-        }
-        pc.printf("\n");
-    }
+    while(true) {                           // Main loop
+        pc.printf("Press the button.\n");   // Instruct the user
+        while(btn != 0);                    // Wait for a button press
+        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
+    }                                       // Repeat
 }
\ No newline at end of file