首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >16X2 LCD屏蔽板,带4x4矩阵键盘

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

Stack Overflow用户
提问于 2016-02-07 12:26:50
回答 1查看 1.1K关注 0票数 1

我有个小问题。我正在尝试使用连接到arduino uno的4x4键盘在我的16x2 LCD屏蔽板上显示字符。当我按下键盘按钮时,相应的字符在串行监视器上打印成功,但在显示器上打印失败。我还应该提到,在查找字符的ASCII表后,LCD上打印的错误字符对应于重复的ASCII字符,即按1键打印1111 1111,而另一个键可能打印对应于ASCII 1011 1011的字符。基本上,ascii表中的字符从右下角到左上角。此外,当我按下一个键时,它在串行监视器上打印一次,但在LCD上打印多次。我将在下面发布我的代码,以及我正在使用的键盘和液晶屏的链接。最后,当我在显示器上打印字符/单词时,与键盘无关,它们打印正常。

代码:

代码语言:javascript
复制
#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);
}
}

液晶屏: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

谢谢,希望有人能帮上忙。

EN

回答 1

Stack Overflow用户

发布于 2016-03-11 13:06:53

删除if条件,然后重试。

代码语言:javascript
复制
#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);

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35249727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档