//SHIP SCIENCE ON STAGE BY PERE COMPTE JOVE WITH ARDUINO
#include <SoftwareSerial.h>
SoftwareSerial blue(10,11); // bluetooth controller WIRE YELLOW 10 TXD AND WIRE BLUE 11 RXD
char rec;
#include<Servo.h>
Servo myservo;
void setup() {
pinMode(2,OUTPUT); //WIRE BLUE TO DRIVER MOTOR
pinMode(3,OUTPUT); //WIRE GREEN TO DRIVER MOTOR
pinMode(4,OUTPUT); //WIRE YELLOW TO DRIVER MOTOR
pinMode(5,OUTPUT); //WIRE ORANGE TO DRIVER MOTOR
pinMode(7,OUTPUT); //ROOF. GREEN AND RED LEDS

Serial.begin(9600);
blue.begin(9600);
myservo.attach(9);//Servo rudder blade
}

void loop() {
if (blue.available()){
  rec=blue.read();
  Serial.println(rec);
  switch(rec){
    case'e':  //STOP
    digitalWrite(2,LOW);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,LOW);
    break;
        case'h': //FORWARD
    digitalWrite(2,HIGH);
    digitalWrite(3,LOW);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    break;
        case'b': //BACKWARD
    digitalWrite(2,LOW);
    digitalWrite(3,HIGH);
    digitalWrite(4,LOW);
    digitalWrite(5,HIGH);
    break;
        case'f': //RIGHT
    digitalWrite(2,LOW);
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    break;
        case'd': //LEFT
    digitalWrite(2,HIGH);
    digitalWrite(3,LOW);
    digitalWrite(4,LOW);
    digitalWrite(5,HIGH);
    break;
         case'a': //SOUND pin 6 BUZZER
         tone(6,220); //Sound frequency 220Hz
         delay(1000);
         noTone(6);//Stop sound
         delay(500);
         tone(6,220); //Sound frequency 220Hz
         delay(1000);
         noTone(6);//parar so
         delay(500);
    break;   
         case'c': // Green and red leds of roof. Invert state pin 7 lights
         digitalWrite(7,!digitalRead(7));
    break; 
         case'v': // pin 9 SERVO right 40 degrees rudder blade control. You must calibrate this value: 50
         myservo.write(50);
         delay(120);
    break; 
         case'w': // pin 9 SERVO right 20 degrees rudder blade control. You must calibrate this value: 70
         myservo.write(70);
         delay(120);
    break;   
         case'x': // pin 9 SERVO middle rudder blade control. You must calibrate this value: 90
         myservo.write(90);
         delay(120);
    break; 
         case'y': // pin 9 SERVO left 20 degrees rudder blade control You must calibrate this value: 110
         myservo.write(110);
         delay(120);
    break;  
         case'z': // pin 9 SERVO left 40 degrees rudder blade control. You must calibrate this value: 130
         myservo.write(130);
         delay(120);
    break;  
    default:
      delay(500);
      blue.print(rec);
      blue.println("this value is not correct");
  }
}
  }

