简体   繁体   English

LCD上显示特殊字符而不是数字 - Arduino

[英]Special characters are displaying on LCD Instead of numbers - Arduino

I want to print the number pressed from the 4x3 matrix keypad to my 20x4 lcd but instead I got aw and arrow as a result.我想将从 4x3 矩阵键盘按下的数字打印到我的 20x4 液晶显示器上,但结果却出现了 aw 和箭头。 The error looks like this.错误看起来像这样。 Here is my code.这是我的代码。

#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//RS,EN,D4,D5,D6,D7

const byte Rows= 4; //number of rows on the keypad i.e. 4
const byte Cols= 3; //number of columns on the keypad i,e, 3

//we will definne the key map as on the key pad:

char keymap[Rows][Cols]={
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rPins[Rows]= {9, 8, 7, 6}; //Rows 0 to 3
byte cPins[Cols]= {5, 4, 3}; //Columns 0 to 2

Keypad kpd= Keypad(makeKeymap(keymap), rPins, cPins, Rows, Cols);

void setup() {
  lcd.begin(20, 4);//initializing LCD
}

void loop() {
  char keypressed = kpd.getKey();
  if (keypressed != NO_KEY) {
    lcd.print(keypressed);
  }
}

Please help me out.请帮帮我。

Your two modules share some of the same pins and that's at the root of the issue:您的两个模块共享一些相同的引脚,这是问题的根源:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);//RS,EN,D4,D5,D6,D7
byte cPins[Cols]= {5, 4, 3}; //Columns 0 to 2

From these declarations, pins 5, 4 and 3 appear to be shared.从这些声明中,引脚 5、4 和 3 似乎是共享的。 All sorts of weird things happen when pins are shared between peripheral devices.当外围设备之间共享引脚时,会发生各种奇怪的事情。 Then when you say that each device seems to work well on its own, without the other... well I'd say the overlapping pins are your culprit.然后,当您说每个设备似乎单独运行良好,而没有其他设备时……好吧,我会说重叠的引脚是您的罪魁祸首。

See if there's a way to remap one or the other devices so as not to have shared pins.看看是否有办法重新映射一个或其他设备,以免共享引脚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM