我试图创建一个基本的arduino uno秒表显示在液晶显示器上。在理论上,这是一个非常容易的项目,但我遇到了问题,我的显示器。我计算我的分钟和秒,然后尝试用冒号将它们打印到显示器上。从java来的,我认为加号是刚刚使用的。然而,这会导致大量随机的、无法识别的字符在屏幕上闪烁。我测试了秒和分钟是否分开工作,所以我认为这是在lcd.print()的语法中。我在其他地方找不到这个地址。我会感谢你的帮助。
代码:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int seconds;
int minutes;
int timedif;
int starttime = -1;
void setup()
{
lcd.begin(16, 2); //Initialize the 16x2 LCD
lcd.clear(); //Clear any old data displayed on the LCD
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("Stopwatch");
lcd.setCursor(0,1);
if (starttime == -1) { //if running first time, time dif is initiated
starttime = millis();
}
timedif = (millis() - starttime)/1000; //will get difference in terms of seconds
minutes = floor(timedif/60); // divides by sixty, drops decimal
seconds = timedif%60; //gets remainder of divided by 60
lcd.print(minutes + ";" + seconds);
}发布于 2018-01-16 19:13:36
您正在打印的是JAVA语法,而Arduino使用的是C语法。关于如何使用这个API,请参见这。
您需要构建字符串(例如char数组)并将其传递给print方法。
https://stackoverflow.com/questions/48287353
复制相似问题