BlinkButton2Sec done
Revision 0:bc51741ad0f9, committed 2018-11-30
- Comitter:
- redona
- Date:
- Fri Nov 30 10:56:33 2018 +0000
- Commit message:
- completed BlinkButton2Sec
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 Fri Nov 30 10:56:33 2018 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+
+DigitalOut led1(LED1);
+InterruptIn button(USER_BUTTON);
+EventQueue queue(32 * EVENTS_EVENT_SIZE);
+Thread t;
+time_t seconds = time(NULL);
+
+void rise_handler_thread_context(void) {
+ if(seconds - time(NULL) > 2){
+ seconds = time(NULL);
+ }
+ else {
+ led1 = !led1;
+ wait(1);
+ led1 = !led1;
+ wait(1);
+ led1 = !led1;
+ wait(1);
+ led1 = !led1;
+ seconds = time(NULL);
+ }
+}
+
+void rise_handler_iterrupt_context(void) {
+ queue.call(rise_handler_thread_context);
+}
+
+void fall_handler(void) {
+ printf("hello\n");
+}
+
+int main() {
+ // Start the event queue
+ t.start(callback(&queue, &EventQueue::dispatch_forever));
+ // The 'rise' handler will execute in IRQ context
+ button.rise(rise_handler_iterrupt_context);
+ // The 'fall' handler will execute in the context of thread 't'
+ button.fall(queue.event(fall_handler));
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Nov 30 10:56:33 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/mbed-os/#bf6f2c3c6434a6de9eb9511feffa5948b3d1f20f