TA的每日心情 | 开心 2024-10-25 14:50 |
---|
签到天数: 1071 天 连续签到: 1 天 [LV.10]以坛为家III
|
本帖最后由 TLLED 于 2021-7-19 17:12 编辑
测试面板上的5方向按键,TFT-LCD显示按键状态。
一、按键电路图
5方向按键的电路图
二、程序
程序源码:
- #include"TFT_eSPI.h"
- #include"Free_Fonts.h"
- int key_status=1;
- TFT_eSPI tft;
-
- void setup() {
- //串口
- Serial.begin(115200);
- //按键
- pinMode(WIO_5S_UP, INPUT_PULLUP);
- pinMode(WIO_5S_DOWN, INPUT_PULLUP);
- pinMode(WIO_5S_LEFT, INPUT_PULLUP);
- pinMode(WIO_5S_RIGHT, INPUT_PULLUP);
- pinMode(WIO_5S_PRESS, INPUT_PULLUP);
- //TFT
- tft.begin();
- tft.setRotation(3);
- tft.fillScreen(TFT_BLACK);
- tft.setFreeFont(&FreeSansBoldOblique12pt7b);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- if (digitalRead(WIO_5S_UP) == LOW) {
- Serial.println("5 Way Up");
- tft.drawString("WIO_5S_UP KEYUP ",10,80);
- key_status=1;
- }
- else if (digitalRead(WIO_5S_DOWN) == LOW) {
- Serial.println("5 Way Down");
- tft.drawString("WIO_5S_DOWN KEYUP ",10,80);
- key_status=1;
- }
- else if (digitalRead(WIO_5S_LEFT) == LOW) {
- Serial.println("5 Way Left");
- tft.drawString("WIO_5S_LEFT KEYUP ",10,80);
- key_status=1;
- }
- else if (digitalRead(WIO_5S_RIGHT) == LOW) {
- Serial.println("5 Way Right");
- tft.drawString("WIO_5S_RIGHT KEYUP ",10,80);
- key_status=1;
- }
- else if (digitalRead(WIO_5S_PRESS) == LOW) {
- Serial.println("5 Way Press");
- tft.drawString("WIO_5S_PRESS KEYUP ",10,80);
- key_status=1;
- }
- else{
- if(key_status==1)
- {
- key_status=0;
- tft.drawString("WIO_5S_UP NO KEYUP ",10,80);
- }
- }
- delay(200);
- }
复制代码
三、程序运行
3.1、串口输出按键状态
3.2、显示屏显示按键状态
|
|