3*4 keypad 如何做出 完成輸入鍵
小弟近日接了一個3*4的keypad 想利用此鍵盤來修改程式裡pwm輸出的功率http://www.arduino.cn/data/attachment/forum/201507/23/123355pt8xsz32hsssqt2z.jpg
現在遇到的問題是:
當我輸入數值後,我希望能按下#來完成輸入
現階段鍵盤只要輸入一個數,LCD就會馬上顯示出來
那麼我設定的代碼 ex. char keyin = keypad.getKey();
keyin 之值 永遠只會是個位數,無法是90、100
想請問各位大大,有些甚麼建議呢?
目前所用的程式碼如下
#include <LiquidCrystal.h>
#include <Keypad.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// 3x4 Keypad
const byte ROWS = 4; // 4 Rows
const byte COLS = 3; // 3 Columns
// 定義 Keypad 的按鍵
char keys = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// 定義 Keypad 連到 Arduino 的接腳
byte rowPins = {32, 22, 24, 28}; // 連到 Keypad 的 4 個 Rows: Row0, Row1, Row2, Row3
byte colPins = {30, 34, 26}; // 連到 Keypad 的 3 個 Columns: Column0, Column1, Column2
// 建立 Keypad 物件
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
// 讀取 Keypad 的輸入
char key = keypad.getKey();
// NO_KEY 代表沒有按鍵被按下
if (key != NO_KEY){
// 假如有按鍵被按下,就印出按鍵對應的字元
Serial.println(key);
lcd.print(key);
}
}
先用一個 char[] 作 buffer, 把收到的 key 先記下.
直到接收到 "#" 的 key 就把已記下的一次過輸出並同時清空.
页:
[1]