Basic serial output program

Dependencies:   mbed

Committer:
ethanharstad
Date:
Fri Jun 06 19:16:10 2014 +0000
Revision:
1:3a83283bcc1c
Parent:
main.cpp@0:3619ce83ea6c
Rename file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ethanharstad 0:3619ce83ea6c 1 #include "mbed.h"
ethanharstad 0:3619ce83ea6c 2
ethanharstad 0:3619ce83ea6c 3 unsigned int counter = 0; // Keep count of lifetime
ethanharstad 0:3619ce83ea6c 4 Serial pc(USBTX, USBRX); // Talk to the computer
ethanharstad 0:3619ce83ea6c 5
ethanharstad 0:3619ce83ea6c 6 void count() {
ethanharstad 0:3619ce83ea6c 7 // Announce lifetime
ethanharstad 0:3619ce83ea6c 8 pc.printf("I have been alive for %i seconds.\n", counter);
ethanharstad 0:3619ce83ea6c 9 counter++; // Count up by 1
ethanharstad 0:3619ce83ea6c 10 }
ethanharstad 0:3619ce83ea6c 11
ethanharstad 0:3619ce83ea6c 12 int main() {
ethanharstad 0:3619ce83ea6c 13 pc.printf("Hello world!\n"); // Say hello
ethanharstad 0:3619ce83ea6c 14 while(true) { // Main loop
ethanharstad 0:3619ce83ea6c 15 count(); // Call our function
ethanharstad 0:3619ce83ea6c 16 wait(1); // Wait for 1 second
ethanharstad 0:3619ce83ea6c 17 } // Repeat
ethanharstad 0:3619ce83ea6c 18 }