![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Test servo using the serial port.
Dependencies: mbed
Revision 0:4abb1d756ad6, committed 2014-10-12
- Comitter:
- jmar11
- Date:
- Sun Oct 12 17:21:05 2014 +0000
- Commit message:
- First commit.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FRDM-TFC.lib Sun Oct 12 17:21:05 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Texas-State-IEEE-Robotics/code/FRDM-TFC/#a7cdfa497d52
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TFC_servo_test.cpp Sun Oct 12 17:21:05 2014 +0000 @@ -0,0 +1,39 @@ +#include "mbed.h" +#include "TFC.h" + +bool isValid(float); + +Serial pc(USBTX, USBRX); + +int main(){ + float pos = 0; + int deg = 0; + uint8_t servo = 0; + + TFC_Init(); + + pc.printf("Please enter a posiiton for your servo (-1.0-1.0)\r\n"); + + while(1){ + pc.scanf("%f", &pos); + + if(isValid(pos)){ + deg = pos * 90; + pc.printf("Your servo is at position %1.3f or %2i degrees \r", pos, deg); + TFC_SetServo(servo, pos); + } + else{ + pc.printf("Sorry, invalid command. \r"); + pos = 0; + TFC_SetServo(servo, pos); + } + wait_ms(500); + } +} + +bool isValid(float pos){\ + if (pos <= 1.0f && pos >= -1.0f) + return true; + else + return false; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Oct 12 17:21:05 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file