Test servo using the serial port.
Dependencies: mbed
TFC_servo_test.cpp
00001 #include "mbed.h" 00002 #include "TFC.h" 00003 00004 bool isValid(float); 00005 00006 Serial pc(USBTX, USBRX); 00007 00008 int main(){ 00009 float pos = 0; 00010 int deg = 0; 00011 uint8_t servo = 0; 00012 00013 TFC_Init(); 00014 00015 pc.printf("Please enter a posiiton for your servo (-1.0-1.0)\r\n"); 00016 00017 while(1){ 00018 pc.scanf("%f", &pos); 00019 00020 if(isValid(pos)){ 00021 deg = pos * 90; 00022 pc.printf("Your servo is at position %1.3f or %2i degrees \r", pos, deg); 00023 TFC_SetServo(servo, pos); 00024 } 00025 else{ 00026 pc.printf("Sorry, invalid command. \r"); 00027 pos = 0; 00028 TFC_SetServo(servo, pos); 00029 } 00030 wait_ms(500); 00031 } 00032 } 00033 00034 bool isValid(float pos){\ 00035 if (pos <= 1.0f && pos >= -1.0f) 00036 return true; 00037 else 00038 return false; 00039 }
Generated on Sun Jul 17 2022 02:14:41 by 1.7.2