:::

7-3 LCD特殊字元

一、write( )函式

write( )函式的功能是將字元寫入 LCD 中,有一個參數 data 必須設定,data 參數 是所要寫入 LCD 中的字元,write( )函式會傳回所寫入的位元組總數。在使用 write( ) 函式之前,必須先使用 LiquidCrystal( )函式宣告一個 LiquidCrystal 資料型態的物件。
 
格式: write(data)  
範例:

  include <LiquidCrystal.h>    //使用LiquidCrystal函式庫。
  LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);//宣告 lcd 變數。 
  lcd.write("hello, world!");     //寫入字元"hello, world!"。

 

二、LCM字形碼

 

 

三、顯示範例

顯示25℃

#include <Wire.h>  // Arduino IDE 內建
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

const byte degree=25;
const byte degreeSymbol=B11011111;
void setup() 
{
  lcd.begin(16,2); 

}   
void loop() 
{
  lcd.setCursor(0,0);
  lcd.print(degree);  
  lcd.write(degreeSymbol);  
  lcd.print("C");
}

 

四、練習

1.設計 Arduino 程式,控制 LCD 顯示 " π=180° "。

2.設計 Arduino 程式,控制 LCD 顯示 " 10÷2=5 "。 


搜尋