Arduino LCD清除,但随后赢得';不要回来 #包括 #包括 液晶显示器(2,3,4,5,6,7); int TempPin=A0; float realTemp=0; int-FakeTemp=0; int目标=20; int-IRPin=11; IRrecv IRrecv(IRPin); 解码_结果; 无效设置(){ //将安装代码放在此处,以便运行一次: lcd.begin(16,2); Serial.begin(9600); 而(!串行); irrecv.enableIRIn();//启用红外接收器 } void循环(){ FakeTemp=模拟读数(TempPin); realTemp=(5.0*FakeTemp*1000.0)/(1024*10);//温度的数学 Serial.println(realTemp); lcd.打印(“温度”); lcd.setCursor(0,13); lcd.print(realTemp);//打印温度 延迟(3000); lcd.clear(); 如果(IRECV.decode(16754775)){//从红外遥控器输入 lcd.clear(); lcd.print(“Target=”); lcd.打印(目标+1); 延迟(3000); 简历(); lcd.clear(); 目标=目标+1; //添加到目标 } 如果(IRECV.decode(16769055)){//这是因为一切都出了问题 lcd.clear(); lcd.print(“Target=”); lcd.打印(目标-1); 延迟(3000); 简历(); lcd.clear(); 目标=目标-1; } }

Arduino LCD清除,但随后赢得';不要回来 #包括 #包括 液晶显示器(2,3,4,5,6,7); int TempPin=A0; float realTemp=0; int-FakeTemp=0; int目标=20; int-IRPin=11; IRrecv IRrecv(IRPin); 解码_结果; 无效设置(){ //将安装代码放在此处,以便运行一次: lcd.begin(16,2); Serial.begin(9600); 而(!串行); irrecv.enableIRIn();//启用红外接收器 } void循环(){ FakeTemp=模拟读数(TempPin); realTemp=(5.0*FakeTemp*1000.0)/(1024*10);//温度的数学 Serial.println(realTemp); lcd.打印(“温度”); lcd.setCursor(0,13); lcd.print(realTemp);//打印温度 延迟(3000); lcd.clear(); 如果(IRECV.decode(16754775)){//从红外遥控器输入 lcd.clear(); lcd.print(“Target=”); lcd.打印(目标+1); 延迟(3000); 简历(); lcd.clear(); 目标=目标+1; //添加到目标 } 如果(IRECV.decode(16769055)){//这是因为一切都出了问题 lcd.clear(); lcd.print(“Target=”); lcd.打印(目标-1); 延迟(3000); 简历(); lcd.clear(); 目标=目标-1; } },arduino,Arduino,我已经做了很长一段时间了,当我添加一个if语句时,它会在lcd上显示一次温度,我不知道是什么错了。但是,它不会再这样做了。我可以在串行监视器中看到,它仍在采集温度,但不会将其打印到LCD上。\35; include #include <IRremote.h> #include <LiquidCrystal.h> LiquidCrystal lcd(2, 3, 4, 5, 6, 7); int TempPin = A0; float realTemp = 0; int F

我已经做了很长一段时间了,当我添加一个if语句时,它会在lcd上显示一次温度,我不知道是什么错了。但是,它不会再这样做了。我可以在串行监视器中看到,它仍在采集温度,但不会将其打印到LCD上。

\35; include
#include <IRremote.h>

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int TempPin = A0;
float realTemp = 0;
int FakeTemp = 0;
int target = 20;
int IRPin = 11;
IRrecv irrecv(IRPin);
decode_results results;

void setup() {
    // put your setup code here, to run once:
    lcd.begin(16, 2);
    Serial.begin(9600);
    while (! Serial);
    irrecv.enableIRIn(); //enables ir receiver
}

void loop() {
    FakeTemp = analogRead(TempPin);
    realTemp = (5.0 * FakeTemp * 1000.0) / (1024 * 10); // math for the temperature
    Serial.println(realTemp);
    lcd.print("Temperature");
    lcd.setCursor(0, 13);
    lcd.print(realTemp); //prints the temperature
    delay(3000);
    lcd.clear();

    if (irrecv.decode(16754775)) { //input from ir remote
        lcd.clear();
        lcd.print("Target=");
        lcd.print(target + 1);
        delay(3000);
        irrecv.resume();
        lcd.clear();
        target = target + 1;
        // adds to target
    }

    if (irrecv.decode(16769055)) { //this is were everything goes wrong
        lcd.clear();
        lcd.print("Target=");
        lcd.print(target - 1);
        delay(3000);
        irrecv.resume();
        lcd.clear();
        target = target - 1;
    }
}
#包括 液晶显示器(2,3,4,5,6,7); int TempPin=A0; float realTemp=0; int-FakeTemp=0; int目标=20; int-IRPin=11; IRrecv IRrecv(IRPin); 解码_结果; 无效设置(){ //将安装代码放在此处,以便运行一次: lcd.begin(16,2); Serial.begin(9600); 而(!串行); irrecv.enableIRIn();//启用红外接收器 } void循环(){ FakeTemp=模拟读数(TempPin); realTemp=(5.0*FakeTemp*1000.0)/(1024*10);//温度的数学 Serial.println(realTemp); lcd.打印(“温度”); lcd.setCursor(0,13); lcd.print(realTemp);//打印温度 延迟(3000); //lcd.clear(); 如果(IRECV.decode(16754775)){//从红外遥控器输入 lcd.clear(); lcd.print(“Target=”); lcd.打印(目标+1); 延迟(3000); 简历(); //lcd.clear(); 目标=目标+1; //添加到目标 } 如果(IRECV.decode(16769055)){//这是因为一切都出了问题 lcd.clear(); lcd.print(“Target=”); lcd.打印(目标-1); 延迟(3000); 简历(); //lcd.clear(); 目标=目标-1; } }

你能试试这个代码吗。我没有使用红外模块。但我认为只有当新的ir消息到达arduino代码时,if语句中的代码才能运行。因此,我认为if语句和主循环中的第二个lcd.clear命令是问题的主要原因。

decode
需要一个
decode\u results
对象,而不是一个文本整数。那么,如果我声明targetup=16769055,然后执行IRECV.decode(targetup),它会工作吗?对不起,我真的是新来的,IRremote图书馆有一些例子。
#include <IRremote.h>

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int TempPin = A0;
float realTemp = 0;
int FakeTemp = 0;
int target = 20;
int IRPin = 11;
IRrecv irrecv(IRPin);
decode_results results;

void setup() {
    // put your setup code here, to run once:
    lcd.begin(16, 2);
    Serial.begin(9600);
    while (! Serial);
    irrecv.enableIRIn(); //enables ir receiver
}

void loop() {
    FakeTemp = analogRead(TempPin);
    realTemp = (5.0 * FakeTemp * 1000.0) / (1024 * 10); // math for the temperature
    Serial.println(realTemp);
    lcd.print("Temperature");
    lcd.setCursor(0, 13);
    lcd.print(realTemp); //prints the temperature
    delay(3000);
    //lcd.clear();

    if (irrecv.decode(16754775)) { //input from ir remote
        lcd.clear();
        lcd.print("Target=");
        lcd.print(target + 1);
        delay(3000);
        irrecv.resume();
        //lcd.clear();
        target = target + 1;
        // adds to target
    }

    if (irrecv.decode(16769055)) { //this is were everything goes wrong
        lcd.clear();
        lcd.print("Target=");
        lcd.print(target - 1);
        delay(3000);
        irrecv.resume();
        //lcd.clear();
        target = target - 1;
    }
}