
Controle do sentido dos Eixos X e Y pelo Joystick
Dependencies: mbed X_NUCLEO_IHM01A1
Revision 32:06c343675a3e, committed 2019-04-24
- Comitter:
- rebecams
- Date:
- Wed Apr 24 18:58:10 2019 +0000
- Parent:
- 31:3aae82e6353c
- Commit message:
- joystick para eixos X+ X- Y+ Y-
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Apr 24 14:14:04 2019 +0000 +++ b/main.cpp Wed Apr 24 18:58:10 2019 +0000 @@ -65,50 +65,42 @@ // x = x_axis.read(); printf("\n Y axis: %f", y_axis.read()); // Show the value of the Y axis (0.0 to 1.0) // y = y_axis.read(); - printf("\n Button: %d", button.read()); // Show the button status (0 is pressed, 1 is not pressed) - - wait_ms(T_MS); // Wait time between reads - printf("Motor Control Application Example for 2 Motors\r\n\n"); - +//the button status (0 is pressed, 1 is not pressed) /*----- Movendo pra frente -----*/ /* Printing to the console. */ - printf("--> Moving forward: M1 %d steps, M2 %d steps.\r\n", STEPS >> 1, STEPS); if (x_axis.read()>0.6){ /* Moving N steps in the forward direction. */ + printf("--> Moving forward Motor 1"); motor1->run(StepperMotor::FWD); - motor1->wait_while_active(); } - else if (y_axis.read()>0.6){ + if (y_axis.read()>0.6){ + printf("--> Moving forward Motor 2"); motor2->run(StepperMotor::FWD); - motor2->wait_while_active(); } int position1 = motor1->get_position(); int position2 = motor2->get_position(); - printf(" Position: M1 %d, M2 %d.\r\n", position1, position2); + //printf(" Position: Motor 1 %d, Motor 2 %d.\r\n", position1, position2); /*----- Movendo pra trás -----*/ - if (x_axis.read()<0.4){ /* Moving N steps in the backward direction. */ - printf("--> Moving X backward: M1 %d steps, M2 %d steps.\r\n", STEPS >> 1, STEPS); + printf("--> Moving X backward Motor 1"); motor1->run(StepperMotor::BWD); } - else if (y_axis.read()<0.4){ - printf("--> Moving Y backward: M1 %d steps, M2 %d steps.\r\n", STEPS >> 1, STEPS); + if (y_axis.read()<0.4){ + printf("--> Moving Y backward Motor 2"); motor2->run(StepperMotor::BWD); } - else{ - soft_stop() + if (0.4<x_axis.read() and x_axis.read()<0.6){ + printf("--> Parado motor 1"); + motor1->soft_stop(); } - - /* Getting current position. */ - position1 = motor1->get_position(); - position2 = motor2->get_position(); - - /* Printing to the console. */ - printf(" Position: M1 %d, M2 %d.\r\n", position1, position2); + if (0.4<y_axis.read() and y_axis.read()<0.6){ + printf("--> Parado motor 2"); + motor2->soft_stop(); + } } } \ No newline at end of file