我已经在Arduino Mega 2560周围为文件选择器创建了一个菜单。问题是,当我在菜单中移动时,arduino的RAM会填充数据,并且在文件一半后,arduino重新启动,因为公羊已满。有没有办法从LCD面板的最后打印行中清洁arduino的RAM? (我不想用菜单行来清洗阵列,如果有的话,只清洗发送到LCD的数据缓存。)
这些是我代码的一部分(完整的代码很多)
//converts a string to a char array, for the lcd.print function
char* ConvertStringToCharArray(String string) {
char* c= new char[string.length() + 1];
strcpy(c, string.c_str());
return c;
}
//truncates a string, if its longer than the maxLength
String TruncateString(String value, int maxLength)
{
if (value.length() <= maxLength) {
return value;
}
else {
return value.substring(0, maxLength);
}
}
/*I've written a function for Printing out Parts of an array with the menu lines (Arguments: l=Object for the LCD; menupos= position in the array, to get the lines; menuname=Header of the menu;menustring=string Array with all menu lines; menustring_length=length of the menustring array):*/
void SetMenuPos(LiquidCrystal l, int menupos, String menuname, String* menustring, int menustring_size) {
l.clear();//clears the lcd
if (menupos == menustring_size - 1) {/*if the last position of the menu is checked, i want to display '>' in the last line*/
l.home();
l.print(ConvertStringToCharArray(TruncateString(menuname, 16))); //convert a truncatet string of the menu line to char array and print it to the lcd, i've truncate the string, else it would be to long. I'm repeating this process until everything is on the LCD
l.setCursor(1, 1);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos - 2], 15)));
l.setCursor(0, 3);
l.print(F(">"));
l.setCursor(1, 2);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos - 1], 15)));
l.setCursor(1, 3);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos], 15)));
}
else if (menupos == 0) {/*if the first position of the menu is checked, i want to display '>' in the first line*/
l.home();
l.print(ConvertStringToCharArray(TruncateString(menuname, 16)));
l.setCursor(1, 1);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos], 15)));
l.setCursor(0, 1);
l.print(F(">"));
l.setCursor(1, 2);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos + 1], 15)));
l.setCursor(1, 3);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos + 2], 15)));
}
else {/*if any other position of the menu is checked, i want to display '>' in the middle line*/
l.home();
l.print(ConvertStringToCharArray(TruncateString(menuname, 16)));
l.setCursor(1, 1);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos - 1], 15)));
l.setCursor(0, 2);
l.print(F(">"));
l.setCursor(1, 2);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos], 15)));
l.setCursor(1, 3);
l.print(ConvertStringToCharArray(TruncateString(menustring[menupos + 1], 15)));
}
}
我希望这是足够的信息