Arduino,似乎语法不正确

时间:2019-04-11 12:05:23

标签: c arduino

水温应保持在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
}

1 个答案:

答案 0 :(得分:1)

在延迟语句后您应该有一个'{',它不应该在其中。有了它,它会使它外面的所有代码都不在循环功能中,这会导致编译器错误。