Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:0d639007cb27, committed 2018-04-26
- Comitter:
- noutram
- Date:
- Thu Apr 26 07:57:38 2018 +0000
- Commit message:
- Demonstration of signal-wait
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 Thu Apr 26 07:57:38 2018 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+#define WAIT_FOR_ISR 1
+//Function declarations
+void Function1();
+void ISR();
+
+//Thread
+Thread t1;
+
+//I/O
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+InterruptIn onBoardSwitch(USER_BUTTON);
+
+//Switch ISR
+void ISR() {
+ t1.signal_set(WAIT_FOR_ISR);
+}
+
+//Thread
+void Function1() {
+ while (true) {
+ Thread::signal_wait(WAIT_FOR_ISR);
+ wait(0.2); //Debounce
+ Thread::signal_clr(WAIT_FOR_ISR);
+ led1 = !led1;
+ }
+}
+
+//Main thread
+int main() {
+ //Initial state
+ led1 = 1;
+ led2 = 1;
+ onBoardSwitch.rise(ISR);
+
+ //Create and run threads (C function pointers)
+ t1.start(Function1);
+
+ //Main thread loop
+ while(1) {
+ led2 = !led2;
+ Thread::wait(100);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Apr 26 07:57:38 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#e62a1b9236b44e70ae3b0902dc538481c04d455b