David Beargie
/
vex_motor_USBcontrol
VEX robotics 393 motor control test
Revision 2:a42e1062af7b, committed 2014-02-01
- Comitter:
- dbearg
- Date:
- Sat Feb 01 16:54:56 2014 +0000
- Parent:
- 1:c41ae3b710a2
- Commit message:
- added title text
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c41ae3b710a2 -r a42e1062af7b main.cpp --- a/main.cpp Tue Jan 28 20:43:23 2014 +0000 +++ b/main.cpp Sat Feb 01 16:54:56 2014 +0000 @@ -1,6 +1,16 @@ +//================================== +// +// VEX MOTOR CONTROL EXAMPLE PROGRAM +// ---------------------------- +// Controls a PWM VEX motor speed +// with the "u" and "d" keys +// +//================================== + //================================== // Add any libraries that you use: //================================== + #include "mbed.h" #include "Servo.h" @@ -10,7 +20,8 @@ //================================== -//add a servo to PWM output on pin 25 +//add a servo to PWM output on pin 21 + Servo myservo(p21); //add a variable for motor speed @@ -21,7 +32,7 @@ float speed = 0.5; //add variables for the 4 onboard LEDS -DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); +PwmOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); //PC USB link Serial pc(USBTX, USBRX); @@ -36,8 +47,8 @@ //prompt the PC user for differential speed value - pc.printf("Control of LED dimmer by host terminal\n\r"); - pc.printf("Press 'u‘ = brighter, 'd‘ = dimmer\n\r"); + pc.printf("Control of servo speed by host terminal\n\r"); + pc.printf("Press 'u' = brighter, 'd' = dimmer\n\r"); while(1) { @@ -48,19 +59,22 @@ //up logic - if((c == 'u') && (speed < 1.0)) { - speed += 0.001; + if((c == 'u') && (speed < 0.99)) { + speed += 0.01; myservo = speed; + led1 = speed; } //down logic if((c == 'd') && (speed > 0.0)) { - speed -= 0.001; + speed -= 0.01; myservo = speed; + led1 = speed; } //display the speed to the PC + pc.printf("%c %1.3f \n \r",c,speed); }