我做了一个简单的液晶显示器示例从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