Rising ISR function with flags and call ISR

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
fpucher
Date:
Sat Dec 14 07:54:12 2019 +0000
Commit message:
copy from simulator

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 79f063524a94 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 14 07:54:12 2019 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#define BUTTON1 p14       // push joystick pin
+
+InterruptIn button(BUTTON1);
+DigitalOut myled(LED1);
+bool _pressed = false;      // definition of the flag _pressed      
+
+int checkFlag() {
+    if( _pressed ) {
+        _pressed = false;   // delete flag
+        return 1;
+    }
+    return 0;
+}
+
+void risingISR() {            
+    _pressed = true;        // set flag _pressed
+}
+
+void callISR() {            // function callISR instead an ISR          
+    myled = ! myled;        // now you can use ... 
+    printf("Pressed\n");    // ... printf
+    wait_ms(500);           // ... wait
+    myled = ! myled;        // etc.
+}
+
+
+int main() {
+    printf("Hello Interrupt-Flag v0.1\n");
+    button.rise(&risingISR);                // call ISR in OS2
+    //button.rise(callback(&risingISR));    // callback in OS5
+ 
+    while(1) {
+        if(checkFlag())     // if set then call the function ISR
+            callISR();
+        wait_ms(10);        // only for simulator
+  }
+}
\ No newline at end of file
diff -r 000000000000 -r 79f063524a94 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 14 07:54:12 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file