Leon Klute / Mbed 2 deprecated frdm_servo_controller

Dependencies:   mbed

Revision:
2:2cc5d274f30d
Parent:
1:08bf7339efdd
Child:
3:8d07dbdd3afc
--- a/main.cpp	Fri Oct 21 13:17:57 2016 +0000
+++ b/main.cpp	Fri Oct 21 13:33:35 2016 +0000
@@ -12,13 +12,13 @@
 int main()
 {
     
-    ServoPWMpin.period(0.01f);      // 0.01 second period
+    ServoPWMpin.period(0.01f);                  // 0.01 second period
     
     while (true) {
         
         if (pc.readable()) {
             Key = pc.getc();
-            switch(Key) {                         //Check to see which Key key...
+            switch(Key) {                         //Check to see which key pressed
                 case 0x41:                        //It was the UP Key key...
                     pc.printf("\n\r UP!");
                     if( ServoAngle < 80){
@@ -31,9 +31,9 @@
                         ServoAngle = ServoAngle-10;
                     }
                     break;
-                case 0x20:
+                case 0x20:                        //It was the Spacebar key...
                     pc.printf("\n\r SPACE!");
-                    if( ServoAngle < 45){
+                    if( ServoAngle < 45){        // Switch from open to closed or else otherwise
                         ServoAngle = 89;
                     }
                     else{
@@ -41,9 +41,10 @@
                     }
                     break;
             }
-        } 
+        } else {
+            wait(1/Frequency);
+        }
 
-        wait(1/Frequency);
         Pulsew = 0.0015+(ServoAngle)/180000;
         ServoPWMpin.pulsewidth(Pulsew);      // write the dutycycle
         pc.printf("\n\r Pulsew is %f",Pulsew);