用户工具

站点工具


ocrobot:alpha:1602:tutorial10

显示Z到A

这个例程显示了如何在OCROBOT ALPHA 1602 LCD显示屏上显示Z到A。

硬件

搭建电路

  1. ALPHA 1602 LCD模块插入并行扩展版1号槽位。
  2. ALPHA MEGA328-U模块插入并行扩展板2号槽位。
  3. USB线连接计算机与ALPHA MEGA328-U。

代码

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); 
int thisChar = 'a';
void setup() {
  lcd.init();
  lcd.backlight();   
  lcd.cursor();
}
 
void loop() {
  // 在'm'改变方向:
  if (thisChar == 'm') {
    // 向右
    lcd.rightToLeft();
  }
  // 在 's'返回:
  if (thisChar == 's') {
    // 向左
    lcd.leftToRight();
  }
  // 在'z'重来:
  if (thisChar > 'z') {
    // 返回 (0,0):
    lcd.home();
    // 在 0 开始
    thisChar = 'a';
  }
  // 显示字符
  lcd.write(thisChar);
  //等一秒:
  delay(1000);
  // 增加字符:
  thisChar++;
}

返回上一级

ocrobot/alpha/1602/tutorial10.txt · 最后更改: 2023/06/07 04:23 由 127.0.0.1