實驗7 按鍵單模組實驗

2021-10-06 23:13:49 字數 1546 閱讀 4724

用esp32和按鍵模組,通過矩陣法來實現對矩陣鍵盤的按鍵讀取

1.連線esp32和按鍵模組的引腳

2.觸控按鍵,esp32獲取到所觸控的按鍵數字,並列印到串列埠監視器中

1.esp32-wroom-32d 開發板

2.3*4按鍵模組

3.杜邦線

1) 連線引腳

3*4矩陣鍵盤

引腳依次為: 7 6 5 4 3 2 1(從左往右)

esp32

esp32的引腳圖:

連線

2) 環境配置

1.開啟arduino ide,選擇左上角 工具–開發板,選擇對應的開發板(esp32 dev module)

2.選擇 工具–埠 , 選擇對應的埠

3) 測試**
/* @file hellokeypad.pde

|| @version 1.0

|| @author alexander brevig

|| @contact [email protected]

|||| @description

|| | demonstrates the ******st use of the matrix keypad library.

|| #

*/#include

const byte rows=4

;//four rows

const byte cols=3

;//three columns

char keys[

rows][

cols]=

,,,}

;byte rowpins[

rows]=

;//connect to the row pinouts of the keypad

byte colpins[

cols]=

;//connect to the column pinouts of the keypad

keypad keypad =

keypad

(makekeymap

(keys)

, rowpins, colpins,

rows

,cols);

void

setup()

void

loop()

}

4) 測試結果

​ 按鍵上的按鈕為0-9,*和#。按過一次相應按鈕,會在串列埠顯示器上顯示相應數字。

實驗3 按鍵輸入實驗

一 原理圖 二 庫函式 1 讀取io的狀態 uint8 t gpio readinputdatabit gpio typedef gpiox,uint16 t gpio pin 引數 gpio pin gpio pin x x 0 15 返回值 讀取到的狀態 0表示按鍵按下 1表示按鍵沒有按下。三 ...

1 按鍵實驗

1 思路 通過設定相應的埠為輸入模式,再通過while語句來迴圈讀取按鍵值,如果按鍵有按下,則做出響應,控制led燈的亮與滅。2 過程 在建立的工程檔案hardware子資料夾中新增乙個檔名為key的資料夾,在裡面新建好key.c,key.h兩個檔案。之後就再新增到工程中,剛開始的時候找不到key....

按鍵輸入實驗

1.硬體接法 4個按鍵 wk up 控制蜂鳴器,key0 同時控制ds0和ds1 key1 控制ds1 key2控制ds0,wk up 外部上拉,晶元內部需要設定為下拉輸入 key0 key2 外部下拉,晶元內部需要設定為上拉輸入。2.標頭檔案編寫 本次實驗涉及到led 蜂鳴器 按鍵,其中led和蜂...