Demonstrate digital input and for loops

Dependencies:   mbed

abcs.cpp

Committer:
ethanharstad
Date:
2014-06-06
Revision:
1:304bb8817c1d
Parent:
0:93dd561b0067

File content as of revision 1:304bb8817c1d:

#include "mbed.h"

Serial pc(USBTX, USBRX);                    // Computer serial port
DigitalIn btn(USER_BUTTON);                 // Button input

// Main function
int main() {
    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
}