我在试着创造一种数字选择器。它将显示0到9,并使用X,我将写一个数字,你可以选择一个数字。例如,01234567x9或0123x56789。不过,我很难把这个打印到LCD上。我使用的是tinkercad,所以我所有的引脚连接都是预先定义的,而且相当正确。我正在使用标准的tinkercad和LiquidCrystal作为库。
但是当我在void ()中使用lcd.print("Hello World)时,它会连续地打印Hello,这显然是因为我把它放在了一个循环中。我试过把它放进一个函数里,但我不能让它起作用.帮个忙就太好了。
这是我目前使用的代码,它以错误的形式返回“函数'void PrintText()‘的”太多参数“。
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char lcdtxt[] = "0123456789 x";
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
}
void PrintText(){
lcd.print(lcdtxt);
lcd.clear();
}
void loop() {
PrintText(lcdtxt);
}发布于 2020-10-16 08:15:36
看到您的代码,您有一个全局char数组,该数组保存将要编写的内容,PrintText()将从其中获取它的输入:
char lcdtxt[] = "0123456789 x";
void PrintText(){
lcd.print(lcdtxt);
lcd.clear();
}
void loop() {
PrintText(lcdtxt);
}所以,PrintText()不会使用任何参数,你用一个参数来调用它。在这种情况下,错误消息会准确地告诉您正在发生什么。
要修复代码,应该只将参数移到“`PrintText()”调用,因为我知道您已经初始化了数组。
void loop() {
PrintText();
}无论如何,您应该定义一个接受PrintText()的const char *函数并将其发送到液晶显示器。
关于hello不断地重复自己,我将调用PrintText()到setup(),因为您不需要这种行为。或者把它留在loop()中,然后通过一个exit(0)停下来。
https://stackoverflow.com/questions/64385129
复制相似问题