LCD1602 คือ อุปกรณ์แสดงผลโดยใช้จอชนิด LCD ซึ่งสามารถแสดงผลข้อความได้แถวละ 16 ตัวอักษรและแสดงได้ 2 แถว เป็นอุปกรณ์มาตรฐานที่สามารถหาซื้อได้ทั่วไป โดยอุปกรณ์นี้มีจำนวนขาทั้งหมด 16 ขาและมีรายละเอียดการใช้งานดังรูป
-ภาคจ่ายไฟ
ให้ต่อไฟเลี้ยงและกราวด์ จากบอร์ดไปเข้า LCD ที่ขา 2 และ 1 ตามลำดับ และให้นำสายทั้ง 2 ไปต่อกับความต้านทานปรับค่าได้ที่ขาด้านนอกทั้ง 2 ด้าน จากนั้นให้นำขากลางของความต้านทานปรับค่าได้ ไปต่อกับขา 3 ของ LCD ซึ่งส่วนนี้จะเป็นการปรับค่า Contrast ของจอ LCD โดยใช้ความต้านทานปรับค่าได้ขนาด 10K หรือ 20K ก็ได้
-ภาคสัญญาณ
ให้ต่อสายไฟ 4 เส้น จาก LCD ขา 11, 12, 13 และ 14 ไปที่บอร์ดขาดิจิตอล 5, 4, 3 และ 2 ตามลำดับ
-ไฟ Backlight
ให้ต่อสายไฟ จาก LCD ขา 15, 16 ไปที่บอร์ดขา 13 และ Gnd ตามลำดับ ถ้าเราไม่ต้องการไฟ Backlight ก็ให้ข้ามขั้นตอนนี้ไป
โปรแกรมบน Arduino ADK
ขอให้เปิดโปรแกรม Arduino ขึ้นมาแล้วเขียนโค๊ดดังนี้
#include <LiquidCrystal.h>
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d4, d5, d6, d7 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 will control the backlight
int num = 0;
void setup()
{
pinMode(backLight, OUTPUT);
digitalWrite(backLight, 0); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row)
lcd.print("Hello, Arduino"); // change this text to whatever you like. keep it clean.
lcd.setCursor(0,1); // set cursor to column 0, row 1
lcd.print("ThaiNetBeans.com");
}
void loop()
{
if(num == 0) {
num = 1;
digitalWrite(13, 0); //backlight off
delay(7000);
} else {
num = 0;
digitalWrite(13, 1); //backlight on
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(200);
}
for (int positionCounter = 0; positionCounter < 32; positionCounter++) {
// scroll one position right:
lcd.scrollDisplayRight();
// wait a bit:
delay(200);
}
for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(200);
}
delay(3000);
}
}
จากนั้น Upload ไปที่บอร์ด แล้วจะได้ผลดังวิดิโอ
ไม่มีความคิดเห็น:
แสดงความคิดเห็น