首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >液晶显示屏显示随机字符

液晶显示屏显示随机字符
EN

Stack Overflow用户
提问于 2020-08-10 02:34:47
回答 1查看 1.3K关注 0票数 0

因此,我最终试图建立一个有趣的安全系统使用4x4数字垫,arduino,和一个螺线管。当我试图让数字垫和液晶显示器一起工作的时候,我总是遇到一些我不知道的原因。下面的代码是我到目前为止所掌握的:

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

然而,我不断地得到随机和破碎的字符,我不明白为什么。有人能帮我吗?

在这里输入图像描述

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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

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

https://stackoverflow.com/questions/63333387

复制
相关文章

相似问题

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