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 /* Servo controller mini-project. Three button control for HS422 servo, left 10*, right 10*, reset to center. 00002 Austin Sloop, 1/7/16 00003 */ 00004 00005 #include "mbed.h" 00006 00007 DigitalIn right(p5); //Right button, CW 00008 DigitalIn left(p9); //Left button, CCW 00009 DigitalIn reset(p7); //Middle button, reset to 0 00010 00011 PwmOut servo(p21); //Servo Control 00012 DigitalOut L(LED1); //Debug LED 00013 DigitalOut R(LED3); //Debugging Purposes 00014 DigitalOut C(LED2); //Debug LED 00015 00016 int i=1500; //value of servo position 00017 int main(){ 00018 servo.period(0.020); 00019 while(1){ 00020 if (right==1){ 00021 wait(0.05); 00022 if (right==0){ 00023 i=i+100; 00024 R=1; 00025 wait(.1); 00026 R=0; 00027 } 00028 } 00029 if (left==1) { 00030 wait(0.05); 00031 if (left==0){ 00032 i=i-100; 00033 L=1; 00034 wait(.1); 00035 L=0; 00036 } 00037 } 00038 if (reset==1) { 00039 wait(0.05); 00040 if (reset==0){ 00041 i=1500; 00042 C=1; 00043 wait(.1); 00044 C=0; 00045 } 00046 } 00047 if (i>2400) {i=2400;} //Prevention of over-extention of servo 00048 if (i<600) {i=600;} 00049 servo.pulsewidth_us(i); 00050 } 00051 }
Generated on Sun Jul 31 2022 11:30:53 by
1.7.2