如何修复lcd.begin()错误(请plz全部读取)

问题描述 投票:0回答:1

我使用nodecmu v1.0在不使用磁带的情况下制作卷尺(因此将其称为非卷尺?),这是代码:

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27f, 16, 2);

#define trigPin D5
#define echoPin D6

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  lcd.begin();
  lcd.backlight();
  lcd.home();
  lcd.print("Distance ");
}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

  lcd.setCursor(0, 1);
  if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
    lcd.print("Out of range");
  } else {
    Serial.print(distance);
    Serial.println(" cm");
    lcd.print(distance);
    lcd.print(" CM       ");
  }
  delay(500);
} 

然后我得到这个错误

C:\Users\Lenovo\Desktop\nonwireruler\nonwireruler.ino: In function 'void setup()':

nonwireruler:11:13: error: no matching function for call to 'LiquidCrystal_I2C::begin()'

   lcd.begin();

             ^

C:\Users\Lenovo\Desktop\nonwireruler\nonwireruler.ino:11:13: note: candidate is:

In file included from C:\Users\Lenovo\Desktop\nonwireruler\nonwireruler.ino:1:0:

C:\Users\Lenovo\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:58:8: note: void LiquidCrystal_I2C::begin(uint8_t, uint8_t, uint8_t)

   void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );

        ^

C:\Users\Lenovo\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:58:8: note:   candidate expects 3 arguments, 0 provided

exit status 1
no matching function for call to 'LiquidCrystal_I2C::begin()'

所以我该如何解决?

arduino arduino-ide lcd
1个回答
-1
投票

如果您的LCD具有I2C模块,请使用此代码。

© www.soinside.com 2019 - 2024. All rights reserved.