Additional events example

Revision:
0:aea2e03f5625
Child:
1:3ee1c217f3cb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jan 19 14:24:27 2017 -0600
@@ -0,0 +1,30 @@
+#include "mbed.h"
+#include "mbed_events.h"
+
+DigitalOut led1(LED1);
+InterruptIn sw(SW2);
+EventQueue queue(32 * EVENTS_EVENT_SIZE);
+Thread t;
+
+void rise_handler(void) {
+    printf("rise_handler in context %p\r\n", Thread::gettid());
+    // Toggle LED
+    led1 = !led1;
+}
+
+void fall_handler(void) {
+    printf("fall_handler in context %p\r\n", Thread::gettid());
+    // Toggle LED
+    led1 = !led1;
+}
+
+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
+    sw.rise(rise_handler);
+    // The 'fall' handler will execute in the context of thread 't'
+    sw.fall(queue.event(fall_handler));
+}
+