16X2 LCD屏蔽,带4x4矩阵键盘

时间:2016-02-07 04:26:50

标签: c arduino serial-port arduino-uno

我有一个小问题。我试图在我的16x2 LCD屏蔽上显示字符,其中4x4键盘连接到arduino uno。当我按下键盘按钮时,相应的字符在串行监视器上成功打印,但不能在dsplay上打印。 我还要提一下,在查找ASCII表格中的字符后,LCD上打印的错误字符对应重复的ASCII字符,即按1键打印1111 1111,另一个键可以打印与ASCII 1011 1011对应的字符基本上是从右下角到左上角的ascii表中的字符。此外,当我按下一个键时,它会在串行监视器上打印ONCE,但在LCD上多次打印。 我将在下面发布我的代码以及我正在使用的键盘和LCD屏蔽的链接。最后一点,当我在显示屏上打印字符/文字与键盘无关时,它们打印得很好。

代码:

#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 个答案:

答案 0 :(得分: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);

}