I具有4条字符OLED(NHD0420CW-AB3)和C ++的结构,其中包含8种不同的线路。 每次按下按钮时,我都希望显示器将每个行移动1位置1位置,以及在底线中添加的结构中的下一个数组。 在结构中的最后一行放置在显示屏底部之后,下一按按钮将第一个阵列放在底部,就像圆形缓冲区一样。我将感谢有关如何索引这些行的任何意见。
struct menus {
char line0[21] = {"This is a menu 12351"};
char line1[21] = {"This is a menu 12352"};
char line2[21] = {"This is a menu 12353"};
char line3[21] = {"This is a menu 12354"};
char line4[21] = {"This is a menu 12355"};
char line5[21] = {"This is a menu 12356"};
char line6[21] = {"This is a menu 12357"};
char line7[21] = {"This is a menu 12358"};
u_int8_t top_line = 0; // place holder for which line is at the top of the display
} menu;
// Function to update the display sendString([text to display],[column],[row])
void updateDisplay() {
LCD.sendString(menu.line0, 0, 0);
LCD.sendString(menu.line1, 0, 1);
LCD.sendString(menu.line2, 0, 2);
LCD.sendString(menu.line3, 0, 3);
}
有一种方法可以做类似:lcd.sendstring(菜单。(线+变量),0,0)?
我尝试的测试
// Function to scroll the display
void scrollDisplay()
{
menu.top_line++;
if (menu.top_line > 7)
{
menu.top_line = 0;
}
// Calculate the indices of the lines to display
int line0_index = menu.top_line % 8;
int line1_index = (menu.top_line + 1) % 8;
int line2_index = (menu.top_line + 2) % 8;
int line3_index = (menu.top_line + 3) % 8;
// Update the display with the new lines
LCD.sendString(menu.line0 + line0_index, 0, 0);
LCD.sendString(menu.line1 + line1_index, 0, 1);
LCD.sendString(menu.line2 + line2_index, 0, 2);
LCD.sendString(menu.line3 + line3_index, 0, 3);
}
,但线只滚动向右滚动。
使用line0, line1, etc...
现在您可以索引要使用哪个行。
LCD.sendString(menu.lines[line0_index], 0, 0);
LCD.sendString(menu.lines[line1_index], 0, 1);
LCD.sendString(menu.lines[line2_index], 0, 2);
LCD.sendString(menu.lines[line3_index], 0, 3);