gpt4 book ai didi

c - Arduino,似乎语法不正确

转载 作者:行者123 更新时间:2023-11-30 14:40:12 25 4
gpt4 key购买 nike

水温应保持在 24-27'c 之间 - 如果没有打印到 LCD 上并发出蜂鸣器声音。水位也会受到监控,并应点亮相关的 LED。

我的问题是,当从循环编译此代码时,我总是收到错误。我假设我缺少大括号或相当基本的东西,但我一生都无法弄清楚我哪里出了问题。

任何人都可以指出我正确的方向吗? - 我承认这可能是一个简单的修复,但我看不到树木。

        void loop()
{

WaterTemp = (sensors.getTempCByIndex(0));

Serial.print(F(" Requesting temperatures..."));
sensors.requestTemperatures(); // Send the command to get temperature
Serial.println("DONE");

Serial.print(F("Water Temperature is: "));
Serial.println(WaterTemp);
lcd.setCursor(9, 0);
lcd.print(WaterTemp, 1);
lcd.print(F(" "));
lcd.print((char)223);
lcd.print(F("C"));
delay(1000);

}

if (WaterTemp <24)
{
tone(piezoPin,600, 200);
delay(1000);
lcd.print("TEMP LOW");
}
if (WaterTemp >27)
{
tone(piezoPin, 400, 200);
delay(1000);
lcd.print("TEMP HIGH");
}
}

value = analogRead(read); //Read data from analog pin and store

if (value<=390) {
Serial.println("Water level: 0mm -Fill FISHTANK NOW!!!");
digitalWrite (4, HIGH);
digitalWrite (3, LOW);
digitalWrite (2, LOW);
tone(piezoPin,500, 400);
delay(1500);
}
else if (value>450 && value<=529) {
Serial.println("Water level: 10mm Fill Fishtank ASAP");
digitalWrite (4, HIGH);
digitalWrite (3, HIGH);
digitalWrite (2, LOW);
}
else if (value>540 && value<=550) {
Serial.println("Water level: 20mm Fishtank getting low!!");
digitalWrite (4, LOW);
digitalWrite (3, HIGH);
digitalWrite (2, LOW);
}
else if (value>560 && value<=570) {
Serial.println("Water level:30mm Fishtank below optimum level");
digitalWrite (4, LOW);
digitalWrite (3, HIGH);
digitalWrite (2, HIGH);
}

else if (value>580) {
Serial.println("Water level:40mm Fishtank FULL");
digitalWrite (4, LOW);
digitalWrite (3, LOW);
digitalWrite (2, HIGH);

}

delay(2000); // Check for new value every 3 sec
}

最佳答案

延迟语句后面有一个不应该出现的“{”。有了它,它外面的所有代码都不会在循环函数中,这会导致编译器错误。

关于c - Arduino,似乎语法不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55632098/

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