C 简单修复?预期';(';之前';!';代币

C 简单修复?预期';(';之前';!';代币,c,arduino,rgb,sensors,temperature,C,Arduino,Rgb,Sensors,Temperature,所以我使用的是DHT11温度/湿度传感器。 我已经把这一切都做好了,我只是想在没有变化的情况下减少输出。在添加这一行之前,没有任何问题。如果你能告诉我我的错误,而不是告诉我更好的方法,我将不胜感激。这只是为了让我知道哪里出了问题 if!(f > priorT + 2 && f < priorT -2 && i = 1) //in a non-repetitive fashion dictated by the counter, if there is

所以我使用的是DHT11温度/湿度传感器。 我已经把这一切都做好了,我只是想在没有变化的情况下减少输出。在添加这一行之前,没有任何问题。如果你能告诉我我的错误,而不是告诉我更好的方法,我将不胜感激。这只是为了让我知道哪里出了问题

if!(f > priorT + 2 && f < priorT -2 && i = 1)  //in a non-repetitive fashion dictated by the counter, if there isnt a large change, do not output. 
if!(f>priorT+2&&f
下面提供了完整的错误消息和代码

代码:

#包括
#定义dht_apin A0//模拟引脚传感器是否连接到
dht-dht;
int=9;
int-GLED=10;
int-RLED=11;
无效设置(){
Serial.begin(9600);
延迟(1000);//允许系统启动的延迟
Serial.println(“DHT11湿度和温度传感器\n\n”);
延迟(500);//在访问传感器之前等待
//正在初始化RGB LED的输出
pinMode(BLED,输出);
pinMode(GLED,输出);
pinMode(RLED,输出);
digitalWrite(RLED,127);//显示初始化已完成
数字写入(GLED,0);
数字写入(BLED,0);
延迟(200);
数字写入(RLED,0);
}//结束“设置()
void循环(){
双f,priorT,current;//用于转换和温度变化确定的变量。
int i=0;//计数器
DHT.read11(DHT_apin);
f=DHT.温度*1.8+32;//DHT.温度的华氏转换
priorT=current;
电流t=f;
如果!(f>priorT+2&&fpriorT+2&&f40)
{
数字写入(BLED,90);
数字写入(RLED,0);
数字写入(GLED,0);
}
否则,如果(f>70和&f<90)
{
数字写入(BLED,0);
数字写入(RLED,0);
digitalWrite(GLED,127);
}
否则,如果(f<40)
{
digitalWrite(BLED,127);
数字写入(RLED,0);
数字写入(GLED,0);
}
如果(f>90),则为其他情况
{
数码书写(RLED,127);
数字写入(GLED,0);
数字写入(带血,低);
}
延迟(5000);//在再次访问传感器之前等待5秒。
i++;
}
错误消息:

Arduino: 1.6.7 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Xxwitherpoon\Documents\Arduino\Sensors\DHT11andRGBLED\DHT11andRGBLED.ino: In function 'void loop()':

DHT11andRGBLED:52: error: expected '(' before '!' token

     if!(f > priorT + 2 && f < priorT -2 && i = 1)  //in a non-repetitive fashion dictated by the counter, if there isnt a large change, do not output.

       ^

DHT11andRGBLED:58: error: 'else' without a previous 'if'

     else if(f > priorT + 2 && f < priorT -2)        //if there is a temperature change, output the change

     ^

exit status 1
expected '(' before '!' token

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino:1.6.7(Windows 7),板:“Arduino/Genuino”
C:\Users\Xxwitherpoon\Documents\Arduino\Sensors\DHT11andRGBLED\DHT11andRGBLED.ino:在函数“void loop()”中:
DHT11andRGBLED:52:错误:应为“(”在“!”之前
如果!(f>priorT+2&&fpriorT+2&&f首选项中启用。

您需要另一组括号

if(!(f > priorT + 2 && f < priorT -2 && i = 1))
if(!(f>priorT+2&&f
您缺少外部括号,代码中应包含:

if (!(f > priorT + 2 && f < priorT -2 && i = 1))  //in a non-repetitive fashion dictated by the counter, if there isnt a large change, do not output. 
if(!(f>priorT+2&&f
您还可以避免使用两级圆括号来消除错误。例如:

if (f <= priorT + 2 || f >= priorT -2 || i != 1)  //in a non-repetitive fashion dictated by the counter, if there isnt a large change, do not output.  
if(f=priorT-2 | | i!=1)//以计数器指定的非重复方式,如果没有大的变化,则不要输出。
您还可以查看以了解更多信息

希望这有帮助。

如果(!(f>priorT+2 | | fif (!(f > priorT + 2 || f < priorT -2 || i == 1))
这就是解决办法,就像你们告诉我的


关于OR语句,您是对的。它们是必要的。我的问题也是i=1必须是i==1 duh。谢谢大家。

关于编译器错误,您的代码

if (f <= priorT + 2 || f >= priorT -2 || i = 1)

也就是说,编译器认为您试图将1赋值给一个表达式,但这是无法完成的。这就是错误消息抱怨某些内容不是左值的意思。(大约30年前,我被一条类似的错误消息惊呆了。我打电话给一位比我更有经验的朋友,问他什么是左值。他的回答是:“你在做类似于5=x的事情。再见!”。

如果(整个表达式属于parens内部)
-你的表达式之外有一个
。应该是
如果(!(yourexpression))
谢谢你们两位的意见。在研究了这个问题之后,我已经尝试了使用附加括号的方法。但我仍然收到一条错误消息。使用文件夹C:\Program Files(x86)\Arduino\libraries\DHT(legacy)中的库DHT的“code”退出状态1需要左值作为赋值'code'的左操作数抱歉,我似乎无法获取'code'部分…但我不确定是否是arduino软件导致了此问题。
if (f <= priorT + 2 || f >= priorT -2 || i = 1)
if (f <= (priorT + 2 || f) >= (priorT -2 || i) = 1)
if(!(..... (priorT -2 && i) = 1))