no matching function for call to 'U8G2_SSD1306_128X64_NONAME_1_HW_I2C::drawStr(int, int, StringSumHelper&)'
时间: 2024-04-09 18:33:32 浏览: 49
抱歉,我之前提供的示例代码中有一个错误。在U8g2库中,drawStr()函数的参数类型应为const char*,而不是String类型。
请尝试将以下代码行:
u8g2.drawStr(0, i * 12, "> " + String(menuItems[i]));
更改为:
u8g2.drawStr(0, i * 12, menuItems[i]);
这样应该可以解决编译错误。
对于Arduino DS1302和LCD1602万年历的示例代码,请查看下面的示例:
```cpp
#include <DS1302.h>
#include <LiquidCrystal_I2C.h>
// 定义DS1302模块的引脚
const int DS1302_CLK = 13;
const int DS1302_DAT = 11;
const int DS1302_RST = 10;
// 定义LCD1602模块的I2C地址
const int LCD_I2C_ADDR = 0x27;
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
// 创建DS1302和LCD对象
DS1302 rtc(DS1302_CLK, DS1302_DAT, DS1302_RST);
LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_COLS, LCD_ROWS);
void setup() {
// 初始化LCD屏幕
lcd.begin(LCD_COLS, LCD_ROWS);
// 初始化DS1302模块
rtc.halt(false);
rtc.writeProtect(false);
}
void loop() {
// 读取DS1302模块的日期和时间
int year = rtc.getYear();
int month = rtc.getMonth(CENTURY);
int day = rtc.getDay();
int hour = rtc.getHour(h12, PM);
int minute = rtc.getMinute();
int second = rtc.getSecond();
// 显示日期和时间在LCD屏幕上
lcd.setCursor(0, 0);
lcd.print("Date: ");
lcd.print(String(year) + "/" + String(month) + "/" + String(day));
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(String(hour) + ":" + String(minute) + ":" + String(second));
delay(1000);
}
```
请确保已安装DS1302和LiquidCrystal_I2C库,并将LCD1602通过I2C连接到Arduino板。
这段代码将读取DS1302模块的日期和时间,并在LCD1602屏幕上显示。希望这次提供的代码能够正常工作。如果您仍然遇到问题,请告诉我。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)