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