53
digitalWrite(Right_motor_back,HIGH);
digitalWrite(Left_motor_go,HIGH);// left motor go ahead
digitalWrite(Left_motor_back,LOW);
}
void back() //back off
{
digitalWrite(Right_motor_go,LOW); //right motor back off
digitalWrite(Right_motor_back,HIGH);
digitalWrite(Left_motor_go,LOW); //left motor back off
digitalWrite(Left_motor_back,HIGH);
}
//==========================================================
void dump(decode_results *results)//Decode Infrared Remote Control Received Signal
{
int count = results->rawlen;
if (results->decode_type == UNKNOWN)
{
brake();
}
}
void loop()
{
if (irrecv.decode(&results)) //receive infrared signal
{
if (millis() - last > 250) //make sure receive signal
{
on = !on;//Sign position reversal
digitalWrite(13, on ? HIGH : LOW);//LED blink
dump(&results);//decode
}
if (results.value == run_car )//key "2"
run();//go ahead
if (results.value == back_car )//key "8"
back();//back off
if (results.value == left_car )//key "4"
left();//turn left
if (results.value == right_car )//key "6"
right();//turn right
if (results.value == stop_car )//key "5"
brake();//stop
if (results.value == left_turn )//key "1"
spin_left();//Left rotation
if (results.value == right_turn )//key "2"
spin_right();//Right rotation
last = millis();
irrecv.resume(); // Receive the next value
}
}
Experimental steps:
1. We need to open the code of this experiment:
Remote_contorl.ino
, click
“
√
”
under
the menu bar to compile the code, and wait for the word "
Done compiling
" in the lower
right corner, as shown in the figure below.