123

Dependencies:   mbed

Fork of Boboobooo by Clark Lin

Revision:
6:b046d6ff3745
Parent:
1:82bc25a7b68b
Child:
7:f04bde0ca846
diff -r e32b091aa1fb -r b046d6ff3745 servo_api.cpp
--- a/servo_api.cpp	Thu Jun 05 10:32:55 2014 +0000
+++ b/servo_api.cpp	Mon Jul 07 08:16:46 2014 +0000
@@ -1,50 +1,28 @@
 // 0~180 angle    1~2ms
 #include "mbed.h"
 #include "servo_api.h"
-
-
-#define right_end 0.05  //90
-
-#define left_end 0.1    //-90
+#define right_end 1.0  //90
+#define left_end 0.0  //-90
+//middle 0.057
 
 //memory opt
 // 5 degree seperate
-
-
-
-BX_servo::BX_servo(void){
-    
-    
-      angle = 0;
+BX_servo::BX_servo(void)
+{
+    angle = 0;
+    servo_in= new  PwmOut(PTB0);
+    servo_in->period_ms(20);
+}
 
-      servo_in= new  PwmOut(PTB0);
-      
-      servo_in->period_ms(20);
-          
-      for(int i=0;i<37;i++){
-          
-          angle_level[i]=i*(0.05/36)+right_end;
-          }
+float BX_servo::set_angle(float a)
+{
 
-      *servo_in =angle_level[18];
-      
-    
-    }
-
-
-
-
-
+    if( a<left_end )
+        a=left_end;
+    else if(a>right_end)
+        a=right_end;
+    angle=a;
+    *servo_in=angle;
 
-int BX_servo::set_angle(int a){
-    
-    
-      angle=a;
-       
-      *servo_in=angle_level[18+a/5];
-   
-         
-     
     return angle;
-    
-    }
\ No newline at end of file
+}
\ No newline at end of file