Clark Lin
/
BX-car_s
QQQ
Fork of BX-car_s by
Diff: servo_api.cpp
- Revision:
- 15:57567d3ee27e
- Parent:
- 11:03d5aa2511c4
- Child:
- 16:b1e11b865d05
--- a/servo_api.cpp Sat Jun 28 07:32:39 2014 +0000 +++ b/servo_api.cpp Sat Jun 28 13:04:29 2014 +0000 @@ -1,53 +1,27 @@ // 0~180 angle 1~2ms #include "mbed.h" #include "servo_api.h" - - -#define right_end 0.06 //90 - -#define left_end 0.101 //-90 +#define right_end 0.093 //90 +#define left_end 0.61 //-90 //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); - - - - } - - - - - +float BX_servo::set_angle(float a) +{ -float BX_servo::set_angle(float a){ - - if( a>left_end ) - a=left_end; - else if(a< right_end) - a=right_end; - - - + if( a<left_end ) + a=left_end; + else if(a>right_end) + a=right_end; + angle=a; + *servo_in=angle; - - - angle=a; - - *servo_in=angle; - - - return angle; - - } \ No newline at end of file +} \ No newline at end of file