Arduino 希望您能帮助解决一些bug和改进的代码

Arduino 希望您能帮助解决一些bug和改进的代码,arduino,Arduino,我写了一个代码,可以根据电池是满的还是空的自动打开和关闭发电机 lcd.begin和lcd.clear中存在一些错误,它们都不工作。 错误:非静态成员函数的使用无效。 谢谢大家! #include <LiquidCrystal_I2C.h> #include <Wire.h> // Set the LCD address to 0x27 for a 16 chars and 2 line display LiquidCrystal_I2C lcd(0x27, 16, 2)

我写了一个代码,可以根据电池是满的还是空的自动打开和关闭发电机

lcd.begin和lcd.clear中存在一些错误,它们都不工作。 错误:非静态成员函数的使用无效。 谢谢大家!

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
bool Settings = false;
unsigned long time1;
#define RELAY_PORT 10
float Voltage = 0.00;
int VoltOn = 47;
int VoltOff = 56;
int upbutton = 1;
int downbutton = 2;
int okbutton = 3;
int backbutton = 4;
void setup() {
  pinMode(upbutton, INPUT);
  pinMode(downbutton, INPUT);
  pinMode(okbutton, INPUT);
  pinMode(backbutton, INPUT);
  pinMode(RELAY_PORT, OUTPUT);
  // initialize the LCD
  lcd.begin();

  // Turn on the blacklight and print a message.
  lcd.backlight();
  lcd.setCursor(0, 1);
  lcd.print ("generator: off");
}

void loop() {
  int analog_value = analogRead(A0);
  Voltage = ((analog_value * 5.0) / 1020) * 12;
  lcd.setCursor(0, 0);
  lcd.print("Volt: ");
  lcd.print(Voltage);
  lcd.print("V");

  if (Voltage <= VoltOn && digitalRead(RELAY_PORT) == LOW)
  {
    digitalWrite(RELAY_PORT, HIGH);
    lcd.setCursor(0, 1);
    lcd.print ("generator: on");
  }

  if (Voltage >= VoltOff && digitalRead(RELAY_PORT) == HIGH)
  {
    digitalWrite(RELAY_PORT, LOW);
    lcd.setCursor(0, 1);
    lcd.print ("generator: off");
  }





  if ((digitalRead(upbutton) == HIGH  && digitalRead(downbutton) == HIGH && digitalRead(okbutton) == HIGH && digitalRead(backbutton) == HIGH) || (Settings = true))
  {
    lcd.clear;
    lcd.print("Settings:");
    delay(2000);
    time1 = millis();
    bool Setting = false;
    while (digitalRead(upbutton) == LOW  && digitalRead(downbutton) == LOW && digitalRead(okbutton) == LOW && digitalRead(backbutton) == LOW)
    {
      if (Setting == false)
      {
        lcd.clear;
        lcd.scrollDisplayLeft();
        lcd.print("press Up to set turn on");
        lcd.setCursor(0, 1);
        lcd.print("press down to set turn off");
        Setting = true;
      }
      if (millis() > time1 + 60000)
      {
        loop();
      }
    }
    time1 = millis();
    while (millis() > time1 + 60000)
    {
      if (upbutton == HIGH)
      {
        time1 = millis();
        //lcd.clear;
        lcd.scrollDisplayLeft();
        lcd.print("press Up/ Down to up/ Down Voltage turn on");
        while (digitalRead(upbutton) == LOW  && digitalRead(downbutton) == LOW && digitalRead(okbutton) == LOW && digitalRead(backbutton) == LOW)
        {
          if (millis() > time1 + 60000)
          {
            loop();
          }
        }
        time1 = millis();
        while (millis() > time1 - 60000)
        {
          if (upbutton == HIGH)
          {
            int xdelay = 1000;
            time1 = millis();
            (VoltOn) = (VoltOn) + 1;
            lcd.setCursor(0, 1);
            lcd.print("Voltage-on: ");
            lcd.print(VoltOn);
            lcd.print("V");
            delay(xdelay);
            xdelay = xdelay / 1.5;
          }
          if (downbutton == HIGH)
          {
            int xdelay = 1000;
            time1 = millis();
            (VoltOn) = (VoltOn) - 1;
            lcd.setCursor(0, 1);
            lcd.print("Voltage-on: ");
            lcd.print(VoltOn);
            lcd.print("V");
            delay(xdelay);
            xdelay = xdelay / 1.5;
          }
          if (okbutton == HIGH)
          {
            loop();
          }
          if (backbutton == HIGH)
          { Settings = true;
          }
          if (millis() > time1 + 60000)
          {
            loop();
          }
        }

      }

      if (downbutton == HIGH)
      {
        time1 = millis();
        lcd.clear;
        lcd.scrollDisplayLeft();
        lcd.print("press Up/ Down to up/ Down Voltage turn off");

        while (digitalRead(upbutton) == LOW  && digitalRead(downbutton) == LOW && digitalRead(okbutton) == LOW && digitalRead(backbutton) == LOW)
        {
          if (millis() > time1 + 60000)
          {
            loop();
          }

        }
        time1 = millis();
        while (millis() > time1 - 60000)
        {
          if (upbutton == HIGH)
          {
            int xdelay = 1000;
            time1 = millis();
            (VoltOff) = (VoltOff) + 1;
            lcd.setCursor(0, 1);
            lcd.print("Voltage-off: ");
            lcd.print(VoltOff);
            lcd.print("V");
            delay(xdelay);
            xdelay = xdelay / 1.5;
          }
          if (downbutton == HIGH)
          {
            int xdelay = 1000;
            time1 = millis();
            (VoltOff) = (VoltOff) - 1;
            lcd.setCursor(0, 1);
            lcd.print("Voltage-off: ");
            lcd.print(VoltOff);
            lcd.print("V");
            delay(xdelay);
            xdelay = xdelay / 1.5;
          }
          if (okbutton == HIGH)
          {
            loop();;
          }
          if (backbutton == HIGH)
          {
            Settings = true;
          }
          if (millis() > time1 + 60000)
          {
            loop();
          }
        }

      }

      if (backbutton == HIGH)
      {
        loop();
      }

      if (okbutton == HIGH)
      {
        loop();
      }

    }

  }
}

我认为你不应该仅仅为了你的工作而要求别人。人们不喜欢这里的不具体的问题,这些问题显示出他们自己的研究几乎没有努力

也就是说,最突出的一点是,所有的lcd.clear都缺少括号,它们应该是lcd.clear;
如果有什么不起作用,试着将代码分成更小的部分,并测试单个组件。

1.如何使循环开始时的代码每半秒运行一次,而不固定代码的其余部分

lcd.setCursor(0, 0);
  lcd.print("Volt: ");
  lcd.print(Voltage);
  lcd.print("V");
2.LCD显示从蓄能器流入Arduino的电流低于其启动发电机:onf,而非发电机:off:

lcd.print ("generator: off");
if (Voltage <= VoltOn && digitalRead(RELAY_PORT) == LOW)
  {
    digitalWrite(RELAY_PORT, HIGH);
    lcd.setCursor(0, 1);
    lcd.print ("generator: on");
  }

  if (Voltage >= VoltOff && digitalRead(RELAY_PORT) == HIGH)
  {
    digitalWrite(RELAY_PORT, LOW);
    lcd.setCursor(0, 1);
    lcd.print ("generator: off");


为什么同一句话重复了这么多次?请包括整个错误信息。