作者: acw@home 時間: 2009-8-26 01:13 標題: 新手 Arduino + DFRobot LCD Keypad Shield
Arduino 團購中買了 DFRobot LCD Keypad Shield, 取貨後即試玩. 但沒有跟原理圖, 只好上網找.
DFRobot website 只說 LCD 用了 digital PIN 4, 5, 6, 7, 8, 9 和 Keypad 用了 analog PIN A0. 經再三找尋, 終於有以下設定:
- LCD Arduino
- ---------------
- RS 8
- Enable 9
- D4 4
- D5 5
- D6 6
- D7 7
- /* LCD Keypad Shield
- Author: acw@home
- Aug 25, 2009
-
- LCD PIN assignment:
- LCD Arduino
- -------------------
- RS 8
- ENABLE 9
- D4 4
- D5 5
- D6 6
- D7 7
- Keypad PIN = A0
- */
- #include <LiquidCrystal.h>
- // analog PIN A0
- #define KEY_PIN 0
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- int key;
- int last_key = -1; // save the last key pressed
- void setup()
- {
- lcd.begin(16, 2);
- lcd.print("Press any key");
- }
- void loop()
- {
- key = analogRead(KEY_PIN);
- if (key != last_key) {
- lcd.setCursor(0, 1);
- lcd.print(key);
- lcd.print(" ");
- last_key = key;
- }
- }
- Key Value
- --------------
- RIGHT 0
- UP 145
- DOWN 329
- LEFT 504
- SELECT 739
- <NONE> 1023
- /* LCD Keypad Shield
- Author: acw@home
- Aug 25, 2009
-
- LCD PIN assignment:
- LCD Arduino
- -------------------
- RS 8
- ENABLE 9
- D4 4
- D5 5
- D6 6
- D7 7
- Keypad PIN = A0
- Key pressed A0 Reading
- --------------------------------
- RIGHT 0
- UP 145
- DOWN 329
- LEFT 504
- SELECT 739
- <NONE> 1023
- */
- #include <LiquidCrystal.h>
- enum {
- KEY_RIGHT,
- KEY_UP,
- KEY_DOWN,
- KEY_LEFT,
- KEY_SELECT,
- NUM_KEYS
- };
- #define LED_PIN 13
- #define KEY_PIN 0
- #define KEY_NONE 1020
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- int key_val[]= { 140, 320, 500, 730, KEY_NONE };
- char *key_name[] = { "right", "up", "down", "left", "select" };
- int key;
- int last_key; // save the last key pressed
- void setup()
- {
- lcd.begin(16, 2);
- lcd.print("Press any key");
- last_key = KEY_NONE;
- }
- int readKey(int pin)
- {
- int n, key_in;
-
- n = analogRead(KEY_PIN);
- if (n < KEY_NONE) {
- // a key is pressed
- digitalWrite(LED_PIN, HIGH); // turn on LED
- // show the A0 reading
- lcd.setCursor(0, 0);
- lcd.print("Value: ");
- lcd.print(n);
- lcd.print(" ");
- // wait for the key being released
- do {
- key_in = n;
- n = analogRead(KEY_PIN);
- } while (n < KEY_NONE);
- digitalWrite(LED_PIN, LOW); // turn off LED
- // decode the key
- for (int i=KEY_RIGHT; i<NUM_KEYS; ++i) {
- if (key_in < key_val[i]) {
- return i;
- }
- }
- }
- return KEY_NONE;
- }
- void loop()
- {
- key = readKey(KEY_PIN);
- if (key != KEY_NONE && key != last_key) {
- lcd.setCursor(0, 1);
- lcd.print("Key : ");
- lcd.print(key_name[key]);
- lcd.print(" ");
- last_key = key;
- }
- }
https://www.hkepc.com/forum/attachment.php?aid=933479&k=7e6878c65a13b6700e3686298573ffeb&t=1790479791&sid=G3xBEqqZ8r

作者: avdaemon 時間: 2009-8-26 10:14
知不知道團購還有沒有過剩物品出售?
作者: acw@home 時間: 2009-8-26 11:18
你最好直接 PM 團長問, 但現在有團友仍未能取貨
作者: tobyho91 時間: 2009-8-27 16:19
點解我照COPY你D CODE,但隻野冇反應既
作者: acw@home 時間: 2009-8-28 00:31
你的 LCD Keypad Shield 是否團購的?
因不同版本, PIN assignment 可能不同.
另你話'隻野冇反應既', 係指冇顯示定keypad冇反應?
我的程式執行中, 若你按下any key, Arduino 上的 red led 會 turn on 的.
[ 本帖最後由 acw@home 於 2009-8-28 00:36 編輯 ]
作者: victorchuk622 時間: 2009-8-28 00:32 標題: 回覆 2# 的帖子
try try pm holder, u may have surprise
[ 本帖最後由 victorchuk622 於 2009-8-28 00:33 編輯 ]
作者: tobyho91 時間: 2009-8-29 01:57
原帖由 acw@home 於 2009-8-28 00:31 發表
你的 LCD Keypad Shield 是否團購的?
因不同版本, PIN assignment 可能不同.
另你話'隻野冇反應既', 係指冇顯示定keypad冇反應?
我的程式執行中, 若你按下any key, Arduino 上的 red led 會 turn on 的.
係呀.團購個堆囉..
我就係UPLOAD左..PRESS ANY KEY都冇反應
作者: acw@home 時間: 2009-8-29 14:14
1) Are you using Arduino IDE version 0017?
2) Please check whether you have properly connected the LCD Keypad Shield to Arduino. And the power LED and the backlight of the LCD should be on after the Arduino is connected to PC via USB cable no matter whether there is application or not.
3) Also, in order to check whether your Arduino is working or not, just upload the 'Blink' example and see whether the RED LED (labeled 'L' between 'R7' and 'R5', near digital PIN 13) on the Arduino is flashing.
[ 本帖最後由 acw@home 於 2009-8-29 14:18 編輯 ]
作者: bchan 時間: 2009-9-2 03:31
i have connected the shield and uploaded the code.
it works
作者: Joe_Black 時間: 2009-9-2 10:34
提示: 作者被禁止或刪除 內容自動屏蔽
作者: bchan 時間: 2009-9-3 12:56
加左lcd shield, 你地點駁其他野?
佢未用哂d pin但又駁唔到其他野。
響中間加其他shield?
作者: acw@home 時間: 2009-9-3 13:29
See dulllou's 'Arduino LCD Keypad shield小改善':
http://global.hkepc.com/forum/viewthread.php?tid=1249168
作者: bchan 時間: 2009-9-3 20:08
原帖由 acw@home 於 2009-9-3 13:29 發表
See dulllou's 'Arduino LCD Keypad shield小改善':
http://global.hkepc.com/forum/viewthread.php?tid=1249168
正
一個咁正ge post點解無人re?


