当我点击遥控器上的下一步按钮时,代码没有改变命令
Ir code not changing commands when I click the next button on the remote
我正在用 Arduino 建造一架红外控制的直升机并且代码有效,但是当我点击下一个按钮让直升机移动到其他地方时,它一直在串行监视器中打印相同的东西并且命令没有改变... 有人可以帮帮我吗?
这是我的代码:
#include <IRremote.h>
#define in1 6
#define in2 7
#define in3 4
#define in4 5
int IR_RECEIVE_PIN = 2;
IRrecv IrReceiver(IR_RECEIVE_PIN);
decode_results results;
void setup(){
Serial.begin(9600);
IrReceiver.enableIRIn();
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop(){
if(IrReceiver.decode(&results))
switch (results.value) {
case 0xFFA857:
Serial.println("case: UP");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
break;
case 0xFFE01F:
Serial.println("case: DOWN");
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
break;
case 0xFF18E7:
Serial.println("case: FORWARD");
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
break;
case 0xFF10EF:
Serial.println("case: LEFT");
break;
case 0xFF5AA5:
Serial.println("case: RIGHT");
break;
case 0xFF48B5:
Serial.println("case: BACKWARDS");
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
break;
}
Serial.println(results.value, HEX);
IrReceiver.resume();
}
尝试运行 if:
上带有大括号的代码
#include <IRremote.h>
#define in1 6
#define in2 7
#define in3 4
#define in4 5
int IR_RECEIVE_PIN = 2;
IRrecv IrReceiver(IR_RECEIVE_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
IrReceiver.enableIRIn();
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop() {
if (IrReceiver.decode(&results)) {
switch (results.value) {
case 0xFFA857:
Serial.println("case: UP");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
break;
case 0xFFE01F:
Serial.println("case: DOWN");
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
break;
case 0xFF18E7:
Serial.println("case: FORWARD");
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
break;
case 0xFF10EF:
Serial.println("case: LEFT");
break;
case 0xFF5AA5:
Serial.println("case: RIGHT");
break;
case 0xFF48B5:
Serial.println("case: BACKWARDS");
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
break;
}
Serial.println(results.value, HEX);
IrReceiver.resume();
}
}
我正在用 Arduino 建造一架红外控制的直升机并且代码有效,但是当我点击下一个按钮让直升机移动到其他地方时,它一直在串行监视器中打印相同的东西并且命令没有改变... 有人可以帮帮我吗? 这是我的代码:
#include <IRremote.h>
#define in1 6
#define in2 7
#define in3 4
#define in4 5
int IR_RECEIVE_PIN = 2;
IRrecv IrReceiver(IR_RECEIVE_PIN);
decode_results results;
void setup(){
Serial.begin(9600);
IrReceiver.enableIRIn();
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop(){
if(IrReceiver.decode(&results))
switch (results.value) {
case 0xFFA857:
Serial.println("case: UP");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
break;
case 0xFFE01F:
Serial.println("case: DOWN");
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
break;
case 0xFF18E7:
Serial.println("case: FORWARD");
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
break;
case 0xFF10EF:
Serial.println("case: LEFT");
break;
case 0xFF5AA5:
Serial.println("case: RIGHT");
break;
case 0xFF48B5:
Serial.println("case: BACKWARDS");
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
break;
}
Serial.println(results.value, HEX);
IrReceiver.resume();
}
尝试运行 if:
上带有大括号的代码#include <IRremote.h>
#define in1 6
#define in2 7
#define in3 4
#define in4 5
int IR_RECEIVE_PIN = 2;
IRrecv IrReceiver(IR_RECEIVE_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
IrReceiver.enableIRIn();
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop() {
if (IrReceiver.decode(&results)) {
switch (results.value) {
case 0xFFA857:
Serial.println("case: UP");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
break;
case 0xFFE01F:
Serial.println("case: DOWN");
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
break;
case 0xFF18E7:
Serial.println("case: FORWARD");
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
break;
case 0xFF10EF:
Serial.println("case: LEFT");
break;
case 0xFF5AA5:
Serial.println("case: RIGHT");
break;
case 0xFF48B5:
Serial.println("case: BACKWARDS");
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
break;
}
Serial.println(results.value, HEX);
IrReceiver.resume();
}
}