Clark Lin
/
0709
QQQQQQQ
Fork of 7_7Boboobooo by
servo_api.cpp@9:c318ee86d6e9, 2014-07-09 (annotated)
- Committer:
- physicsgood
- Date:
- Wed Jul 09 07:34:23 2014 +0000
- Revision:
- 9:c318ee86d6e9
- Parent:
- 7:f04bde0ca846
0709
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" |
physicsgood | 9:c318ee86d6e9 | 4 | #define right_end 0.057 //90 |
physicsgood | 9:c318ee86d6e9 | 5 | #define left_end 0.025 //-90 |
backman | 1:82bc25a7b68b | 6 | |
backman | 1:82bc25a7b68b | 7 | //memory opt |
backman | 1:82bc25a7b68b | 8 | // 5 degree seperate |
physicsgood | 6:b046d6ff3745 | 9 | BX_servo::BX_servo(void) |
physicsgood | 6:b046d6ff3745 | 10 | { |
physicsgood | 6:b046d6ff3745 | 11 | angle = 0; |
physicsgood | 6:b046d6ff3745 | 12 | servo_in= new PwmOut(PTB0); |
physicsgood | 6:b046d6ff3745 | 13 | servo_in->period_ms(20); |
physicsgood | 6:b046d6ff3745 | 14 | } |
backman | 1:82bc25a7b68b | 15 | |
physicsgood | 6:b046d6ff3745 | 16 | float BX_servo::set_angle(float a) |
physicsgood | 6:b046d6ff3745 | 17 | { |
backman | 1:82bc25a7b68b | 18 | |
physicsgood | 6:b046d6ff3745 | 19 | if( a<left_end ) |
physicsgood | 6:b046d6ff3745 | 20 | a=left_end; |
physicsgood | 6:b046d6ff3745 | 21 | else if(a>right_end) |
physicsgood | 6:b046d6ff3745 | 22 | a=right_end; |
physicsgood | 6:b046d6ff3745 | 23 | angle=a; |
physicsgood | 6:b046d6ff3745 | 24 | *servo_in=angle; |
backman | 1:82bc25a7b68b | 25 | |
backman | 1:82bc25a7b68b | 26 | return angle; |
physicsgood | 6:b046d6ff3745 | 27 | } |