我有這樣的代碼,應該在LCD屏幕的第一行顯示一個時鐘,並在第二行文本「Hello World」:Arduino的LCD時鐘不工作
#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
爲什麼?
我不想使用時間庫,BTW。
如果你打電話給millis()會打印出什麼? – CBredlow
代碼上傳以來的毫秒數。 – Cinder