servo
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 //Program to 'sweep' test a 'standard RC type servo 00003 //Define some parameters using compiler directive '#define' 00004 //Check Servo DATA if 0.75ms to 2.25ms then use min=750 and max=2250 00005 //NB be values in microseconds (Following are generic values) 00006 #define MID 1500 00007 #define MIN 1000 00008 #define MAX 2000 00009 #define STEP 50 00010 //Time delay between steps in milliseconds 00011 #define TIME 400 00012 00013 DigitalOut myLed(LED1); 00014 DigitalIn myButton(USER_BUTTON); 00015 00016 PwmOut myServo(D11); 00017 00018 int main() { 00019 00020 myServo.period_ms(20); 00021 myServo.pulsewidth_us(MID); //NB in microseconds 00022 00023 while(true) { 00024 for (int i=MIN;i<=MAX;i+=STEP){ 00025 myServo.pulsewidth_us(i); 00026 wait_ms(TIME); 00027 } 00028 for (int i=MAX;i>=MIN;i-=STEP){ 00029 myServo.pulsewidth_us(i); 00030 wait_ms(TIME); 00031 } 00032 } 00033 }
Generated on Mon Sep 5 2022 19:34:28 by
1.7.2