Simon Ford
/
ServoProgram
Example program, usingthe Servo library
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "Servo.h" 00003 00004 Servo myservo(p21); 00005 Serial pc(USBTX, USBRX); 00006 00007 int main() { 00008 printf("Servo Calibration Controls:\n"); 00009 printf("1,2,3 - Position Servo (full left, middle, full right)\n"); 00010 printf("4,5 - Decrease or Increase range\n"); 00011 00012 float range = 0.0005; 00013 float position = 0.5; 00014 00015 while(1) { 00016 switch(pc.getc()) { 00017 case '1': position = 0.0; break; 00018 case '2': position = 0.5; break; 00019 case '3': position = 1.0; break; 00020 case '4': range += 0.0001; break; 00021 case '5': range -= 0.0001; break; 00022 } 00023 printf("position = %.1f, range = +/-%0.4f\n", position, range); 00024 myservo.calibrate(range, 45.0); 00025 myservo = position; 00026 } 00027 }
Generated on Tue Jul 12 2022 12:37:03 by 1.7.2