在我的 Arduino 库中使用外部库
Use external library in my Arduino library
我想创建一个个人库,在那里我使用另一个。在我的代码中,我在私有部分声明并初始化了库。
但是我有错误'((LCD*)this)->LCD::lcd' does not have class type
.
我已经写了几个版本,但没有任何变化。充其量我可以显示print Test01
和test02
.
.h
#ifndef LCD_h
#define LCD_h
#include <LiquidCrystal_I2C.h>
class LCD{
public:
LCD();
void firstLine();
void secondLine(float tempInCelsius);
private:
LiquidCrystal_I2C lcd(0x27, 16, 2);
};
#endif
。.cpp
#include "LCD.h"
#include <LiquidCrystal_I2C.h>
LCD::LCD(){
Serial.begin(9600);
Serial.println("Test 01");
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
}
void LCD::secondLine(float tempInCelsius){
Serial.println("Test 03");
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("T = ");
lcd.print(tempInCelsius);
}
.ino
#include "LCD.h"
LCD CrystalLCD();
void setup(void)
{
Serial.begin(9600);
Serial.println("Test 02");
}
void loop(void)
{
CrystalLCD.secondLine(1.40);
}
我也会给你整个错误消息。
[Starting] Verify sketch - arduino.ino
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
In file included from /Users/WorkSpace/Make/RucheChaufante/ino/LCD.cpp:1:0:
LCD.h:13: error: expected identifier before numeric constant
LiquidCrystal_I2C lcd(0x27, 16, 2);
^
LCD.h:13: error: expected ',' or '...' before numeric constant
/Users/WorkSpace/Make/RucheChaufante/ino/arduino.ino: In constructor 'LCD::LCD()':
arduino:9: error: '((LCD*)this)->LCD::lcd' does not have class type
Serial.println("Test 02");
^
arduino:10: error: '((LCD*)this)->LCD::lcd' does not have class type
}
^
arduino:11: error: '((LCD*)this)->LCD::lcd' does not have class type
^
/Users/WorkSpace/Make/RucheChaufante/ino/arduino.ino: In member function 'void LCD::secondLine(float)':
arduino:16: error: '((LCD*)this)->LCD::lcd' does not have class type
arduino:17: error: '((LCD*)this)->LCD::lcd' does not have class type
arduino:18: error: '((LCD*)this)->LCD::lcd' does not have class type
arduino:19: error: '((LCD*)this)->LCD::lcd' does not have class type
/Users/WorkSpace/Make/RucheChaufante/ino/arduino.ino: In function 'void loop()':
arduino:14: error: request for member 'secondLine' in 'CrystalLCD', which is of non-class type 'LCD()'
CrystalLCD.secondLine(1.40);
^
exit status 1
[Error] Exit with code=1
不能初始化类声明中的成员。尝试:
class LCD
{
public:
LCD();
void firstLine();
void secondLine(float tempInCelsius);
private:
LiquidCrystal_I2C lcd;
};
但是,您可以在构造函数中初始化此类成员(如果它们不提供默认构造函数,则必须初始化(。尝试:
LCD::LCD() : lcd(0x27, 16, 2) {
Serial.begin(9600);
Serial.println("Test 01");
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
}
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 在函数内部的声明中初始化数组,并在外部使用它
- 使外部项目可用于find_package CMake
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- 人脸跟踪arduino代码的优化
- C++:来自外部文件的Trivia
- 从函数角度看ID到文件路径的内部与外部映射
- C++:将外部库链接到dll库
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- vscode下的Arduino代码出现意外编译错误
- 节俭并发:未解决的外部问题
- 如何在c++中从git建立外部库
- Arduino从Txt读取整数
- 未解析的外部符号_MsiLocateComponentW@12.
- 如何使用对C函数和类对象的外部调用来处理C++头文件
- Arduino C++在构造函数中用参数声明对象数组
- 在我的 Arduino 库中使用外部库
- 如何使用Arduino将外部电源用于接近传感器