เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล LCD16x2
ฟังก์ชั่นที่ใช้ในกลุ่ม LCD http://arduino.cc/en/Tutorial/LiquidCrystal (http://arduino.cc/en/Tutorial/LiquidCrystal)
-lcd.begin()http://arduino.cc/en/Reference/LiquidCrystalBegin (http://arduino.cc/en/Reference/LiquidCrystalBegin)
-lcd.print() http://arduino.cc/en/Reference/LiquidCrystalPrint (http://arduino.cc/en/Reference/LiquidCrystalPrint)
-lcd.setCursor() http://arduino.cc/en/Reference/LiquidCrystalSetCursor (http://arduino.cc/en/Reference/LiquidCrystalSetCursor)
-Liquid Crystal Library (ฟังก์ชั่นอื่น ๆ ที่มีให้ใช้งาน) http://arduino.cc/en/Reference/LiquidCrystal (http://arduino.cc/en/Reference/LiquidCrystal)
*ไลบารี่ LiquidCrystal.h มีมาให้แล้วพร้อมโปรแกรม Arduino IDE ไม่ต้องติดตั้งเพิ่ม
ไลบารี่เพิ่มเติม
-Keypah.h (ไลบรารี่ตัวเดียวกันกับงานครั้งที่ 38 หากติดตั้งแล้วไม่ต้องทำซ้ำ)*ดูวิธีติดตั้งในงานครั้งที่ 38 (http://www.praphas.com/forum/index.php?topic=289.0)
ฟังก์ชั่นในไลบารี่ Keypad.h http://playground.arduino.cc/Code/Keypad (http://playground.arduino.cc/Code/Keypad)
-begin(
-waitForKey()
-getKey()
-getState()
-keyStateChanged()
-setHoldTime()
-setDebounceTime()
-addEventListener()
ฟังก์ชั่นที่ใช้งาน
-pinMode() http://arduino.cc/en/Reference/PinMode (http://arduino.cc/en/Reference/PinMode)
-digitalWrite() http://arduino.cc/en/Reference/DigitalWrite (http://arduino.cc/en/Reference/DigitalWrite)
-delay() http://arduino.cc/en/reference/delay (http://arduino.cc/en/reference/delay)
*หมายเหตุ จากการทดลองไลบรารี่ keypad เมื่อใช้ขา D13 จะทำให้ไม่สามารถใช้งานได้ ดังนั้นเวลาใช้งานขา D13 จึงห้ามใช้
โจทย์การทดลอง
-เขียนโปรแกรมรับค่าจากคีย์แพดแสดงผล LCD 16 character 2 line
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino
(http://www.praphas.com/PhotoForum/arduino/Lab-38-01.png)
วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)
(http://www.praphas.com/PhotoForum/arduino/Lab-38-01.png)
บริเวณใช้งานบอร์ดทดลอง
(http://www.praphas.com/PhotoForum/arduino/Lab-38-01.png)
โมดูลสำเร็จรูปเพิ่มเติม
Keypad
http://www.arduinoall.com (คลิก) (http://www.arduinoall.com/product/119/3x4-matrix-keypad)
LCD 16x2
http://www.arduinoall.com/product/142/1602-lcd-blue-screen-16x2-lcd-with-backlight-of-the-lcd-screen (http://www.arduinoall.com/product/142/1602-lcd-blue-screen-16x2-lcd-with-backlight-of-the-lcd-screen)
ตำแหน่งขาต่อของคีย์แพด
(http://www.praphas.com/PhotoForum/arduino/Lab-37-b.png)
ตัวอย่างโปรแกรมรับค่าจากคีย์แพด
#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
#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() {}