Sei sulla pagina 1di 4

#include <SoftwareSerial.

h>

SoftwareSerial BT(1, 0); //TX, RX respetively


String readvoice;

const int sw1=2;


const int sw2=3;
const int sw3=4;
const int sw4=5;

int switchState = 0;
int switchState1 = 0;

int switchState2 = 0;
int switchState3 = 0;

const int mot1 = 13;


const int mot2 = 12;
const int mot3 = 11;
const int mot4 = 10;
const int mot5 = 9;
char c ;

void setup()

BT.begin(9600);
pinMode(sw1,INPUT);
pinMode(sw2,INPUT);
pinMode(sw3,INPUT);
pinMode(sw4,INPUT);
pinMode(mot1,OUTPUT);
pinMode(mot2,OUTPUT);
pinMode(mot3,OUTPUT);
pinMode(mot4,OUTPUT);
pinMode(mot5,OUTPUT);
digitalWrite(mot1,LOW);
digitalWrite(mot2,LOW);
digitalWrite(mot3,LOW);
digitalWrite(mot4,LOW);
digitalWrite(mot5,LOW);
}

void loop()
{

serialEvent();

while (c == 'A')

digitalWrite(mot1,HIGH);
switchState = digitalRead(sw1);
if (switchState == LOW )
{
digitalWrite(mot1,LOW);
delay(2000);
c='X';
digitalWrite(mot2,HIGH);
delay(4000);
digitalWrite(mot2,LOW);
break;
}
}

while (c == 'B')
{
digitalWrite(mot1,HIGH);
switchState = digitalRead(sw2);
if (switchState == LOW )
{
digitalWrite(mot1,LOW);
delay(2000);
c='X';
digitalWrite(mot3,HIGH);
delay(4000);
digitalWrite(mot3,LOW);
break;
}
}
while (c == 'C')
{
digitalWrite(mot1,HIGH);
switchState = digitalRead(sw3);
if (switchState == LOW )
{
digitalWrite(mot1,LOW);
delay(2000);
c='X';
digitalWrite(mot4,HIGH);
delay(4000);
digitalWrite(mot4,LOW);
break;
}
}
while (c == 'D')
{
digitalWrite(mot1,HIGH);
switchState = digitalRead(sw4);
if (switchState == LOW )
{
digitalWrite(mot1,LOW);
delay(2000);
c='X';
digitalWrite(mot5,HIGH);
delay(4000);
digitalWrite(mot5,LOW);
break;
}
}
while (c == 'E')
{
digitalWrite(mot1,HIGH);
switchState = digitalRead(sw1);
if (switchState == LOW )
{
digitalWrite(mot1,LOW);
delay(2000);
digitalWrite(mot2,HIGH);
delay(2000);
digitalWrite(mot2,LOW);
digitalWrite(mot1,HIGH);
while (c == 'E')
{
switchState = digitalRead(sw2);
if (switchState == LOW )
{
digitalWrite(mot1,LOW);
delay(2000);
digitalWrite(mot3,HIGH);
delay(2000);
digitalWrite(mot3,LOW);
c='X';
break;
}
}
}
}

while (c == 'F')
{
digitalWrite(mot1,HIGH);
switchState = digitalRead(sw3);
if (switchState == LOW )
{
digitalWrite(mot1,LOW);
delay(2000);
digitalWrite(mot4,HIGH);
delay(2000);
digitalWrite(mot4,LOW);
digitalWrite(mot1,HIGH);
while (c == 'F')
{
switchState = digitalRead(sw4);
if (switchState == LOW )
{
digitalWrite(mot1,LOW);
delay(2000);
digitalWrite(mot5,HIGH);
delay(2000);
digitalWrite(mot5,LOW);
c='X';
break;
}
}
}
}
}

void serialEvent()
{

if(BT.available())
{
char data =BT.read();
c=data;
}

Potrebbero piacerti anche