2016-02-07 117 views
1

我有一個小問題。我試圖在連接到arduino uno的4x4鍵盤的16x2 LCD屏幕上顯示字符。當我按下鍵盤按鈕時,相應的字符在串行監視器上成功打印,但不是dsplay。 我還應該提到,在查找字符的ASCII表之後,LCD上打印的錯誤字符對應於重複的ASCII字符,即按1鍵打印1111 1111,而另一個鍵可能打印對應於ASCII 1011的字符1011.基本上是從右下角到左上角的ascii表中的字符。另外,當我按下某個鍵時,它會在串行監視器上打印一次,但在LCD上多次打印。 我會在下面發佈我的代碼,並鏈接到我正在使用的鍵盤和LCD屏蔽。當我在顯示屏上打印字符/文字時,最後一個注意事項與鍵盤無關,因此它們打印的很好。16X2 LCD屏蔽與4x4矩陣鍵盤

代碼:

#include <Keypad.h> 
#include <LiquidCrystal.h> // initialize the library with the numbers of the 

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 


const byte ROWS = 4; //four rows 
const byte COLS = 4; //four columns 
char hexaKeys[ROWS][COLS] = { 
{'1','2','3','A'}, 
{'4','5','6','B'}, //define the cymbols on the buttons of the keypads 
{'7','8','9','C'}, 
{'*','0','#','D'} 
}; 
byte rowPins[ROWS] = {13, 12, 11, 10}; //connect to the row pinouts of the   keypad 
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the  keypad 


Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad 

void setup() 
{ 
lcd.begin(16, 2); 
Serial.begin(9600); 
} 

void loop() 
{ 
char customKey = customKeypad.getKey(); 

if (customKey) 
{ 
//lcd.setCursor(1,1); 
lcd.print(customKey); 
delay(500); 
Serial.print(customKey); 
} 
} 

LCD屏蔽: http://www.maplin.co.uk/p/16x2-lcd-shield-for-arduino-n07dh

鍵盤: https://www.coolcomponents.co.uk/sealed-membrane-4-4-button-pad-with-sticker.html

感謝,希望有人可以提供幫助。

+1

我不確定你的問題在這裏。你想問我們什麼? – duskwuff

+0

你是什麼意思?我問是否有人知道爲什麼在LCD上打印錯誤的字符,但在串行監視器上顯示正確的字符... – Davidgasp

回答

0

刪除,如果條件和嘗試。

#include <Keypad.h> 
#include <LiquidCrystal.h> // initialize the library with the numbers of the 

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); 


const byte ROWS = 4; //four rows 
const byte COLS = 4; //four columns 
char hexaKeys[ROWS][COLS] = { 
{'1','2','3','A'}, 
{'4','5','6','B'}, //define the cymbols on the buttons of the keypads 
{'7','8','9','C'}, 
{'*','0','#','D'} 
}; 
byte rowPins[ROWS] = {13, 12, 11, 10}; //connect to the row pinouts of the   keypad 
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the  keypad 


Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad 

void setup() 
{ 
lcd.begin(16, 2); 
Serial.begin(9600); 
} 

void loop() 
{ 
char customKey = customKeypad.getKey(); 
//lcd.setCursor(1,1); 
lcd.print(customKey); 
delay(500); 
Serial.print(customKey); 

}