液晶显示器 Arduino Uno
LCD display Arduino Uno
我正在尝试创建一个显示在液体 crystal 显示屏上的基本 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);
}
您正在打印的是 JAVA
语法,而 Arduino
使用的是 C
语法。
请参阅 this 了解如何使用此 API。
您需要构建字符串(例如作为字符数组)并将其传递给 print
方法
我正在尝试创建一个显示在液体 crystal 显示屏上的基本 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);
}
您正在打印的是 JAVA
语法,而 Arduino
使用的是 C
语法。
请参阅 this 了解如何使用此 API。
您需要构建字符串(例如作为字符数组)并将其传递给 print
方法