使用 Arduino 板控制 LCD 在第 0 行、第 0 列顯示字元"up counter",在第 0 行、第 1 列顯示 00~99 計數值,每秒上數加 1。本例使用 lcd.print( )函式直接將 計數值顯示在所設定的 LCD 座標位置即可。
#include <Wire.h> // Arduino IDE 內建
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int counts=0;
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("up counter");
}
void loop()
{
lcd.setCursor(0,1);
if(counts<10)
lcd.print("0");
lcd.print(counts);
delay(1000);
counts++;
if(counts==100)
counts=0;
}
1.設計 Arduino 程式,在第 0 行、第 0 列顯示字元"down counter",在第 0 行、第 1 列 顯示 99~00 計數值,每秒下數加 1。
2.設計 Arduino 程式,在第 0 行、第 0 列顯示字元"up counter",在第 0 行、第 1 列顯 示 0000~9999 計數值,每秒上數加 1