如何使用中断将消息写入LCD屏幕

步骤1:连接lcd屏幕
首先,我们将连接lcd显示。
lcd屏幕使用arduino上的6个引脚板。首先,将lcd显示屏的两个外部引脚以及引脚5都接地。接下来,将引脚2和倒数第二个引脚连接到5v。
下一步,使用以下映射连接这些引脚:
lcd 4 =》 arduino 7
lcd 6 =》 arduino 8
lcd 11 =》 arduino 9
lcd 12 =》 arduino 10
lcd 13 =》 arduino 11
lcd 14 =》 arduino 12
就是lcd显示器了!
步骤2:连接电位计
下一步使用基本电位器。电位器的中间引脚连接到lcd显示屏上的引脚3。电位器的左侧引脚为5v,而右侧引脚接地。
在此之后,又有一块硬件,然后我们继续进行代码操作。
第3步:添加按钮
现在已经连接了带有电位计的lcd显示屏,我们需要一个按钮来引起硬件中断。将arduino上的引脚2连接到按钮的一侧,使另一侧的电路继续接地。在与地面相同的一侧,将另一个引脚连接到5v。
这完成了硬件设置。
步骤4:实现代码
我已经上载了用于该项目的代码,因此您可以根据需要为您的电路板或您要执行的操作对其进行修改。
关于在arduino uno上实现硬件中断的注意事项是您必须使用引脚2或3,因为这是唯一可用于中断的引脚。除此之外,如果需要,可以更改其他大多数引脚。
另一个警告是,为了使这种类型的设置正常工作,您需要使用millis()方法来实现延迟,因为它在后台工作,所以不同于delay()方法,该方法暂停cpu并实际上使用cpu周期,即使它看起来处于静止状态也是如此。 millis()使用arduino的内置硬件计时器之一完成工作,因此它在后台运行,并且在主循环期间不会停止cpu。
下面是代码:
#include
// initialize the library with the numbers of the interface pins
liquidcrystal lcd(7, 8, 9, 10, 11, 12);
const int buttonpin = 2; // button pin
volatile bool buttonpressed = false; // gauge if the button is pressed
int wait = 500; // ms to wait between messages
int messagewait = 3000; // ms to display an interrupt message
unsigned long current = 0; // holds current timestamp
void setup()
{
serial.begin(9600); // for debugging, remove if you want
pinmode( buttonpin, input_pullup ); // setup for hardware interrupt
// [interrupt, method used, when to call]
attachinterrupt( digitalpintointerrupt( buttonpin ), showmessage, rising );
lcd.begin(16, 2); // set up the lcd‘s number of columns and rows:
lcd.print(“timer:”); // print on the top line
current = millis(); // set up the current time
} // setup
void loop()
{
if( buttonpressed )
{
delay( 3000 ); // put this in the main loop to stop
// the message from being erased
buttonpressed = false; // after the delay, continue the loop
lcd.setcursor(0, 1); // set the cursor to char 0 on line 1
lcd.print( “ ” ); // clear the display
}
else if( millis() 》 current + wait )
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setcursor(0, 1); // set the cursor to char 0 on line 1
lcd.print( (string) ( millis() / (float) 1000 ) ); // output sec passed
current = millis(); // set current time
} // if.。.else if
} // loop
void showmessage()
{
string message = “intrpt: ” + (string) millis();
lcd.setcursor(0, 1); // set the cursor to char 0 on line 1
lcd.print( “intrpt: ” + (string) ( millis() / (float) 1000 ) ); // output interrupt
buttonpressed = true; // indicate button was pressed.
// handle the button press in
// the main loop.
serial.println(“=================================”); // debug
serial.println( message ); // debug
} // showmessage
现在您可以使用中断了,做点很酷的事情!

根系分析系统介绍
支持1000条中英文指令语音识别芯片GM11A550
InfoComm展:互动式触摸屏走对了路
应答机器人可通过导航系统传达实时灾情
当酷睿i9-9900K使用47WTDP的散热器时会怎样 开机瞬间就升温到100度左右
如何使用中断将消息写入LCD屏幕
数控系统故障诊断方法解析
家里WiFi信号弱怎么办?7招教你完美解决信号弱的问题!
共漏极放大电路
单片机的优缺点和应用领域 单片机的硬件特征
解析扇入型封装和扇出型封装的区别
智能化无人装备能给我们带来什么
AD9857在DVB-T调制器系统中的应用
自动驾驶的主流玩家究竟有哪些
人机界面设计用什么软件_人机界面通常包括哪些设备
一文读懂人工智能CLDNN网络结构
OPPO即将发布新机会冠以Reno2,配备后置四摄像头搭+载骁龙730
罗德与施瓦茨公司庆祝成立75周年,公司元老回忆发展历程
高颜值的蓝牙耳机有哪些?适合学生党的蓝牙耳机
值得关注的20家模拟IC初创企业