CODE :-
int A=3;
int B=5;
int C=9;
int D=10;
int Speed=100;
String Command;
void setup() {
// put your setup code here, to run once:
pinMode(A,OUTPUT);
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available()==0) {
}
Command=Serial.readString();
Serial.println(Command);
if (Command=="forward") {
analogWrite(A,Speed);
analogWrite(B,LOW);
analogWrite(C,LOW);
analogWrite(D,Speed);
}
if (Command=="stop") {
analogWrite(A,LOW);
analogWrite(B,LOW);
analogWrite(C,LOW);
analogWrite(D,LOW);
}
if (Command=="backward") {
analogWrite(A,LOW);
analogWrite(B,Speed);
analogWrite(C,Speed);
digitalWrite(D,LOW);
}
if (Command=="right") {
analogWrite(A,LOW);
analogWrite(B,LOW);
analogWrite(C,LOW);
analogWrite(D,Speed);
}
if (Command=="left") {
analogWrite(A,Speed);
analogWrite(B,LOW);
analogWrite(C,LOW);
analogWrite(D,LOW);
}
}
0 Comments