Clark Lin
/
BX-car_s
QQQ
Fork of BX-car_s by
servo_api.cpp@23:d6d4e8adf7fe, 2014-07-02 (annotated)
- Committer:
- physicsgood
- Date:
- Wed Jul 02 13:33:49 2014 +0000
- Revision:
- 23:d6d4e8adf7fe
- Parent:
- 16:b1e11b865d05
QQQQ
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
backman | 1:82bc25a7b68b | 1 | // 0~180 angle 1~2ms |
backman | 1:82bc25a7b68b | 2 | #include "mbed.h" |
backman | 1:82bc25a7b68b | 3 | #include "servo_api.h" |
TonyLin | 15:57567d3ee27e | 4 | #define right_end 0.093 //90 |
TonyLin | 16:b1e11b865d05 | 5 | #define left_end 0.061 //-90 |
backman | 1:82bc25a7b68b | 6 | |
backman | 1:82bc25a7b68b | 7 | //memory opt |
backman | 1:82bc25a7b68b | 8 | // 5 degree seperate |
TonyLin | 15:57567d3ee27e | 9 | BX_servo::BX_servo(void) |
TonyLin | 15:57567d3ee27e | 10 | { |
TonyLin | 15:57567d3ee27e | 11 | angle = 0; |
TonyLin | 15:57567d3ee27e | 12 | servo_in= new PwmOut(PTB0); |
TonyLin | 15:57567d3ee27e | 13 | servo_in->period_ms(20); |
TonyLin | 15:57567d3ee27e | 14 | } |
backman | 1:82bc25a7b68b | 15 | |
TonyLin | 15:57567d3ee27e | 16 | float BX_servo::set_angle(float a) |
TonyLin | 15:57567d3ee27e | 17 | { |
backman | 1:82bc25a7b68b | 18 | |
TonyLin | 15:57567d3ee27e | 19 | if( a<left_end ) |
TonyLin | 15:57567d3ee27e | 20 | a=left_end; |
TonyLin | 15:57567d3ee27e | 21 | else if(a>right_end) |
TonyLin | 15:57567d3ee27e | 22 | a=right_end; |
TonyLin | 15:57567d3ee27e | 23 | angle=a; |
TonyLin | 15:57567d3ee27e | 24 | *servo_in=angle; |
backman | 11:03d5aa2511c4 | 25 | |
backman | 1:82bc25a7b68b | 26 | return angle; |
TonyLin | 15:57567d3ee27e | 27 | } |