![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
VEX robotics 393 motor control test
main.cpp
- Committer:
- dbearg
- Date:
- 2014-01-28
- Revision:
- 1:c41ae3b710a2
- Parent:
- 0:1719fc9a160e
- Child:
- 2:a42e1062af7b
File content as of revision 1:c41ae3b710a2:
//================================== // Add any libraries that you use: //================================== #include "mbed.h" #include "Servo.h" //================================== // Add variables: //================================== //add a servo to PWM output on pin 25 Servo myservo(p21); //add a variable for motor speed //0.0 is full counter-clockwise //0.5 is zero rpm //1.0 is full clockwise float speed = 0.5; //add variables for the 4 onboard LEDS DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); //PC USB link Serial pc(USBTX, USBRX); //========================================================== // MAIN FUNCTION // waits for button press, then uses the button code above //========================================================== int main() { //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"); while(1) { //get the value for speed char c = pc.getc(); wait(0.001); //up logic if((c == 'u') && (speed < 1.0)) { speed += 0.001; myservo = speed; } //down logic if((c == 'd') && (speed > 0.0)) { speed -= 0.001; myservo = speed; } //display the speed to the PC pc.printf("%c %1.3f \n \r",c,speed); } //end while loop } //end of main function