Demonstrate digital input and for loops
Dependencies: mbed
abcs.cpp@1:304bb8817c1d, 2014-06-06 (annotated)
- Committer:
- ethanharstad
- Date:
- Fri Jun 06 20:42:01 2014 +0000
- Revision:
- 1:304bb8817c1d
- Parent:
- 0:93dd561b0067
Comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ethanharstad | 0:93dd561b0067 | 1 | #include "mbed.h" |
ethanharstad | 0:93dd561b0067 | 2 | |
ethanharstad | 1:304bb8817c1d | 3 | Serial pc(USBTX, USBRX); // Computer serial port |
ethanharstad | 1:304bb8817c1d | 4 | DigitalIn btn(USER_BUTTON); // Button input |
ethanharstad | 0:93dd561b0067 | 5 | |
ethanharstad | 1:304bb8817c1d | 6 | // Main function |
ethanharstad | 0:93dd561b0067 | 7 | int main() { |
ethanharstad | 1:304bb8817c1d | 8 | while(true) { // Main loop |
ethanharstad | 1:304bb8817c1d | 9 | pc.printf("Press the button.\n"); // Instruct the user |
ethanharstad | 1:304bb8817c1d | 10 | while(btn != 0); // Wait for a button press |
ethanharstad | 1:304bb8817c1d | 11 | for(int i = 'a'; i <= 'z'; i++) { // Loop through the alphabet |
ethanharstad | 1:304bb8817c1d | 12 | pc.printf("%c", i); // Say the letter |
ethanharstad | 1:304bb8817c1d | 13 | wait(0.1); // Wait a bit |
ethanharstad | 1:304bb8817c1d | 14 | } // End the for loop |
ethanharstad | 1:304bb8817c1d | 15 | pc.printf("\n"); // Print a new line |
ethanharstad | 1:304bb8817c1d | 16 | } // Repeat |
ethanharstad | 0:93dd561b0067 | 17 | } |