this is a blocking call (cf the documentation)
that's why you don't get simultaneous movement. Each time you get a command, you wait until it's completed before fetching the next one.
you need to use run() in the loop to get the motors to move when needed.
--
side note, why do you go for Strings for the command when you have a perfect c-string... it's duplicating memory for nothing.
change
into
Serial.print("Comanda primita: ");
Serial.println(command); // Afișează comanda primită
if your command fits only on one character, there is no need to use strcmp()
instead of
just test the first character it will be faster
if (command[0] == '1') {
and of course, as you have many of those, a switch/case is more appropriate
switch(command[0]) {
case '1':
motor1.runToNewPosition(1000);
motor1.runToNewPosition(0);
motor1.runToNewPosition(-1000);
// Adaugă aici comenzi pentru motorul 1
break;
case '2':
motor1.setSpeed(5);
motor1.runSpeed();
motor1.runToNewPosition(0);
motor1.runToNewPosition(500);
//motor1.runToNewPosition(100);
break;
case '3':
motor1.setSpeed(5);
motor1.runSpeed();
motor1.runToNewPosition(1026);
motor1.runToNewPosition(0);
//motor1.moveTo(x);
// Adaugă aici comenzi pentru motorul 2
break;
case '4':
motor1.runToNewPosition(-1026);
while (motor1.isRunning()) {
motor2.runToNewPosition(-1026);
}
break;
case 'A':
// Adaugă aici comenzi pentru ambele motoare
break;
case 'B':
break;
default:
// Tratează cazurile de comenzi necunoscute
Serial.println("Comanda Bluetooth necunoscuta");
break;
}
(but solve those blocking waits until you get to position)