[the overview]
I made the Car with 2 2channel relays and 2 motors and i thinked it was controlled well,but it was not..
whenever i double-click the remote control same key, the car went forward and back.
what make it ?
the source code is as following.Help me!!!!!!
###################Source Code ###############
#include <IRremote.h>
// set pin numbers:
#define TRIG 10
#define ECHO 9
const int BAUD_RATE = 9600 ;
int RECV_PIN = 11;
int Remote_keyed_Status = 0 ;
int distance = 0;
IRrecv irrecv(RECV_PIN);
decode_results results;
// variables will change:
void setup() {
Serial.begin(BAUD_RATE);
irrecv.enableIRIn(); // Start the receiver
pinMode(TRIG,OUTPUT);
pinMode(ECHO,INPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
delay(1000);
}
void loop(){
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
switch(results.value)
{
case 0xFFC23D: //right
digitalWrite(6, LOW);
digitalWrite(7, HIGH); //Back
delay(500);
digitalWrite(6, HIGH); //Back
digitalWrite(7, HIGH);
break;
case 0xFF22DD: //left
digitalWrite(7, LOW);
digitalWrite(6, HIGH); //Back
delay(500);
digitalWrite(7, HIGH); //Back
digitalWrite(6, HIGH);
break;
case 0xFF629D: //up
Remote_keyed_Status = 8 ;
digitalWrite(12, LOW);
digitalWrite(13, HIGH); //Back
delay(1000);
digitalWrite(12, HIGH); //Back
digitalWrite(13, HIGH);
break;
case 0xFFA857: //down
Remote_keyed_Status = 2 ;
// digitalWrite(TRIG,HIGH);
//delayMicroseconds(10);
//digitalWrite(TRIG,LOW);
// distance = pulseIn(ECHO,HIGH)/58.2;
//Serial.print("distance:"+(String)distance);
// Serial.println("cm");
// if (distance > 20)
// {
digitalWrite(13, LOW);
digitalWrite(12, HIGH); //Back
delay(1000);
digitalWrite(12, HIGH); //Back
digitalWrite(13, HIGH);
// }
break;
case 0xFFFFFFFF: //continue
if (Remote_keyed_Status = 8)
{
Remote_keyed_Status = 8 ;
digitalWrite(12, LOW);
digitalWrite(13, HIGH); //Back
delay(1000);
digitalWrite(12, HIGH); //Back
digitalWrite(13, HIGH);
};
if (Remote_keyed_Status = 2)
{
Remote_keyed_Status = 2 ;
digitalWrite(13, LOW);
digitalWrite(12, HIGH); //Back
delay(1000);
digitalWrite(12, HIGH); //Back
digitalWrite(13, HIGH);
};
break;
}
irrecv.resume(); // Receive the next value
}
}