Arduino UNO 專用 LCD 1602 Keypad Shield 液晶螢幕 擴展板 MEGA 可【現貨】
LCD 1602 Keypad Shield 字符液晶 輸入輸出 擴展板 【有現貨可立即出貨】
還在為LCD 1602的腳位不足,沒有按鍵使用設定不易而煩惱嗎?【有現貨可立即出貨】
將LCD 1602 Keypad Shield Arduino Uno R3 專用擴展板插入UNO就搞定了! Arduino MEGA 也可搞定!
研究生、研發必備利器!
※規格:
(1)尺寸:80mm(長)、58mm(寬)、21mm(高、含排針長度)
SIZE:80x58x21mm
(2)重量:50g(克)
※產品特色
(1)LCD 1602 Keypad Shield 輸入輸出擴展板使用2行的16字符液晶,
(2)具有對比度調節和背光燈,使用1個模擬接口便完成5個按鍵的輸入,
1個複位按鍵,未使用的IO口都擴展出來備用,充分利用IO口。
(3)占用數字端口:PIN4(DB4),5(DB5),6(DB6),7(DB7),8(RS),9(E),
10(背光控制),模擬按鍵端口A0。可與Arduino UNO 完美配合使用。
※模組調試:
(1)將LCD Keypad Shield插接到Arduino UNO 主控板上,
(2)請Google爬文下載LCD4Bit_mod.h程式庫文件到您的Arduino IDE 的libraries位置中
(3)編譯下面的一個測試程序再下載到Arduino中,初次使用LCD Keypad Shield
(4)先觀察LCD有沒有顯示字符,如果沒有顯示字符那可能是對比度不正確,可以使用一字
起子調節RP1(藍色可變電阻順時針旋轉),調到出現清晰地字符即可。
※測試源碼如下(Arduino Code)
//example use of LCD4Bit_mod library
#include <LCD4Bit_mod.h> //create object to control an LCD. //number of lines in display=1 LCD4Bit_mod lcd = LCD4Bit_mod(2);
//Key message char msgs[5][15] = {"Right Key OK ", "Up Key OK ", "Down Key OK ", "Left Key OK ", "Select Key OK" }; int adc_key_val[5] ={30, 150, 360, 535, 760 }; int NUM_KEYS = 5; int adc_key_in; int key=-1; int oldkey=-1;
void setup() { pinMode(13, OUTPUT); //we'll use the debug LED to output a heartbeat
lcd.init(); //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init() //lcd.commandWrite(0x0F);//cursor on, display on, blink on. (nasty!) lcd.clear(); lcd.printIn("KEYPAD testing... pressing"); }
void loop() {
adc_key_in = analogRead(0); // read the value from the sensor digitalWrite(13, HIGH); key = get_key(adc_key_in); // convert into key press if (key != oldkey) // if keypress is detected { delay(50); // wait for debounce time adc_key_in = analogRead(0); // read the value from the sensor key = get_key(adc_key_in); // convert into key press if (key != oldkey) { oldkey = key; if (key >=0){ lcd.cursorTo(2, 0); //line=2, x=0 lcd.printIn(msgs[key]); } } } //delay(1000); digitalWrite(13, LOW);
}
// Convert ADC value to key number int get_key(unsigned int input) { int k; for (k = 0; k < NUM_KEYS; k++) { if (input < adc_key_val[k]) { return k; } } if (k >= NUM_KEYS) k = -1; // No valid key pressed return k; } |