Servo Motor Example for electric skateboard

Dependencies:   Servo mbed

Fork of Servo_HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
kaizen
Date:
Thu Oct 29 05:36:03 2015 +0000
Parent:
1:40d2fd0b99e6
Commit message:
First application using servo motor for me

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 40d2fd0b99e6 -r 265f6c40ef23 main.cpp
--- a/main.cpp	Tue Nov 23 16:10:35 2010 +0000
+++ b/main.cpp	Thu Oct 29 05:36:03 2015 +0000
@@ -1,13 +1,45 @@
-// Hello World to sweep a servo through its full range
-
 #include "mbed.h"
 #include "Servo.h"
 
-Servo myservo(p21);
+int main() {    
+    uint8_t ch;
+    volatile float speed_value = 0.5;
+
+    Servo myservo(PC_8);
+    Serial pc(USBTX,USBRX);
+    
+    pc.baud(115200);
+    wait(1);
+    pc.printf("TEST Start\r\n");
+    
+    while(1)
+    {
+        pc.printf("speed : %f\r\n",speed_value);
+        myservo = speed_value;
 
-int main() {    
-    for(float p=0; p<1.0; p += 0.1) {
-        myservo = p;
-        wait(0.2);
+        ch = pc.getc();
+        
+        if(ch == 'u')
+        {
+            speed_value += 0.001;
+        }
+        else if(ch == 'd')
+        {
+            speed_value -= 0.001;
+        }
+        
+        else if(ch == 's')
+        {
+            myservo = 0.5;
+            wait(0.5);
+            
+            speed_value = 0.41;
+            myservo = speed_value;
+            wait(5);
+
+            speed_value = 0.5;
+            myservo = speed_value;
+            
+        }
     }
 }
diff -r 40d2fd0b99e6 -r 265f6c40ef23 mbed.bld
--- a/mbed.bld	Tue Nov 23 16:10:35 2010 +0000
+++ b/mbed.bld	Thu Oct 29 05:36:03 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file