Prints "Hello World!" every 5 seconds, and blinks LED1 at a defined hertz.

Dependencies:   mbed

Revision:
0:543eb4b01cda
Child:
1:f09b0fb6022a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 14 18:07:09 2014 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+
+// A simple and concise explanation of what this program does
+/* Simple Hello World program that outputs "Hello World!" every 
+    five seconds to the serial debug port, and blinks at the user
+    defined hertz
+*/
+
+// LED blink rate: higher -> faster blinking
+#define LED_BLINK_RATE 4 //Hertz
+
+//Define the LED pin output
+DigitalOut led(LED1);
+//Define timers
+Timer print_timer;
+Timer led_timer;
+
+int main() {
+    led = 0;                            //Initialize LED off
+    print_timer.start();                //Start timers, will count until stopped
+    led_timer.start();
+    
+    while (1) {
+        if (print_timer.read() >= 5) {  //print_timer.read() returns time in seconds
+            printf("Hello World!\n");
+            print_timer.reset();        //Resets timer count to 0
+        }
+        
+        //Calculates interval needed for specified frequency
+        if ( led_timer.read_ms() >= (1000.0/(2*LED_BLINK_RATE))) {     
+            led = !led;                 //Invert LED output
+            led_timer.reset();          //Resets timer count to 0
+        }
+    }
+}
\ No newline at end of file