Thread example of multiple things happening at once. Requires mbed OS 5 and up-to-date mbed firmware.

Dependencies:   Motor Servo

Fork of Fa2018-es200-1121-3321-thread-example-peanut by Fa2018-es200-3321-proj2-GoodTeam#2

Revision:
5:0c7c692db414
Parent:
4:6ccbc7542ddc
diff -r 6ccbc7542ddc -r 0c7c692db414 main.cpp
--- a/main.cpp	Sun Oct 14 22:05:59 2018 +0000
+++ b/main.cpp	Mon Oct 15 11:34:44 2018 +0000
@@ -21,15 +21,13 @@
 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.
+/** 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.
+/** 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);
 
@@ -48,8 +46,9 @@
     // main loop
     while(1){
         heartbeat = !heartbeat; // blink heartbeat once a second
-        ThisThread::sleep_for(1000);
-        
+        //ThisThread::sleep_for(1000);
+        Thread::wait(1000);
+                
         // I don't have to do my motor or servo stuff here because they are
         // running in their own threads. 
         } // main loop
@@ -69,7 +68,8 @@
                 led1.write(0); 
                 m.speed(0.0); // stop the shaft
                 }
-        ThisThread::sleep_for(200); // this thread executes 5x a second
+        //ThisThread::sleep_for(200); // this thread executes 5x a second
+        Thread::wait(200); 
     } // while(1)
 } // m_callback()
     
@@ -86,6 +86,7 @@
                 led2.write(0); 
                 s1.write(s1.read()-0.1); // move servo a step to left
                 }
-        ThisThread::sleep_for(200); // this thread executes 5x a second
+        //ThisThread::sleep_for(200); // this thread executes 5x a second
+        Thread::wait(200); 
         } // while(1)
 } // s1_callback()