#include <SoftwareSerial.h>
#include <Wire.h>
const int motor1 =  2;      // the number of the motor1 pin
const int motor2 =  3;      // the number of the motor2 pin

SoftwareSerial BT(10,11); //TX-10,RX-11

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0; 
 
void setup() {
  BT.begin(9600);  
  // initialize the motor pin as an output:
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
}
void loop() {
  
  byte cmd[20];
  int strsize;
  while(true){
    if ((strsize=(BT.available()))>0){
      for (int i=0; i<strsize; i++){
        cmd[i]=char(BT.read());
      }
    }

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
    switch (cmd[0]) {
    // turn motor1 on:
    case 'a':
    digitalWrite(motor1, HIGH);
    digitalWrite(motor2, LOW);
    break;
  
    case 'b':
    // turn motor2 on:
    digitalWrite(motor1, LOW);
    digitalWrite(motor2, HIGH);
    break;
  
    case 'c':
    // turn Both motors on:
    digitalWrite(motor1, HIGH);
    digitalWrite(motor2, HIGH);
    break;

    case 'd':
    // turn Both motors off:
    digitalWrite(motor1, LOW);
    digitalWrite(motor2, LOW);
    break;

    default:
    // if nothing else matches, do the default
    // default is optional
    break;
   
    }
     cmd[0]=0;
}
}
