LCD1602 Arduino 电位器
VSS → GND
VDD → 5V
VO → 电位器中脚
RS → 12
E → 11
D4-D7 → 5,4,3,2
A → 5V(背光)
K → GND
电位器左脚 → 5V
电位器中脚 → LCD VO
电位器右脚 → GND- #include <LiquidCrystal.h>
- // 初始化LCD,设置接口引脚
- // RS, E, D4, D5, D6, D7
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- void setup() {
- // 设置LCD的列数和行数(16列2行)
- lcd.begin(16, 2);
-
- // 打印初始信息
- lcd.print("Hello, World!");
-
- // 将光标移动到第二行第一个位置
- lcd.setCursor(0, 1);
- lcd.print("LCD1602 Test");
-
- delay(2000); // 显示2秒
- }
- void loop() {
- // 清屏
- lcd.clear();
-
- // 显示静态文本
- lcd.print("Arduino LCD");
- lcd.setCursor(0, 1);
- lcd.print("Welcome!");
-
- delay(2000);
-
- // 显示滚动文本
- lcd.clear();
- lcd.print("Scrolling Text");
- for (int position = 0; position < 13; position++) {
- lcd.scrollDisplayLeft();
- delay(300);
- }
-
- delay(1000);
-
- // 显示计数
- lcd.clear();
- lcd.print("Counter:");
- for (int i = 0; i <= 10; i++) {
- lcd.setCursor(0, 1);
- lcd.print("Count: ");
- lcd.print(i);
- delay(500);
- }
-
- delay(1000);
- }
复制代码
|