Hello, I'm a complete noob and trying to get both motors to run at the same time, the idea is that the program should receive an input and keep the previous motor running, could anyone please help me?
PROGRAM:
#include <Servo.h>
#include <SoftwareSerial.h>
int led1 = 6;
int vel_mtrasero=1000;
int vel_mprincipal=1000;
int giro=90;
Servo ESC;
Servo ESC1;
void setup() {
Serial.begin(9600);
//---------SETUP DE ESC-------------------------
ESC.attach(11); //Aciva el ESC
ESC1.attach(10);
ESC.writeMicroseconds(1000);
ESC1.writeMicroseconds(1000);
delay(5000);
//--------------------led1--------------------------
pinMode(led1,OUTPUT);
}
void loop() {
//----------SETUP BLUETOOTH------------
char DATO;
//-------------------------------------
if (Serial.available()>0){
ESC.writeMicroseconds(vel_mtrasero);
ESC1.writeMicroseconds(vel_mprincipal);
}
//-----------------------TRADUCCION DE DATOS DEL CELU-----------
while (Serial.available()>0){
DATO=Serial.read();
Serial.println(DATO);
switch(DATO){
//----------------------MOTOR TRASERO------------
//--------VEL MAXIMA------------
case'3': //en el caso de que lea "3"
vel_mtrasero=2000;
digitalWrite(led1,HIGH); //se prende la luz
break;
//------VEL MEDIA----------
case'4': //en el caso de que lea "4"
vel_mtrasero=1200;
digitalWrite(led1,HIGH); //se prende la luz
break;
//----________________--MOTOR PRINCIPAL--------
//------VEL MAXIMA------------
case'1': //en caso de que lea "1"
vel_mprincipal=2000;
digitalWrite(led1,HIGH); //se prende la luz
break;
//------VEL MEDIA--------------
case'2': //en caso de que lea "2"
vel_mprincipal=1200;
digitalWrite(led1,HIGH); //se prende la luz
break;
//----------------------------APAGAR LOS DOS MOTORES-----------
case'5':
vel_mtrasero=0;
vel_mprincipal=0;
digitalWrite(led1,LOW);
break;
}
}
}