帮忙看一看-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 401|回复: 1

[未解决] 帮忙看一看

[复制链接]
发表于 2022-5-26 13:50 | 显示全部楼层 |阅读模式
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> .
啥意思????
代码:

  1. #include <IRremote.hpp>
  2. const int leftPin1=3;  //AIN1连接引脚8
  3. const int leftPin2=11;  //AIN2连接引脚7
  4. const int rightPin3=6;  //BIN1连接引脚4
  5. const int rightPin4=5;  //BIN2连接引脚3
  6. const int irPin = A0;  //红外遥控传感器信号引脚连接主板引脚A0
  7. const int maxspeedPwm = 255;  //PWM 最大值
  8. const int minspeedPwm = 90;  //PWM 最小值
  9. const int speedStep = 10;  //加速或减速时PWM的增减幅度
  10. int intSpeedPWM= 200;  //设置小车运行的初始速度
  11. IRrecv irRecv(irPin);  //定义红外库对象irRecv
  12. decode_results irResults;  //定义红外数据对象irResults

  13. void setup() {
  14.   // put your setup code here, to run once:
  15.   pinMode(leftPin1, OUTPUT);
  16.   pinMode(leftPin2, OUTPUT);
  17.   pinMode(rightPin3, OUTPUT);
  18.   pinMode(rightPin4, OUTPUT);
  19.   irRecv.enableIRIn();
  20.   Serial.begin(9600);
  21. }

  22. void loop() {
  23. if (irRecv.decode(&irResults)) {  
  24.     delay(10);
  25.     switch (irResults.value) {
  26.       case 0xFF10EF :    //左转
  27.         turnLeft();
  28.         Serial.println("123");
  29.         break;
  30.       case 0xFF5AA5 :   //右转
  31.         turnRight();
  32.         Serial.println("12");
  33.         break;
  34.       case 0xFF18E7:    //前进
  35.         forward();
  36.         Serial.println("1");
  37.         break;
  38.       case 0xFF4AB5:    //后退
  39.         backward();
  40.         Serial.println("456");
  41.         break;
  42.       case 0xFF38C7:     //停止
  43.         pause();
  44.         Serial.println("45");
  45.         break;
  46.       case 0xFFA25D:     //❷减速
  47.         if (intSpeedPWM- speedStep < minspeedPwm){
  48.           intSpeedPWM= minspeedPwm;
  49.         }
  50.         else{
  51.           intSpeedPWM-= speedStep;
  52.         }
  53.         Serial.println("4");
  54.         break;
  55.       case 0xFF629D:    //❷加速
  56.         if (intSpeedPWM+ speedStep > maxspeedPwm) {
  57.           intSpeedPWM= maxspeedPwm;
  58.         }
  59.         else{
  60.           intSpeedPWM+= speedStep;
  61.         }
  62.         Serial.println("789");
  63.         break;
  64.       case 0xFFE21D:    //全速
  65.         intSpeedPWM= maxspeedPwm;
  66.         Serial.println("79");
  67.         break;
  68.       default:
  69.         break;
  70.     }
  71.     irRecv.resume(); // 接收下一个值
  72.   }
  73.   delay(50);
  74. }
  75. //===============
  76. // ❸小车动作控制函数与上一个项目相同
  77. //===============


  78. //===============
  79. // 前进
  80. //===============
  81. void forward(){
  82.     analogWrite(leftPin1,intSpeedPWM);
  83.     analogWrite(leftPin2,0);
  84.     analogWrite(rightPin3,intSpeedPWM);
  85.     analogWrite(rightPin4,0);
  86. }
  87. //===============
  88. // 后退
  89. //===============
  90. void backward(){
  91.     analogWrite(leftPin1,0);
  92.     analogWrite(leftPin2,intSpeedPWM);
  93.     analogWrite(rightPin3,0);
  94.     analogWrite(rightPin4,intSpeedPWM);
  95. }
  96. //===============
  97. // 左转
  98. //===============
  99. void turnLeft(){
  100.     analogWrite(leftPin1,0);
  101.     analogWrite(leftPin2,0);
  102.     analogWrite(rightPin3,intSpeedPWM);
  103.     analogWrite(rightPin4,0);
  104. }
  105. //===============
  106. // 右转
  107. //===============
  108. void turnRight(){
  109.     analogWrite(leftPin1,intSpeedPWM);
  110.     analogWrite(leftPin2,0);
  111.     analogWrite(rightPin3,0);
  112.     analogWrite(rightPin4,0);
  113. }
  114. //===============
  115. // 原地左转
  116. //===============
  117. void rotateLeft(){
  118.     analogWrite(leftPin1,0);
  119.     analogWrite(leftPin2,intSpeedPWM);
  120.     analogWrite(rightPin3,intSpeedPWM);
  121.     analogWrite(rightPin4,0);
  122. }
  123. //===============
  124. // 原地右转
  125. //===============
  126. void rotateRight(){
  127.     analogWrite(leftPin1,intSpeedPWM);
  128.     analogWrite(leftPin2,0);
  129.     analogWrite(rightPin3,0);
  130.     analogWrite(rightPin4,intSpeedPWM);
  131. }
  132. //===============
  133. // 停止
  134. //===============
  135. void pause(){
  136.     analogWrite(leftPin1,0);
  137.     analogWrite(leftPin2,0);
  138.     analogWrite(rightPin3,0);
  139.     analogWrite(rightPin4,0);
  140. }
复制代码
求您了,大佬!!!!
发表于 2022-5-26 17:30 | 显示全部楼层
函数 decode(&results)) 已弃用,可能无法按预期工作!只需使用不带参数的decode()和IrReceiver.decodedIRData。<fieldname> 。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2025-1-1 20:31 , Processed in 0.072296 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表