Example of using threads to run different actions happening at the same time.
Fork of Fa2018-es200-1121-3321-thread-example-rockem by
Revision 4:6ccbc7542ddc, committed 2018-10-14
- Comitter:
- evangeli
- Date:
- Sun Oct 14 22:05:59 2018 +0000
- Parent:
- 3:68bba10e81aa
- Child:
- 5:0c7c692db414
- Commit message:
- Still trying to get docstrings to work right
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Oct 14 22:00:35 2018 +0000
+++ b/main.cpp Sun Oct 14 22:05:59 2018 +0000
@@ -21,7 +21,16 @@
Thread m_thread; // NEW IN mbed OS 5, threads are used to (sorta) do multiple things at once
Thread s1_thread;
+/**
+ * Callback for executing a simple motor action. When sw1 is high,
+ * the motor turns forward, otherwise the motor turns off.
+ */
void m_callback(void); // This function will be run within the corresponding thread
+
+/**
+ * Simple callback for servo motion. When sw2 is high, the servo steps right,
+ * otherwise it steps left. If it hits the ends it stays there.
+ */
void s1_callback(void);
// main() runs in its own thread in the OS
@@ -49,10 +58,6 @@
-/**
- * Callback for executing a simple motor action. When sw1 is high,
- * the motor turns forward, otherwise the motor turns off.
- */
void m_callback(void){
printf("m_thread running\n");
while(1) {
@@ -70,10 +75,6 @@
-/**
- * Simple callback for servo motion. When sw2 is high, the servo steps right,
- * otherwise it steps left. If it hits the ends it stays there.
- */
void s1_callback(void){
printf("s1_thread running\n");
while(1){
