我有这段代码应该在 LCD 屏幕的第一行显示时钟,在第二行显示文本“Hello World”:
#include <LiquidCrystal.h>
int x=0;
int a=0;
int y=0;
int z=0;
int initialHours = 14;//set this to whatever
int initialMins = 37;
int initialSecs = 45 + 11;
int secspassed()
{
x = initialHours*3600;
x = x+(initialMins*60);
x = x+initialSecs;
x = x+(millis()/1000);
return x;
}
int hours()
{
y = secspassed();
y = y/3600;
y = y%24;
return y;
}
int mins()
{
z = secspassed();
z = z/60;
z = z%60;
return z;
}
int secs()
{
a = secspassed();
a = a%60;
return a;
}
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup(){
lcd.print("load...");
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 1);
lcd.print("Hello world");
}
void loop(){
digitalClockDisplay();
}
void printDigits(byte digits){
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}
char sep()
{
x = millis()/1000;
if(x%2==0)
{
lcd.print(":");
}
else {
lcd.print(" ");
}
}
void digitalClockDisplay(){
lcd.setCursor(0,0);
printDigits(
hours());
sep();
printDigits(mins());
sep();
printDigits(secs());
}
而不是打印以下内容
12:35:15
Hello World
它改为打印:
253:255:243
Hello World
为什么?
我不想使用时间库,顺便说一句。