|
13:32:59.249 -> The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData.<fieldname> .
啥意思????
代码:
- #include <IRremote.hpp>
- const int leftPin1=3; //AIN1连接引脚8
- const int leftPin2=11; //AIN2连接引脚7
- const int rightPin3=6; //BIN1连接引脚4
- const int rightPin4=5; //BIN2连接引脚3
- const int irPin = A0; //红外遥控传感器信号引脚连接主板引脚A0
- const int maxspeedPwm = 255; //PWM 最大值
- const int minspeedPwm = 90; //PWM 最小值
- const int speedStep = 10; //加速或减速时PWM的增减幅度
- int intSpeedPWM= 200; //设置小车运行的初始速度
- IRrecv irRecv(irPin); //定义红外库对象irRecv
- decode_results irResults; //定义红外数据对象irResults
- void setup() {
- // put your setup code here, to run once:
- pinMode(leftPin1, OUTPUT);
- pinMode(leftPin2, OUTPUT);
- pinMode(rightPin3, OUTPUT);
- pinMode(rightPin4, OUTPUT);
- irRecv.enableIRIn();
- Serial.begin(9600);
- }
- void loop() {
- if (irRecv.decode(&irResults)) {
- delay(10);
- switch (irResults.value) {
- case 0xFF10EF : //左转
- turnLeft();
- Serial.println("123");
- break;
- case 0xFF5AA5 : //右转
- turnRight();
- Serial.println("12");
- break;
- case 0xFF18E7: //前进
- forward();
- Serial.println("1");
- break;
- case 0xFF4AB5: //后退
- backward();
- Serial.println("456");
- break;
- case 0xFF38C7: //停止
- pause();
- Serial.println("45");
- break;
- case 0xFFA25D: //❷减速
- if (intSpeedPWM- speedStep < minspeedPwm){
- intSpeedPWM= minspeedPwm;
- }
- else{
- intSpeedPWM-= speedStep;
- }
- Serial.println("4");
- break;
- case 0xFF629D: //❷加速
- if (intSpeedPWM+ speedStep > maxspeedPwm) {
- intSpeedPWM= maxspeedPwm;
- }
- else{
- intSpeedPWM+= speedStep;
- }
- Serial.println("789");
- break;
- case 0xFFE21D: //全速
- intSpeedPWM= maxspeedPwm;
- Serial.println("79");
- break;
- default:
- break;
- }
- irRecv.resume(); // 接收下一个值
- }
- delay(50);
- }
- //===============
- // ❸小车动作控制函数与上一个项目相同
- //===============
- //===============
- // 前进
- //===============
- void forward(){
- analogWrite(leftPin1,intSpeedPWM);
- analogWrite(leftPin2,0);
- analogWrite(rightPin3,intSpeedPWM);
- analogWrite(rightPin4,0);
- }
- //===============
- // 后退
- //===============
- void backward(){
- analogWrite(leftPin1,0);
- analogWrite(leftPin2,intSpeedPWM);
- analogWrite(rightPin3,0);
- analogWrite(rightPin4,intSpeedPWM);
- }
- //===============
- // 左转
- //===============
- void turnLeft(){
- analogWrite(leftPin1,0);
- analogWrite(leftPin2,0);
- analogWrite(rightPin3,intSpeedPWM);
- analogWrite(rightPin4,0);
- }
- //===============
- // 右转
- //===============
- void turnRight(){
- analogWrite(leftPin1,intSpeedPWM);
- analogWrite(leftPin2,0);
- analogWrite(rightPin3,0);
- analogWrite(rightPin4,0);
- }
- //===============
- // 原地左转
- //===============
- void rotateLeft(){
- analogWrite(leftPin1,0);
- analogWrite(leftPin2,intSpeedPWM);
- analogWrite(rightPin3,intSpeedPWM);
- analogWrite(rightPin4,0);
- }
- //===============
- // 原地右转
- //===============
- void rotateRight(){
- analogWrite(leftPin1,intSpeedPWM);
- analogWrite(leftPin2,0);
- analogWrite(rightPin3,0);
- analogWrite(rightPin4,intSpeedPWM);
- }
- //===============
- // 停止
- //===============
- void pause(){
- analogWrite(leftPin1,0);
- analogWrite(leftPin2,0);
- analogWrite(rightPin3,0);
- analogWrite(rightPin4,0);
- }
复制代码 求您了,大佬!!!!
|
|