Proyecto 20 - Coche RC Bluetooth
En este tutorial vamos a ver como convertir el vehículo del Proyecto 18 en un coche RC controlado por bluetooth.
Sólo hay que sustituir el receptor de infrarrojos por un módulo HC-05 y modificar ligeramente el código del Proyecto 19.
Como todo proyecto de cierta envergadura, iremos paso a paso, haciendo pequeñas pruebas y añadiendo complejidad según avanzamos.
En un primer lugar utilizaremos la aplicación BlueTerm para controlar el coche, luego modificaremos el código para adaptarlo a la aplicación Bluetooth RC Controler, que tiene un aspecto mucho más atractivo y funcional.
Esquema
Sketch v1.
Versión del sketch para BlueTerm app
/*
* Control DC motor with Smartphone via bluetooth
* created by Rui Santos, http://randomnerdtutorials.com
* modificado por angmuz, https://sites.google.com/site/angmuz
*/
int motor1Pin1 = 10; // pin 2 on L293D IC
int motor1Pin2 = 9; // pin 7 on L293D IC
int enableM1 = 5; // pin 1 on L293D IC
int motor2Pin1 = 13; // pin 10 on L293D IC
int motor2Pin2 = 4; // pin 15 on L293D IC
int enableM2 = 6; // pin 9 on L293D IC
int luces = 2; // Leds al pin 2
int state;
int flag=0; //makes sure that the serial only prints once the state
void setup() {
// sets the pins as outputs:
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enableM1, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enableM2, OUTPUT);
pinMode(luces, OUTPUT);
Serial.begin(9600);
}
void loop() {
//if some date is sent, reads it and saves in state
if(Serial.available() > 0){
state = Serial.read();
flag=0;
}
// if the state is '0' the motors will turn off
if (state == '0') {
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
if(flag == 0){
Serial.println("Motors: off");
flag=1;
}
}
// if the state is '1' the car go forward
else if (state == '1') {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D high
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
if(flag == 0){
Serial.println("Go forward");
flag=1;
}
}
// if the state is '2' the car go backward
else if (state == '2') {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D low
digitalWrite(motor2Pin1, HIGH); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D high
if(flag == 0){
Serial.println("Go backward");
flag=1;
}
}
// if the state is '3' the car turn right
else if (state == '3') {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
if(flag == 0){
Serial.println("Turn right");
flag=1;
}
}
// if the state is '4' the car turn left
else if (state == '4') {
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
if(flag == 0){
Serial.println("Turn left");
flag=1;
}
}
// if the state is '5' the leds will turn ON
else if (state == '5') {
digitalWrite(luces, HIGH); // set leds ON
if(flag == 0){
Serial.println("Leds ON");
flag=1;
}
}
// if the state is '6' the leds will turn OFF
else if (state == '6') {
digitalWrite(luces, LOW); // set leds OFF
if(flag == 0){
Serial.println("Leds OFF");
flag=1;
}
}
}
Sketch v2
Versión del sketch para BlueTerm app con instrucciones switch/case
/*
* Bluetooth RC Car con BlueTerm app e instrucciones switch/case
*
*/
int motor1Pin1 = 10; // pin 2 on L293D IC
int motor1Pin2 = 9; // pin 7 on L293D IC
int enableM1 = 5; // pin 1 on L293D IC
int motor2Pin1 = 13; // pin 10 on L293D IC
int motor2Pin2 = 4; // pin 15 on L293D IC
int enableM2 = 6; // pin 9 on L293D IC
int luces = 2; // Led rojo al pin 2
char command = 'S';
int flag=0; //makes sure that the serial only prints once the state
void setup() {
// sets the pins as outputs:
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enableM1, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enableM2, OUTPUT);
pinMode(luces, OUTPUT);
Serial.begin(9600);
}
// Funciones
// if the state is '0' the motors will turn off
void motorsOff(){
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
if(flag == 0){
Serial.println("Motors: off");
flag=1;
}
}
// if the state is '1' the car go forward
void goForward() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D high
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
if(flag == 0){
Serial.println("Go forward");
flag=1;
}
}
// if the state is '2' the car go backward
void goBackward() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D low
digitalWrite(motor2Pin1, HIGH); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D high
if(flag == 0){
Serial.println("Go backward");
flag=1;
}
}
// if the state is '3' the car turn right
void turnRight() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
if(flag == 0){
Serial.println("Turn right");
flag=1;
}
}
// if the state is '4' the car turn left
void turnLeft() {
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
if(flag == 0){
Serial.println("Turn left");
flag=1;
}
}
// if the state is '5' the leds will turn ON
void ledsOn() {
digitalWrite(luces, HIGH); // set leds ON
if(flag == 0){
Serial.println("Leds ON");
flag=1;
}
}
// if the state is '6' the leds will turn OFF
void ledsOff() {
digitalWrite(luces, LOW); // set leds OFF
if(flag == 0){
Serial.println("Leds OFF");
flag=1;
}
}
void loop() {
//if some date is sent, reads it and saves in command
if(Serial.available() > 0){
command = Serial.read();
flag=0;
switch(command){
case '0':
motorsOff();
break;
case '1':
goForward();
break;
case '2':
goBackward();
break;
case '3':
turnRight();
break;
case '4':
turnLeft();
break;
case '5':
ledsOn();
break;
case '6':
ledsOff();
break;
}
}
}
Sketch v3
Versión del sketch para Arduino Bluetooth RC Car app con instrucciones switch/case
Partiendo del código anterior es muy fácil adaptarlo a la aplicación Arduino Bluetooth RC Car de Andi.Co
Esta aplicación tiene un aspecto más atractivo y su manejo es muy fácil ya que está diseñada específicamente para controlar coches desde el móvil mediante bluetooth. Mira la interfaz, no me negarás que es una chulada.
En las versiones anteriores para BlueTerm no he incluido el zumbador por simplificar, en esta versión y porteriores sí está incluido.
En esta primera versión he programado solamente las cuatro funciones básicas de avanzar, retroceder, girar a la derecha y a la izquierda.
Puedes consultar el código original de la aplicación aquí.
Lista de caracteres usados:
Forward---------------------F
Back-------------------------B
Left---------------------------L
Right-------------------------R
Forward Left--------------G
Forward Right------------I
Back Left------------------H
Back Right----------------J
Stop-------------------------S
Front Lights On---------W
Front Lights Off---------w (lower case)
Back Lights On---------U
Back Lights Off---------u (lower case)
Horn On-------------------V
Horn Off--------------------v (lower case)
Extra On (triangle)-----X
Extra Off (triangle)-----x (lower case)
Speed 0-------------------0
Speed 10-----------------1
Speed 20-----------------2
Speed 30-----------------3
Speed 40-----------------4
Speed 50-----------------5
Speed 60-----------------6
Speed 70-----------------7
Speed 80-----------------8
Speed 90-----------------9
Speed 100---------------q
Everything OFF--------D
Descarga la aplicación desde Google Play market:
Special thanks to Andi.Co for this amazing app, I´t works really fine.
// RC Car con Bluetooth RC Controller app
// version 3 On Change mode con buzzer
int motor1Pin1 = 10; // pin 2 on L293D IC
int motor1Pin2 = 9; // pin 7 on L293D IC
int enableM1 = 5; // pin 1 on L293D IC
int motor2Pin1 = 13; // pin 10 on L293D IC
int motor2Pin2 = 4; // pin 15 on L293D IC
int enableM2 = 6; // pin 9 on L293D IC
int luces = 2; // Leds rojos al pin 2
int cortas = 3; // Luces frontales al pin 3
int buzz = 12; // Buzzer al pin 12
char command = 'S';
void setup() {
// sets the pins as outputs:
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enableM1, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enableM2, OUTPUT);
pinMode(luces, OUTPUT);
pinMode(cortas, OUTPUT);
pinMode(buzz, OUTPUT);
Serial.begin(9600);
}
// Funciones
// if the command is 'S' the motors will turn off
void motorsOff(){
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
}
// if the command is 'F' the car go forward
void goForward() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D high
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
}
// if the command is 'B' the car go backward
void goBackward() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D low
digitalWrite(motor2Pin1, HIGH); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D high
}
// if the command is 'R' the car turn right
void turnRight() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
}
// if the command is 'L' the car turn left
void turnLeft() {
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
}
// if the command is 'U' the leds will turn ON
void ledsOn() {
digitalWrite(luces, HIGH); // set leds ON
}
// if the command is 'u' the leds will turn OFF
void ledsOff() {
digitalWrite(luces, LOW); // set leds OFF
}
// if the command is 'W' the front leds will turn ON
void cortasOn() {
digitalWrite(cortas, HIGH); // set leds ON
}
// if the command is 'w' the front leds will turn OFF
void cortasOff() {
digitalWrite(cortas, LOW); // set leds OFF
}
// if the command is 'V' the buzzer will turn ON
void buzzOn() {
digitalWrite(buzz, HIGH); // set buzzer ON
}
// if the command is 'v' the buzzer will turn OFF
void buzzOff() {
digitalWrite(buzz, LOW); // set buzzer OFF
}
// if the command is 'D' all Off
void allOff(){
digitalWrite(luces, LOW); // set rear leds OFF
digitalWrite(cortas, LOW); // set front leds OFF
digitalWrite(buzz, LOW); // set buzzer OFF
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
}
void loop() {
//if some date is sent, reads it and saves in command
if(Serial.available() > 0){
command = Serial.read();
switch(command){
case 'S':
motorsOff();
break;
case 'F':
goForward();
break;
case 'B':
goBackward();
break;
case 'R':
turnRight();
break;
case 'L':
turnLeft();
break;
case 'U':
ledsOn();
break;
case 'u':
ledsOff();
break;
case 'W':
cortasOn();
break;
case 'w':
cortasOff();
break;
case 'V':
buzzOn();
break;
case 'v':
buzzOff();
break;
case 'D':
allOff();
break;
}
}
}
Sketch v4
Versión del sketch para Arduino Bluetooth RC Car app con instrucciones switch/case.
Programadas todas las funciones que permite la app.
A las funciones anteriores he añadido avanzar a la derecha e izquierda, retroceder a la derecha e izquierda.
También he añadido una función warningOn / Off y dos leds más en el frontal para simular las luces de emergencia.
Para hacer que el coche avance y gire a la vez, he cambiado el digitalWriteM1 y M2 por analogWrite, de esa forma hacemos que una de las ruegas gire más lenta que la otra, haciendo que el coche avance mientras tuerce a la derecha o izquierda.
/* Bluetooth RC Car
version 4 On Change mode con buzzer
luces cortas y 4 luces de posicion
y warning lights
Full motion functions
*/
int motor1Pin1 = 10; // pin 2 on L293D IC
int motor1Pin2 = 9; // pin 7 on L293D IC
int enableM1 = 5; // pin 1 on L293D IC
int motor2Pin1 = 13; // pin 10 on L293D IC
int motor2Pin2 = 4; // pin 15 on L293D IC
int enableM2 = 6; // pin 9 on L293D IC
int luces = 2; // Leds rojos al pin 2
int cortas = 3; // Luces cortas al pin 3
int buzz = 12; // Buzzer al pin 12
char command = 'S';
int cont = 0;
boolean warning = 0;
void setup() {
// sets the pins as outputs:
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(enableM1, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enableM2, OUTPUT);
pinMode(luces, OUTPUT);
pinMode(cortas, OUTPUT);
pinMode(buzz, OUTPUT);
Serial.begin(9600);
}
// Funciones
// if the command is 'S' the motors will turn off
void motorsOff(){
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
}
// if the command is 'F' the car go forward
void goForward() {
analogWrite(enableM1, 224); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D high
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
}
// if the command is 'I' the car go forward right
void goForwardRight() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D high
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
}
// if the command is 'G' the car go forward left
void goForwardLeft() {
analogWrite(enableM1, 200); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D high
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
}
// if the command is 'B' the car go backward
void goBackward() {
analogWrite(enableM1, 245); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D low
digitalWrite(motor2Pin1, HIGH); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D high
}
// if the command is 'J' the car go backward right
void goBackwardRight() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D low
digitalWrite(motor2Pin1, HIGH); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D high
}
// if the command is 'H' the car go backward left
void goBackwardLeft() {
analogWrite(enableM1, 200); // enable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, HIGH); // set pin 7 on L293D low
digitalWrite(motor2Pin1, HIGH); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D high
}
// if the command is 'R' the car turn right
void turnRight() {
digitalWrite(enableM1, HIGH); // enable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, HIGH); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
}
// if the command is 'L' the car turn left
void turnLeft() {
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, HIGH); // enable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D high
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, HIGH); // set pin 15 on L293D high
}
// if the command is 'U' the rear leds will turn ON
void ledsOn() {
digitalWrite(luces, HIGH); // set leds ON
}
// if the command is 'u' the rear leds will turn OFF
void ledsOff() {
digitalWrite(luces, LOW); // set leds OFF
}
// if the command is 'W' the front leds will turn ON
void cortasOn() {
digitalWrite(cortas, HIGH); // set leds ON
}
// if the command is 'w' the front leds will turn OFF
void cortasOff() {
digitalWrite(cortas, LOW); // set leds OFF
}
// if the command is 'X' the warning leds will turn ON for ten times
void warningOn() {
digitalWrite(luces, HIGH); // set leds ON
delay(500);
digitalWrite(luces, LOW);
delay(500);
warning = 1;
}
// if the command is 'x' the warning leds will turn OFF
void warningOff() {
digitalWrite(luces, LOW); // set leds ON
}
// if the command is 'V' the buzzer will turn ON
void buzzOn() {
digitalWrite(buzz, HIGH); // set buzzer ON
}
// if the command is 'v' the buzzer will turn OFF
void buzzOff() {
digitalWrite(buzz, LOW); // set buzzer OFF
}
// if the command is 'D' all Off
void allOff(){
digitalWrite(luces, LOW); // set leds OFF
digitalWrite(buzz, LOW); // set buzzer OFF
digitalWrite(cortas, LOW); // set cortas OFF
digitalWrite(enableM1, LOW); // disable M1
digitalWrite(enableM2, LOW); // disable M2
digitalWrite(motor1Pin1, LOW); // set pin 2 on L293D low
digitalWrite(motor1Pin2, LOW); // set pin 7 on L293D low
digitalWrite(motor2Pin1, LOW); // set pin 10 on L293D low
digitalWrite(motor2Pin2, LOW); // set pin 15 on L293D low
}
void loop() {
//if some date is sent, reads it and saves in command
if(Serial.available() > 0){
command = Serial.read();
switch(command){
case 'S':
motorsOff();
break;
case 'F':
goForward();
break;
case 'I':
goForwardRight();
break;
case 'G':
goForwardLeft();
break;
case 'B':
goBackward();
break;
case 'J':
goBackwardRight();
break;
case 'H':
goBackwardLeft();
break;
case 'R':
turnRight();
break;
case 'L':
turnLeft();
break;
case 'U':
ledsOn();
break;
case 'u':
ledsOff();
break;
case 'W':
cortasOn();
break;
case 'w':
cortasOff();
break;
case 'V':
buzzOn();
break;
case 'v':
buzzOff();
break;
case 'D':
allOff();
break;
case 'X':
warningOn();
break;
case 'x':
warningOff();
break;
}
if ((cont < 9) & (warning == 1)) {
cont++;
warningOn();
}
if (cont >=9) {
cont = 0;
warning = 0;
warningOff();
}
}
}