【发布时间】:2018-01-17 03:13:36
【问题描述】:
我正在尝试创建一个显示在液晶显示器上的基本 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);
}
【问题讨论】:
标签: arduino-uno