我做了一個簡單的液晶顯示器示例從this guide。 它工作後,我想玩它。我寫了一個程序來計算這個屏幕的fps。最大的問題是Arduino有多慢。Arduino液晶屏fps奇怪的行爲
程序代碼是在這裏:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int lastMillis = 0;
long fps = 0;
void setup() {
lcd.begin(16, 2);
lcd.print("seconds ");
lcd.setCursor(0, 1);
lcd.print("fps ");
}
void loop() {
if ((millis() - lastMillis) > 1000) {
lcd.setCursor(8, 0);
lcd.print(millis()/1000);
lcd.setCursor(4, 1);
lcd.print(fps);
fps = 0;
lastMillis = millis();
}
fps = fps + 1;
}
和它的工作。我很高興知道Arduino可以在一個小型的16x2液晶顯示器上以超過300,000 fps的速度運行。
但秒數超過32秒(幻數)後,fps凍結在值124,185,之後永遠不會改變。
如果有人知道爲什麼會發生這種情況,請解釋一下。我不明白爲什麼fps(每秒設置爲0)可能會凍結,而秒數則會不斷變化。
我收到了一個視頻,顯示發生了什麼。 Video
然後,ahaltindis建議,我改變了代碼如下:
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int lastMillis = 0;
long fps = 0;
void setup() {
lcd.begin(16, 2);
}
void loop() {
if ((millis() - lastMillis) > 1000) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("seconds ");
lcd.setCursor(0, 1);
lcd.print("fps ");
lcd.setCursor(8, 0);
lcd.print(millis()/1000);
lcd.setCursor(4, 1);
lcd.print(fps);
fps = 0;
lastMillis = millis();
}
fps = fps + 1;
}
而且它變得更糟糕:video
這是視頻https://www.youtube.com/watch?v=HacKep-U_CY – 2014-11-03 13:19:16
在將fps打印到顯示器之前,嘗試使用lcd.clear()清潔lcd。這可能會解決。 – ahaltindis 2014-11-03 14:05:17
我做到了,但沒有幫助。視頻:[鏈接](https://www.youtube.com/watch?v=J9KwaYnJEus) – 2014-11-03 14:38:21