Hi all, I'm very new to arduino and currently doing a project on a RC car. The car works pretty fine but just one last thing that frustrates me which is the outputs (eg. when rear light left blinking signal is ON, I couldn't turn on the front lights). I always need to wait until the blinking rear light signal code is completely ended before I can start giving a new command..
Below is the coding I have done.. anyone can help?
char t;
int SPEED1 = 80; // Steering Speed
int SPEED2 = 200; // Engine Speed
void setup() {
pinMode(13,OUTPUT); // Motor A forward
pinMode(12,OUTPUT); // Motor A reverse
pinMode(11,OUTPUT); // Motor B forward
pinMode(8,OUTPUT); // Motor B reverse
pinMode(9,OUTPUT); // Front LEDs (x2)
pinMode(5,OUTPUT); // Left rear LEDS (x2)
pinMode(3,OUTPUT); // Right rear LEDS (x2)
pinMode(10,OUTPUT); // Voltage of Steering
pinMode(6,OUTPUT); // Voltage of Engine
Serial.begin(9600);
}
void loop() {
if(Serial.available()){
t = Serial.read();
Serial.println(t);
}
if(t == 'F'){ //Forward
digitalWrite(8,HIGH);
analogWrite(6,SPEED2);
}
else if(t == 'B'){ //Backward
digitalWrite(11,HIGH);
analogWrite(6,SPEED2);
}
else if(t == 'L'){ //Left
analogWrite(10,SPEED1);
digitalWrite(12,HIGH);
}
else if(t == 'R'){ //Right
analogWrite(10,SPEED1);
digitalWrite(13,HIGH);
}
else if(t == 'W'){ //Frontlights ON with 30 magnitude
analogWrite(9,30);
}
else if(t == 'w'){ //Frontlights OFF
analogWrite(9,0);
}
else if(t == 'V'){ //Rearlights ON with 30 magnitude
analogWrite(5,30);
analogWrite(3,30);
}
else if(t == 'v'){ //Rearlights OFF
analogWrite(5,0);
analogWrite(3,0);
}
else if(t == 'A'){ //Left Blinking Signal
analogWrite(5,0);
delay(500);
analogWrite(5,30);
delay(500);
analogWrite(5,0);
delay(500);
analogWrite(5,30);
delay(500);
analogWrite(5,0);
}
else if(t == 'Q'){ //Right Blinking Signal
analogWrite(3,0);
delay(500);
analogWrite(3,30);
delay(500);
analogWrite(3,0);
delay(500);
analogWrite(3,30);
delay(500);
analogWrite(3,0);
}
else if(t == 'S'){ //STOP (all motors stop)
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(8,LOW);
}