Beating led (a simple example of function call by reference argument)

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jose_23991
Date:
Mon Sep 08 10:42:36 2014 +0000
Commit message:
Version 1.0

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f3fc2277e34d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Sep 08 10:42:36 2014 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+
+void beat(DigitalOut* led, double time); // Prototype of the function beat
+
+int main()
+{
+    DigitalOut led(LED1, 0);            // Create the LED object and setup OFF
+    
+    while(1)
+    {
+        beat(&led, 1);                  // Beat the LED during 1s
+    }
+}
+
+void beat(DigitalOut* led, double time)
+{
+    double portion = (0.33*time)/3;      // Calculate the third portion of the 33% of the time
+    
+    *led = 1;                           // LED ON
+    wait(portion);                      // Wait a third portion of the 33% of the time
+    *led = 0;                           // LED OFF
+    wait(portion);                      // Wait a third portion of the 33% of the time
+    *led = 1;                           // LED ON
+    wait(portion);                      // Wait a third portion of the 33% of the time
+    *led = 0;                           // LED OFF
+    wait(time-(3*portion));             // Wait for the 66% of the time
+}
diff -r 000000000000 -r f3fc2277e34d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Sep 08 10:42:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file