Update 'Deplacement-robot/bluetooth_control/bluetooth_control.ino'

This commit is contained in:
Estevan BIAU-LOYER 2023-12-12 14:35:34 +01:00
parent a036ab0626
commit 940fcc45d1
1 changed files with 45 additions and 58 deletions

View File

@ -1,5 +1,4 @@
#include <SoftwareSerial.h>
const int analogPin = A0; // Analog input pin on Arduino
#define RX_PIN 13 // Connected to HC-05 TX pin
#define TX_PIN 12 // Connected to HC-05 RX pin
#define LED_PIN 2 // Connected to LED pin
@ -72,7 +71,6 @@ void RotateRelative()
{
//We move X steps from the current position of the stepper motor in a given direction.
//The direction is determined by the multiplier (+1 or -1)
runallowed = true; //allow running - this allows entering the RunTheMotor() function.
stepper.setMaxSpeed(receivedSpeed); //set speed
stepper.move(directionMultiplier * receivedSteps); //set relative distance and direction
@ -124,12 +122,12 @@ void RotateAbsolute2()
//The AccelStepper library keeps track of the position.
//The direction is determined by the multiplier (+1 or -1)
//Why do we need negative numbers? - If you drive a threaded rod and the zero position is in the middle of the rod...
runallowed = true; //allow running - this allows entering the RunTheMotor() function.
stepper2.setMaxSpeed(receivedSpeed); //set speed
stepper2.moveTo(directionMultiplier2 * receivedSteps); //set relative distance
}
void readinfo()
{
if (bluetooth.available() > 0) //if something comes from the computer
@ -144,9 +142,11 @@ void readinfo()
case 'L':
digitalWrite(LED_PIN, HIGH);
break;
case 'O':
digitalWrite(LED_PIN, LOW);
break;
case 'P': //P uses the move() function of the AccelStepper library, which means that it moves relatively to the current position.
receivedSteps = bluetooth.parseFloat(); //value for the steps
@ -154,85 +154,72 @@ void readinfo()
directionMultiplier = 1; //We define the direction
bluetooth.println("Positive direction."); //print the action
RotateRelative(); //Run the function
//example: P2000 400 - 2000 steps (5 revolution with 400 step/rev microstepping) and 400 steps/s speed
//In theory, this movement should take 5 seconds
break;
case 'N': //N uses the move() function of the AccelStepper library, which means that it moves relatively to the current position.
case 'N': //N uses the move() function of the AccelStepper library, which means that it moves relatively to the current position.
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = -1; //We define the direction
bluetooth.println("Negative direction."); //print action
RotateRelative(); //Run the function
//example: N2000 400 - 2000 steps (5 revolution with 400 step/rev microstepping) and 500 steps/s speed; will rotate in the other direction
//In theory, this movement should take 5 seconds
break;
case '1': //avancer
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = -1; //We define the direction
directionMultiplier2 = 1;
bluetooth.println("CA AVANCE."); //print the action
RotateRelative();
RotateRelative2(); //Run the function
//example: P2000 400 - 2000 steps (5 revolution with 400 step/rev microstepping) and 400 steps/s speed
//In theory, this movement should take 5 seconds
break;
case '1': //avancer
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = -1; //We define the direction
directionMultiplier2 = 1;
bluetooth.println("CA AVANCE."); //print the action
RotateRelative();
RotateRelative2(); //Run the function
//example: P2000 400 - 2000 steps (5 revolution with 400 step/rev microstepping) and 400 steps/s speed
//In theory, this movement should take 5 seconds
break;
case '2': //reculer
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = 1; //We define the direction
directionMultiplier2 = -1;
bluetooth.println("CA RECULE"); //print the action
RotateRelative();
RotateRelative2(); //Run the function
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = 1; //We define the direction
directionMultiplier2 = -1;
bluetooth.println("CA RECULE"); //print the action
RotateRelative();
RotateRelative2(); //Run the function
//example: P2000 400 - 2000 steps (5 revolution with 400 step/rev microstepping) and 400 steps/s speed
//In theory, this movement should take 5 seconds
break;
//example: P2000 400 - 2000 steps (5 revolution with 400 step/rev microstepping) and 400 steps/s speed
//In theory, this movement should take 5 seconds
break;
case '3': //a gauche
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = 1; //We define the direction
directionMultiplier2 = 1;
bluetooth.println("CA TOURNE A GAUCHE"); //print the action
RotateRelative();
RotateRelative2(); //Run the function
//example: P2000 400 - 2000 steps (5 revolution with 400 step/rev microstepping) and 400 steps/s speed
//In theory, this movement should take 5 seconds
break;
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = 1; //We define the direction
directionMultiplier2 = 1;
bluetooth.println("CA TOURNE A GAUCHE"); //print the action
RotateRelative();
RotateRelative2(); //Run the function
break;
case '4': //a droite.
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = -1; //We define the direction
directionMultiplier2 = -1;
bluetooth.println("CA TOURNE A DROITE"); //print the action
RotateRelative();
RotateRelative2(); //Run the function
//example: P2000 400 - 2000 steps (5 revolution with 400 step/rev microstepping) and 400 steps/s speed
//In theory, this movement should take 5 seconds
break;
receivedSteps = bluetooth.parseFloat(); //value for the steps
receivedSpeed = bluetooth.parseFloat(); //value for the speed
directionMultiplier = -1; //We define the direction
directionMultiplier2 = -1;
bluetooth.println("CA TOURNE A DROITE"); //print the action
RotateRelative();
RotateRelative2(); //Run the function
break;
default:
default:
break;
}
}
}
}