![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
servo
main.cpp@2:10498697e83b, 2021-09-03 (annotated)
- Committer:
- silviosz
- Date:
- Fri Sep 03 12:16:55 2021 +0000
- Revision:
- 2:10498697e83b
- Parent:
- 1:40d2fd0b99e6
- Child:
- 3:2848f736b75a
2021-09-03_Servo_02
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
silviosz | 2:10498697e83b | 1 | // https://os.mbed.com/questions/1680/Analog-In-PWM-Out-to-control-rc-servo/ |
silviosz | 2:10498697e83b | 2 | // 2021-08-26 |
simon | 1:40d2fd0b99e6 | 3 | |
simon | 1:40d2fd0b99e6 | 4 | #include "mbed.h" |
silviosz | 2:10498697e83b | 5 | PwmOut servo(D9); |
simon | 1:40d2fd0b99e6 | 6 | |
silviosz | 2:10498697e83b | 7 | int main() |
silviosz | 2:10498697e83b | 8 | { |
silviosz | 2:10498697e83b | 9 | servo.period_us(20000); //20ms period, typical for analog RC servo |
silviosz | 2:10498697e83b | 10 | int servopulsewidth=1500; |
silviosz | 2:10498697e83b | 11 | servo.pulsewidth_us(servopulsewidth); //centers the servo. Usually a RC servos range is from 1000 to 2000us. |
silviosz | 2:10498697e83b | 12 | while(1) |
silviosz | 2:10498697e83b | 13 | { |
silviosz | 2:10498697e83b | 14 | //servo.pulsewidth_us(1500); //increments servopulsewidth with 1 |
silviosz | 2:10498697e83b | 15 | //wait(0.5); |
silviosz | 2:10498697e83b | 16 | servo.pulsewidth_us(1000); //increments servopulsewidth with 1 |
silviosz | 2:10498697e83b | 17 | wait(0.5); |
silviosz | 2:10498697e83b | 18 | servo.pulsewidth_us(2000); //increments servopulsewidth with 1 |
silviosz | 2:10498697e83b | 19 | wait(0.5); |
simon | 1:40d2fd0b99e6 | 20 | } |
silviosz | 2:10498697e83b | 21 | } |