Arduino(C/C++)代码在LCD上显示阵列的内容
Arduino (C/C++) Code To Display Contents of Array on LCD
在发布这篇文章之前,我已经尽可能多地进行了研究,但我是编程新手,所以我的普遍无知使我无法真正知道如何提出正确的问题。
当前目标:
- 构建一个存储50多个英语单词/短语的数组
- 访问我的Arduino上的数组,并在我的LCD上显示单个单词/短语;以及
- 点击Arduino上的按钮切换单词/短语
硬件规格:SainSmart UnoR3,基于HD44780 的液晶显示器
问题:编写一个代码,当我按下按钮时会显示一个新词。
"你好,世界!"LCD的代码
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}
数组中随机字符串的代码
#include <stdio.h>
#include <stdlib.h>
int main() {
const char *messages[] = {
"Hello!",
"How are you?",
"Good stuff!"
};
const size_t messages_count = sizeof(messages) / sizeof(messages[0]);
char input[64];
while (1) {
scanf("%63s", input);
printf("%sn", messages[rand() % messages_count]);
}
return 0;
}
我还有一个Arduino Uno和一个LCD显示屏。您的任务将是调试硬件和软件。所以,让我问一些问题。
在您的代码列表中,当您运行草图时,LCD上会显示"你好,世界!"吗?
您提供的main()
与此问题有何关联。具体来说,main()
在哪里运行?我希望这不是你素描的一部分!!
在您的loop()
中,您确实没有有延迟。在一个刚起步的程序员。。。通常在显示内容时,您需要暂停几秒钟,否则您将以每秒数千次的更改来驱动LCD。
因此,添加一个delay(3000);
语句,在LCD更新之间延迟3秒(3000毫秒)。
接下来,在"loop()"中,您需要测试是否按下了按钮,但现在只需要让LCD显示即可。
请做这些事情,并相应地更新你的问题,我会跟进更多的建议/问题。
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- OpenMP阵列性能较差
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 为什么以下代码在阵列中显示上个月的最后一个月,而不是显示降雨量最高和最低降雨量的月份
- 将25个甚至整数存储到一个名为intlist的整数阵列中,然后在屏幕上显示数组,并在屏幕上显示名为fivintegers
- 为什么Xor-ing两个“ char”阵列显示垃圾位
- char阵列使用新的实例化后显示垃圾
- OpenGL:从数据阵列生成2D纹理以显示在四边形上
- 显示阵列排列
- 从队列中显示2D阵列后程序崩溃
- 将我的阵列移动到 Mat 并使用打开的 CV 显示图像
- 尝试修改和显示 2D 阵列时出错
- 如何显示非对角线二维阵列元素
- 如何不仅要求动态2D阵列的行数和列数,还要求以表格格式显示
- Arduino(C/C++)代码在LCD上显示阵列的内容
- 2D 阵列循环显示
- 使用二维阵列在地图/栅格上显示坐标