Hello!
I’m working on my DFRobotShop Rover and I’m trying to control my car via Infrared and using IRremote library(github.com/shirriff/Arduino-IRremote).
However, After I verify the code it appear the error message:
Below is my code:
[code]
////重复码的部分没处理好,我按着不放,它就动一下就不动了
#include <IRremote.h>
#include <IRremoteInt.h>
//红外遥控逻辑代码 自己通过串口监视器可以找出
#define UP 0xC26BF044 //我的遥控器UP键
#define DOWN 0xC4FFB646 //我的遥控器DOWN键
#define LEFT 0x758C9D82 //我的遥控器LEFT键
#define RIGHT 0x53801EE85LL //我的遥控器RIGHT键
#define STOP 0x8AF13528 //我的遥控器STOP键
/To control the rover, Copy and paste the code below into the Arduino software/
int E1 = 6; //M1 Speed Control
int E2 = 5; //M2 Speed Control
int M1 = 8; //M1 Direction Control
int M2 = 7; //M2 Direction Control
int RECV_PIN = 11; //红外接收信号引脚
IRrecv irrecv(RECV_PIN);//初始化
decode_results results;//定义结构体类型
void setup(void)
{
int i;
for(i=5;i<=8;i++)
pinMode(i, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // 开始接收
}
void loop(void)
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
int leftspeed = 255;
int rightspeed = 255;
switch(results.value)
{
case UP://2键前进
forward (leftspeed,rightspeed);
break;
case DOWN://4键左转
reverse (leftspeed,rightspeed);
break;
case LEFT://8键后退
left (leftspeed,rightspeed);
break;
case RIGHT://6键右转
right (leftspeed,rightspeed);
break;
case STOP://5键前进
stop();
break;
default:
stop();
delay(100);
}
irrecv.resume(); // Receive the next value
}
stop();//松开按钮停止
}
void stop(void) //Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
void forward(int a,int b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void reverse (int a,int b)
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void left (int a,int b)
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,LOW);
}
void right (int a,int b)
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}[/code]
Please help me figure out what’s wrong with my program.
Thank you!
Tony