Martijn Grootens / Mbed 2 deprecated mbr_2016_hw_2_ex_1

Dependencies:   MODSERIAL mbed

Files at this revision

API Documentation at this revision

Comitter:
megrootens
Date:
Fri Sep 16 15:26:34 2016 +0000
Child:
1:847e4f0d71f5
Commit message:
Example solution Minor Biorobotics 2016; University of Twente,; Dept. of Biomechanical Engineering; Homework set 2, Exercise 1.

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Fri Sep 16 15:26:34 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#4737f8a5b018
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 16 15:26:34 2016 +0000
@@ -0,0 +1,58 @@
+/**
+ * Minor BioRobotics 2016
+ *
+ * Programming Homework Set 2
+ * Exercise 1, example solution
+ *
+ * M.E. Grootens [at] utwente.nl,
+ * v0.1, 16.09.2016
+ */
+
+#include "mbed.h"
+#include "MODSERIAL.h"
+
+#define SERIAL_BAUD 115200  // baud rate for serial communication
+
+// Serial communication using MODSERIAL
+MODSERIAL pc(USBTX,USBRX);
+
+// LED that is to blink
+DigitalOut led_r(LED_RED);
+
+
+const float kTimeLedToggle = 0.5f;  // period with which to toggle LED
+const int kLedOn = 0;               // LED on if 0
+
+int num_turned_on = 0;              // count number of times LED is turned on
+
+/**
+ * Toggle / Switch the state of the LED.
+ * Count the number of times the LED was turned ON.
+ */
+void ToggleLed()
+{
+    led_r = not led_r;
+    if (led_r == kLedOn) {
+        num_turned_on++;
+        pc.printf("LED has been turned on %d times\r\n",num_turned_on);
+    }
+}
+
+/**
+ * Main loop.
+ */
+int main()
+{
+    // Serial comm baud rate
+    pc.baud(SERIAL_BAUD);
+    pc.printf("\r\n**RESET**\r\n");
+    
+    // Turn off LED initially
+    led_r = not kLedOn;
+    
+    // Create ticker and attach LED toggle function
+    Ticker tick_toggle_led;
+    tick_toggle_led.attach(ToggleLed,kTimeLedToggle);
+    
+    while (true);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Sep 16 15:26:34 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897
\ No newline at end of file