int M1Pin1 = 8

int M1Pin1 = 8;
int M1Pin2 = 9;
int M2Pin1 = 11;
int M2Pin2 = 10;

int M3Pin1 = 4;
int M3Pin2 = 5;
int M4Pin1 = 6;
int M4Pin2 = 7;

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

int st;
int flag=0;
int stcease=0;
void setup()
{
pinMode(M1Pin1, OUTPUT);
pinMode(M1Pin2, OUTPUT);
pinMode(M2Pin1, OUTPUT);
pinMode(M2Pin2, OUTPUT);
pinMode(M3Pin1, OUTPUT);
pinMode(M3Pin2, OUTPUT);
pinMode(M4Pin1, OUTPUT);
pinMode(M4Pin2, OUTPUT);
Serial.begin(9600);
}

void loop() {
if(Serial.available() > 0){
st = Serial.read();
flag=0;
}
if (st == ‘A’) {
digitalWrite(M1Pin1, HIGH);
digitalWrite(M1Pin2, LOW);
digitalWrite(M2Pin1, HIGH);
digitalWrite(M2Pin2, LOW);
if(flag == 0){
Serial.println(“Forward”);
flag=1;
}
}

else if (st == ‘C’) {
digitalWrite(M1Pin1, HIGH);
digitalWrite(M1Pin2, LOW);
digitalWrite(M2Pin1, LOW);
digitalWrite(M2Pin2, HIGH);
if(flag == 0){
Serial.println(“LEFT”);
flag=1;
}
}
else if (st == ‘E’ || stcease == 1) {
digitalWrite(M1Pin1, LOW);
digitalWrite(M1Pin2, LOW);
digitalWrite(M2Pin1, LOW);
digitalWrite(M2Pin2, LOW);
if(flag == 0){
Serial.println(“CEASE”);
flag=1;
}
stcease=0;
}
else if (st == ‘D’) {
digitalWrite(M1Pin1, LOW);
digitalWrite(M1Pin2, HIGH);
digitalWrite(M2Pin1, HIGH);
digitalWrite(M2Pin2, LOW);
if(flag == 0){
Serial.println(“RIGHT”);
flag=1;
}
}
else if (st == ‘B’) {
digitalWrite(M1Pin1, LOW);
digitalWrite(M1Pin2, HIGH);
digitalWrite(M2Pin1, LOW);
digitalWrite(M2Pin2, HIGH);
if(flag == 0){
Serial.println(“BACKWARD”);
flag=1;
}
}
else if (st == ‘1’) {
digitalWrite(M3Pin1, LOW);
digitalWrite(M3Pin2, HIGH);
digitalWrite(M4Pin1, LOW);
digitalWrite(M4Pin2, LOW);
if(flag == 0){
Serial.println(“Go UP”);
flag=1;
}
}
else if (st == ‘2’) {
digitalWrite(M3Pin1, HIGH);
digitalWrite(M3Pin2, LOW);
digitalWrite(M4Pin1, LOW);
digitalWrite(M4Pin2, LOW);
if(flag == 0){
Serial.println(“Go DOWN”);
flag=1;
}
}
else if (st == ‘3’) {
digitalWrite(M3Pin1, LOW);
digitalWrite(M3Pin2, LOW);
digitalWrite(M4Pin1, LOW);
digitalWrite(M4Pin2, HIGH);
if(flag == 0){
Serial.println(“Grip OPEN”);
flag=1;
}
}
else if (st == ‘4’) {
digitalWrite(M3Pin1, LOW);
digitalWrite(M3Pin2, LOW);
digitalWrite(M4Pin1, HIGH);
digitalWrite(M4Pin2, LOW);
if(flag == 0){
Serial.println(“Grip CLOSE”);
flag=1;
}
}
else if (st == ‘5’ || stcease == 1) {
digitalWrite(M3Pin1, LOW);
digitalWrite(M3Pin2, LOW);
digitalWrite(M4Pin1, LOW);
digitalWrite(M4Pin2, LOW);
if(flag == 0){
Serial.println(“cease”);
flag=1;
}
stcease=0;
}