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.
Diff: main.cpp
- Revision:
- 0:a76aa1242d9e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Apr 26 07:56:30 2018 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#define WAIT_FOR_ISR 1
+//Function declarations
+void Function1();
+void ISR();
+
+//Thread
+Thread t1;
+
+//I/O
+DigitalOut led(LED1);
+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);
+ led = !led;
+ }
+}
+
+//Main thread
+int main() {
+ //Initial state
+ led = 1;
+ onBoardSwitch.rise(ISR);
+
+ //Create and run threads (C function pointers)
+ t1.start(Function1);
+
+ //Main thread loop
+ while(1) {
+ t1.join();
+ }
+}