TaChing Yu / Mbed 2 deprecated Wifi_Servo

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(D9);
00005 Serial esp8266(D6, D7);
00006 Serial pc(USBTX, USBRX);
00007 
00008 int main() {
00009     printf("Servo Calibration Controls:\n");
00010     printf("1,2,3 - Position Servo (full left, middle, full right)\n");
00011     printf("4,5 - Decrease or Increase range\n");
00012  
00013     float range = 0.0005;
00014     float position = 0.5;
00015     
00016     while(1) {                   
00017         switch(esp8266.getc()) {
00018             case '1': position = 0.0; break;
00019             case '2': position = 0.5; break;
00020             case '3': position = 1.0; break;
00021             case '4': range += 0.0002f; break; 
00022             case '5': range -= 0.0002f; break; 
00023         }
00024         printf("position = %.1f, range = +/-%0.4f\n", position, range);
00025         myservo.calibrate(range, 45.0); 
00026         myservo = position;
00027     }
00028     }