![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
servo
main.cpp@3:2848f736b75a, 23 months ago (annotated)
- Committer:
- henriquer
- Date:
- Mon Sep 05 19:34:06 2022 +0000
- Revision:
- 3:2848f736b75a
- Parent:
- 2:10498697e83b
servo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 1:40d2fd0b99e6 | 1 | #include "mbed.h" |
henriquer | 3:2848f736b75a | 2 | //Program to 'sweep' test a 'standard RC type servo |
henriquer | 3:2848f736b75a | 3 | //Define some parameters using compiler directive '#define' |
henriquer | 3:2848f736b75a | 4 | //Check Servo DATA if 0.75ms to 2.25ms then use min=750 and max=2250 |
henriquer | 3:2848f736b75a | 5 | //NB be values in microseconds (Following are generic values) |
henriquer | 3:2848f736b75a | 6 | #define MID 1500 |
henriquer | 3:2848f736b75a | 7 | #define MIN 1000 |
henriquer | 3:2848f736b75a | 8 | #define MAX 2000 |
henriquer | 3:2848f736b75a | 9 | #define STEP 50 |
henriquer | 3:2848f736b75a | 10 | //Time delay between steps in milliseconds |
henriquer | 3:2848f736b75a | 11 | #define TIME 400 |
henriquer | 3:2848f736b75a | 12 | |
henriquer | 3:2848f736b75a | 13 | DigitalOut myLed(LED1); |
henriquer | 3:2848f736b75a | 14 | DigitalIn myButton(USER_BUTTON); |
henriquer | 3:2848f736b75a | 15 | |
henriquer | 3:2848f736b75a | 16 | PwmOut myServo(D11); |
henriquer | 3:2848f736b75a | 17 | |
henriquer | 3:2848f736b75a | 18 | int main() { |
henriquer | 3:2848f736b75a | 19 | |
henriquer | 3:2848f736b75a | 20 | myServo.period_ms(20); |
henriquer | 3:2848f736b75a | 21 | myServo.pulsewidth_us(MID); //NB in microseconds |
henriquer | 3:2848f736b75a | 22 | |
henriquer | 3:2848f736b75a | 23 | while(true) { |
henriquer | 3:2848f736b75a | 24 | for (int i=MIN;i<=MAX;i+=STEP){ |
henriquer | 3:2848f736b75a | 25 | myServo.pulsewidth_us(i); |
henriquer | 3:2848f736b75a | 26 | wait_ms(TIME); |
henriquer | 3:2848f736b75a | 27 | } |
henriquer | 3:2848f736b75a | 28 | for (int i=MAX;i>=MIN;i-=STEP){ |
henriquer | 3:2848f736b75a | 29 | myServo.pulsewidth_us(i); |
henriquer | 3:2848f736b75a | 30 | wait_ms(TIME); |
henriquer | 3:2848f736b75a | 31 | } |
simon | 1:40d2fd0b99e6 | 32 | } |
silviosz | 2:10498697e83b | 33 | } |