ผู้เขียน หัวข้อ: งานครั้งที่ 38 เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล LCD16x2  (อ่าน 19061 ครั้ง)

admin

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 706
    • ดูรายละเอียด
    • อีเมล์
เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล LCD16x2
ฟังก์ชั่นที่ใช้ในกลุ่ม LCD http://arduino.cc/en/Tutorial/LiquidCrystal
-lcd.begin()http://arduino.cc/en/Reference/LiquidCrystalBegin
-lcd.print() http://arduino.cc/en/Reference/LiquidCrystalPrint
-lcd.setCursor() http://arduino.cc/en/Reference/LiquidCrystalSetCursor
-Liquid Crystal Library (ฟังก์ชั่นอื่น ๆ ที่มีให้ใช้งาน) http://arduino.cc/en/Reference/LiquidCrystal
*ไลบารี่ LiquidCrystal.h มีมาให้แล้วพร้อมโปรแกรม Arduino IDE ไม่ต้องติดตั้งเพิ่ม

ไลบารี่เพิ่มเติม
-Keypah.h (ไลบรารี่ตัวเดียวกันกับงานครั้งที่ 38 หากติดตั้งแล้วไม่ต้องทำซ้ำ)*ดูวิธีติดตั้งในงานครั้งที่ 38

ฟังก์ชั่นในไลบารี่ Keypad.h http://playground.arduino.cc/Code/Keypad
-begin(
-waitForKey()
-getKey()
-getState()
-keyStateChanged()
-setHoldTime()
-setDebounceTime()
-addEventListener()

ฟังก์ชั่นที่ใช้งาน
-pinMode() http://arduino.cc/en/Reference/PinMode
-digitalWrite() http://arduino.cc/en/Reference/DigitalWrite
-delay() http://arduino.cc/en/reference/delay

*หมายเหตุ จากการทดลองไลบรารี่ keypad เมื่อใช้ขา D13 จะทำให้ไม่สามารถใช้งานได้ ดังนั้นเวลาใช้งานขา D13 จึงห้ามใช้

โจทย์การทดลอง
-เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล LCD 16 character 2 line
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)

วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino


วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)


บริเวณใช้งานบอร์ดทดลอง


โมดูลสำเร็จรูปเพิ่มเติม
Keypad
http://www.arduinoall.com (คลิก)

LCD 16x2
http://www.arduinoall.com/product/142/1602-lcd-blue-screen-16x2-lcd-with-backlight-of-the-lcd-screen

ตำแหน่งขาต่อของคีย์แพด


ตัวอย่างโปรแกรมรับค่าจากคีย์แพด
โค๊ด: [Select]
#include <Keypad.h>
const byte ROWS = 4;       //four rows
const byte COLS = 3;       //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {13,12,11,10};    //connect to the row pinouts of the keypad
byte colPins[COLS] = {A0,A1,A2};       //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
     Serial.begin(9600);
}
void loop()
{
     char key = keypad.getKey();
     if (key != NO_KEY)
     {
           Serial.println(key);
     }
}

ตัวอย่างโปรแกรมแสดงผลจอ LCD
โค๊ด: [Select]
#include <LiquidCrystal.h>
/* The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
*/
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);       // set up the LCD's connection pins
void setup()
{
  lcd.begin(16, 2);       // set up the LCD's number of columns and rows:
  lcd.print("hello, world!");
}
void loop() {}
« แก้ไขครั้งสุดท้าย: มิถุนายน 27, 2017, 09:52:50 PM โดย admin »