我的Arduino项目有问题。
基本上,我要制造的是一个可以显示温度,时钟速度,风扇速度等的硬件监视器。
我正在通过串行监视器将时钟速度和温度等值发送到arduino。 arduino读取这些值并显示在屏幕上
问题如下。它可以很好地读取串行输出。但是显示它不能正常工作。 arduino永远需要在显示屏上加载这些值,而更新时,如果我希望为1s,则需要10-15s。
可能是C#发送给Arduino的值名称太长,所以在很短的时间内完成所有这些操作都需要太多时间和处理能力吗?
我让arduino在屏幕上显示的值越少,它变得越快。
下面将向您展示Arduino串行监视器并显示代码(是的,我可能会犯很多错误,我4个月前才刚开始使用Arduino)
串行监视器:
void RefreshAllValues()
{
static bool isBuffering = false;
int CPUL;
int GPUL;
int RAMT;
int RAMA;
int CPUC;
int GPUC;
int GPUMC;
int CPUT;
int GPUT;
static String IncomingMessage = "";
if (Serial.available() > 0)
{
char IncomingChar = (char)Serial.read();
if (IncomingChar == '#')
{
isBuffering = true;
IncomingMessage = "";
}
if (IncomingChar == '*')
{
isBuffering = false;
IncomingMessage += IncomingChar;
if (IncomingMessage.startsWith("#CPU_LOAD:"))
{
int dv = IncomingMessage.indexOf(":");
CPUL = IncomingMessage.substring(dv + 1).toInt();
CPULoad = String(CPUL) + "%";
IncomingMessage = "";
}
else if (IncomingMessage.startsWith("#GPU_LOAD:"))
{
int dv = IncomingMessage.indexOf(":");
GPUL = IncomingMessage.substring(dv + 1).toInt();
GPULoad = String(GPUL) + "%";
IncomingMessage = "";
}
else if (IncomingMessage.startsWith("#TOTAL_RAM:"))
{
int dv = IncomingMessage.indexOf(":");
RAMT = IncomingMessage.substring(dv + 1).toInt();
RAMTotal = String(RAMT) + "MB";
IncomingMessage = "";
}
else if (IncomingMessage.startsWith("#AVAILABLE_RAM:"))
{
int dv = IncomingMessage.indexOf(":");
RAMA = IncomingMessage.substring(dv + 1).toInt();
RAMAvailable = String(RAMA) + "MB";
IncomingMessage = "";
}
else if (IncomingMessage.startsWith("#GPU_CLOCK:"))
{
int dv = IncomingMessage.indexOf(":");
GPUC = IncomingMessage.substring(dv + 1).toInt();
GPUClock = String(GPUC) + "Mhz";
IncomingMessage = "";
}
else if (IncomingMessage.startsWith("#GPU_MEMORY_CLOCK:"))
{
int dv = IncomingMessage.indexOf(":");
GPUMC = IncomingMessage.substring(dv + 1).toInt();
GPUMemory = String(GPUMC) + "Mhz";
IncomingMessage = "";
}
else if (IncomingMessage.startsWith("#CPU_CLOCK:"))
{
int dv = IncomingMessage.indexOf(":");
CPUC = IncomingMessage.substring(dv + 1).toInt();
CPUClock = String(CPUC) + "Mhz";
IncomingMessage = "";
}
else if (IncomingMessage.startsWith("#CPU_TEMP:"))
{
int dv = IncomingMessage.indexOf(":");
CPUT = IncomingMessage.substring(dv + 1).toInt();
CPUTemp = String(CPUT) + "C";
IncomingMessage = "";
}
else if (IncomingMessage.startsWith("#GPU_TEMP:"))
{
int dv = IncomingMessage.indexOf(":");
GPUT = IncomingMessage.substring(dv + 1).toInt();
GPUTemp = String(GPUT) + "C";
IncomingMessage = "";
}
}
if (isBuffering)
{
IncomingMessage += IncomingChar;
}
}
}
将其显示在屏幕上
tft.setFont(Terminal6x8);
RefreshAllValues();
delay(10); //Otherwise it skips the 1st value that comes through
tft.drawText(30, 10, "CPU");
tft.drawText(130, 10, "GPU");
tft.drawText(30, 20, CPULoad);
tft.drawText(30, 40, CPUClock);
tft.drawText(130, 20, GPUTemp);
tft.drawText(130, 40, GPUClock);
tft.drawText(130, 60, GPULoad);
tft.drawText(75, 85, RAMAvailable);
我基本上不知道如何解决此问题,并且搜索如何在两次串行读取之间设置5s的间隔并没有给我任何有益的结果。
我希望有人可以帮助我 谢谢