STM32HAL library study notes (3) - button control

Preface: see page views increase, was very happy, and is also a lovely small partners concerned, I am very grateful, so resolutely and then update a busy schedule, I hope that we can support.

First, the development board Introduction

1. First development board with you about my own use, because I think it is very good, so we recommend it, talk about its pros and cons
Here Insert Picture Description
this is Winnie the school boards, and the use for a long time, some dirty, I have the advantage of local box out, first of all it is the key, this key unlike other development board, Da Dada press down the ring, just like home air conditioning remote control buttons feel the same, still very comfortable, followed by LDC display with a resolution of 240 * 240, high, to be honest, show a picture really clear, then it is the case of sensor expansion interface, the Cubs sent provided some good integrated sensor expansion board cases, such as agriculture wisdom wisdom logistics, use is also very convenient, do not pick a mess of DuPont line, the most important is that it can through the communication interface network, network mode on the right there are several, 2G, NB, WIFI, etc., after the network docking with Huawei's cloud platform , receive real-time data expansion board, or the great, the most important is my most treasured its communication module, I have been studies, follow-up will be with you Explain. This development board it, if we are interested can go to Taobao " Winnie the open source community school " look. Well, ado, into the topic.

Second, the button configuration

  1. You can configure the LDE method in accordance with the previous period do it again, if the period of the LED projects we also saved, then you can open ** "CubeMX" **
    Here Insert Picture Description

直接点击这个工程就能进入配置程序了。如果没有保存呢,就按照LED的方法重新进行配置,中间需要添加以下几个地方,其他的都不变。
Here Insert Picture Description
Here Insert Picture Description
这里呢,选择PB2和PB3,小熊派的两个按键的端口就是PB2和PB3,选中之后呢,要选择 GPIO_Input,按键和LED是相反的,LED是输出一个高低电平,按键呢就是输入一个高低电平
Here Insert Picture DescriptionHere Insert Picture Description
3.添加完之后呢,也要像LED一样,设置以下宏定义,这样更方便进入工程的时候查看代码
Here Insert Picture Description
4.最后工程配置好了之后直接打开, 查看代码
Here Insert Picture Description
大家可以看到,这是KEY的配置文件,跟LED有明显的区别,刚入门的小伙伴可以细细斟酌
Here Insert Picture Description
这里呢,控制按键的代码跟LED是相反的,LED是给它写一个数据,0或者1,按键是读取它的数据,0或者1,所以LED用的是Write,按键是Read;代码中注释消抖的延时函数我这边不做解释,大家可以尝试一下没有那个延时之后的效果,相信大家做了之后就会明白了。
这段代码是用按键控制LED的亮灭,大家也可以随意调用这些函数做一些有意思的实验。

最后呢给大家一个建议,每次配置完一个工程之后呢先拷贝出来一个,所有的调试都在拷贝工程上完成,这样就算工程出错了还有个工程可以用,凡事都做两手打算嘛,好了,大家如果还有其他的问题可以在下面留言,想要获取更多的资料视频的可以关注“小熊派开源社区”公众号,好了,本期分享就到这里了,大家下期见。

发布了3 篇原创文章 · 获赞 5 · 访问量 510

Guess you like

Origin blog.csdn.net/XT_666/article/details/104050635