gpt4 book ai didi

c - 简单修复? '(' token 之前应为 '!'

转载 作者:行者123 更新时间:2023-11-30 18:29:37 25 4
gpt4 key购买 nike

所以我正在使用 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. 

下面提供了完整的错误消息和代码。

代码:

    #include <dht.h>

#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

int BLED=9;
int GLED=10;
int RLED=11;

void setup(){

Serial.begin(9600);

delay(1000);//Delay to let system boot

Serial.println("DHT11 Humidity & temperature Sensor\n\n");

delay(500);//Wait before accessing Sensor

// initializing output to RGB LED

pinMode (BLED, OUTPUT);
pinMode (GLED, OUTPUT);
pinMode (RLED, OUTPUT);

digitalWrite(RLED, 127); //show that initialization is complete
digitalWrite(GLED, 0);
digitalWrite(BLED, 0);

delay(200);

digitalWrite(RLED, 0);
}//end "setup()"



void loop(){


double f, priorT, currentT; //variables for conversion and temperature change determination.
int i = 0; //counter
DHT.read11(dht_apin);

f = DHT.temperature * 1.8 + 32; //fahrenheit conversion from DHT.Temperature

priorT = currentT;

currentT = 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.
{
Serial.print("Awaiting status change.");
i++;
}

else if(f > priorT + 2 && f < priorT -2) //if there is a temperature change, output the change
{
Serial.print("Current humidity = ");

Serial.print(DHT.humidity);

Serial.print("% ");

Serial.print("temperature = ");

Serial.print(DHT.temperature);

Serial.print("C ");

Serial.print(f);
Serial.println(" F");
i = 0;
}
if(f < 70 && f > 40)
{
digitalWrite(BLED, 90);
digitalWrite(RLED, 0);
digitalWrite(GLED, 0);
}
else if(f > 70 && f < 90)
{
digitalWrite(BLED, 0);
digitalWrite(RLED, 0);
digitalWrite(GLED, 127);
}
else if(f < 40)
{
digitalWrite(BLED, 127);
digitalWrite(RLED, 0);
digitalWrite(GLED, 0);

}
else if(f > 90)
{
digitalWrite(RLED, 127);
digitalWrite(GLED, 0);
digitalWrite(BLED, LOW);
}

delay(5000);//Wait 5 seconds before accessing sensor again.

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.

最佳答案

您需要另一组括号

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

关于c - 简单修复? '(' token 之前应为 '!',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36338448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com