譯文 張
/
7_7Boboobooo
123
Fork of Boboobooo by
servo_api.cpp@7:f04bde0ca846, 2014-07-07 (annotated)
- Committer:
- even
- Date:
- Mon Jul 07 15:23:50 2014 +0000
- Revision:
- 7:f04bde0ca846
- Parent:
- 6:b046d6ff3745
- Child:
- 9:a891053657f3
half circle
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 |
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 | } |