exercise1

Files at this revision

API Documentation at this revision

Comitter:
mcalzana
Date:
Wed Nov 28 17:12:03 2018 +0000
Commit message:
exercise1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 28 17:12:03 2018 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+
+DigitalOut led1(LED1);
+InterruptIn button(USER_BUTTON);
+EventQueue queue(32 * EVENTS_EVENT_SIZE);
+Thread t;
+volatile static time_t begin;
+volatile static int pressCount = 0;
+
+void blinkLed1(void){
+    led1 = 1;
+    wait(0.5);
+    led1 = 0;
+}
+
+void rise_handler_thread_context(void) {
+    printf("Button pressed. count = %d\n", pressCount);
+    if(pressCount == 1){
+        begin = time(NULL);
+    }else{
+        pressCount = 0;
+        if(time(NULL) - begin < 2){
+            printf("Blinking");
+            blinkLed1();
+        }
+    }
+}
+
+void rise_handler_iterrupt_context(void) {
+    pressCount += 1;
+    queue.call(rise_handler_thread_context);
+}
+
+int main() {
+    // Start the event queue
+    t.start(callback(&queue, &EventQueue::dispatch_forever));
+    printf("Starting in context %p\r\n", Thread::gettid());
+    // The 'rise' handler will execute in IRQ context
+    button.rise(rise_handler_iterrupt_context);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Nov 28 17:12:03 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/armmbed/mbed-os/#bf6f2c3c6434a6de9eb9511feffa5948b3d1f20f