Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 544 00008 #define MAX 2400 00009 #define STEP 50 00010 //Time delay between steps in milliseconds 00011 #define TIME 20 //100 00012 00013 00014 #define DELTA 50 00015 00016 DigitalOut myLed(LED1); 00017 DigitalIn myButton(USER_BUTTON); 00018 00019 DigitalIn myButton_2(D0); 00020 00021 PwmOut myServo(D3); 00022 00023 00024 00025 00026 void motor_on(void) 00027 { 00028 00029 //myServo.period_ms(20); 00030 myServo.pulsewidth_us(MID); //NB in microseconds 00031 00032 } 00033 00034 void motor_off(void) 00035 { 00036 myServo.pulsewidth_us(MIN+2*DELTA); //NB in microseconds 00037 } 00038 00039 00040 bool button_change = false; 00041 00042 int main() { 00043 00044 wait(1); 00045 00046 myServo.pulsewidth_us(MAX); //NB in microseconds 00047 wait(3); 00048 00049 00050 while (1) 00051 { 00052 00053 00054 00055 if (myButton) 00056 { 00057 00058 00059 for (int i=MAX; i>MIN; i=i-10) 00060 { 00061 myServo.pulsewidth_us(i); //NB in microseconds 00062 wait_ms(25); 00063 } 00064 00065 for (int i=MIN; i<MAX; i=i+10) 00066 { 00067 myServo.pulsewidth_us(i); //NB in microseconds 00068 wait_ms(25); 00069 } 00070 00071 wait(1); 00072 00073 00074 00075 00076 } 00077 00078 00079 00080 00081 00082 } 00083 00084 00085 }
Generated on Sat Jul 16 2022 10:17:28 by
1.7.2