/*
# Editor : Phoebe
# Date : 2014.11.6
# Ver : 0.1
# Product: Devastator Tank Mobile Platform
# SKU : RBO0112
# Description:
# Connect the D4,D5,D6,D7,GND to UNO digital 4,5,6,7,GND
*/
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 13; //M1 Direction Control
int M2 = 7; //M1 Direction Control
char val;
boolean y=false;
boolean x=false;
boolean z=false;
void stop(void) //Stop
{
digitalWrite(M1,LOW);
}
void advance(void) //Move forward
{
x=true;
if (z==true)
{
if (x==true && y==true)
{
digitalWrite(M1,HIGH);
delay(450);
}
else
{
x=false;
y=false;
z=false;
}
}
}
void back_off (void) //Move backward
{
y=true;
if (y && x)
{
z=true;
}
else if (y && !x)
{
z=false;
y=false;
}
else if (x && !y)
{
z=false;
x=false;
}
}
void turn_L (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void turn_R (char a,char b) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void setup(void)
{
int i;
for(i=4;i<=13;i++)
pinMode(i, OUTPUT);
Serial.begin(9600); //Set Baud Rate
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void serial (void)
{
switch(val)
{
case 'UP'://Move Forward
advance (); //move forward in max speed
break;
case 'L1'://Move Backward
back_off () ; //move back in max speed
break;
case 'BACK'://Turn Left
turn_L (100,100);
break;
case 'US'://Turn Right
turn_R (100,100);
break;
case 'v':
break;
default:
stop();
}
}
void loop()
{
if(Serial.available())
{
val = Serial.read();
serial();
}
}
/*
# Editor : Phoebe
# Date : 2014.11.6
# Ver : 0.1
# Product: Devastator Tank Mobile Platform
# SKU : RBO0112
# Description:
# Connect the D4,D5,D6,D7,GND to UNO digital 4,5,6,7,GND
*/
int E1 = 5; //M1 Speed Control
int E2 = 6; //M2 Speed Control
int M1 = 13; //M1 Direction Control
int M2 = 7; //M1 Direction Control
char val;
boolean y=false;
boolean x=false;
boolean z=false;
void stop(void) //Stop
{
digitalWrite(M1,LOW);
}
void advance(void) //Move forward
{
x=true;
if (z==true)
{
if (x==true && y==true)
{
digitalWrite(M1,HIGH);
delay(450);
}
else
{
x=false;
y=false;
z=false;
}
}
}
void back_off (void) //Move backward
{
y=true;
if (y && x)
{
z=true;
}
else if (y && !x)
{
z=false;
y=false;
}
else if (x && !y)
{
z=false;
x=false;
}
}
void turn_L (char a,char b) //Turn Left
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void turn_R (char a,char b) //Turn Right
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void setup(void)
{
int i;
for(i=4;i<=13;i++)
pinMode(i, OUTPUT);
Serial.begin(9600); //Set Baud Rate
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void serial (void)
{
switch(val)
{
case 'UP'://Move Forward
advance (); //move forward in max speed
break;
case 'L1'://Move Backward
back_off () ; //move back in max speed
break;
case 'BACK'://Turn Left
turn_L (100,100);
break;
case 'US'://Turn Right
turn_R (100,100);
break;
case 'v':
break;
default:
stop();
}
}
void loop()
{
if(Serial.available())
{
val = Serial.read();
serial();
}
}