servo motor test of CORE-1000

Dependencies:   Servo mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Servo.h"
00003 
00004 Servo myservo(PB_13);
00005 Serial pc(USBTX, USBRX);
00006 
00007 int main() {
00008     printf("Servo Calibration Controls:\r\n");
00009     printf("1,2,3 - Position Servo (full left, middle, full right)\r\n");
00010     printf("4,5 - Decrease or Increase range\r\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\r\n", position, range);
00024         myservo.calibrate(range, 45.0); 
00025         myservo = position;
00026     }
00027 }
00028 
00029 
00030 /* test
00031 
00032 // Hello World to sweep a servo through its full range
00033 
00034 #include "mbed.h"
00035 #include "Servo.h"
00036 
00037 Servo myservo(PA_15);
00038 
00039 int main() {    
00040     for(float p=0; p<1.0; p += 0.1) {
00041         myservo = p;
00042         wait(0.2);
00043     }
00044 }
00045 */