因此,我最终试图建立一个有趣的安全系统使用4x4数字垫,arduino,和一个螺线管。当我试图让数字垫和液晶显示器一起工作的时候,我总是遇到一些我不知道的原因。下面的代码是我到目前为止所掌握的:
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
#include <Keypad.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
//_________________________________________
const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;
char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins [rows] = {1, 2, 3, 4}; //pins of the keypad
byte colPins [cols] = {5, 6, 7, 8};
Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);
//_________________________________________
void setup() {
Serial.begin(9600);
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
}
void loop() {
char key = myKeypad.getKey();
if (key){
Serial.print(key);
lcd.print("key has been pressed!");
delay(2000);
lcd.clear();
}
}然而,我不断地得到随机和破碎的字符,我不明白为什么。有人能帮我吗?
发布于 2020-08-10 05:36:06
您的液晶显示器不显示预期的字符串,因为您是重叠的一个引脚,这是用于另一个任务。
大多数Arduino板上的pin 1被用作串行发射机(Tx)引脚。这个相同的引脚也发生在你的一个引脚到液晶显示器(rs引脚)。这会导致在LCD上出现意想不到的行为和乱七八糟的文本。
//为液晶LiquidCrystal液晶(1、2、4、5、6、7)创建一个LC对象。参数:(rs、enable、d4、d5、d6、d7) . //Pin 1用于串行通信Tx通过端口发送数据。Serial.print(密钥);
要使用Arduino板正确配置LCD显示器,请阅读官方Arduino网站的文档:液晶显示上的HelloWorld
https://stackoverflow.com/questions/63333387
复制相似问题