|
楼主 |
发表于 2020-2-28 15:18:46
|
显示全部楼层
程序之二:矩阵键盘部分测试每个按键的按下与松开
- /*
- 【Arduino】168种传感器模块系列实验(资料+代码+图形+仿真)
- 实验一百四十:YL-004老款20按键独立键盘 跑马灯矩阵键盘模块
- 程序之二:矩阵键盘部分测试每个按键的按下与松开
- */
- #include "Adafruit_Keypad.h"
- const byte ROWS = 4; // 行
- const byte COLS = 4; // 列
- //定义键盘按钮上的符号
- char hexaKeys[ROWS][COLS] = {
- {'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}
- };
- byte rowPins[ROWS] = {2, 3, 4, 5}; //连接到键盘的行插脚
- byte colPins[COLS] = {6, 7, 8, 9}; //连接到键盘的列插脚
- //初始化类NewKeypad的实例
- Adafruit_Keypad customKeypad = Adafruit_Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void setup() {
- Serial.begin(9600);
- customKeypad.begin();
- }
- void loop() {
- //把你的主代码放在这里,重复运行
- customKeypad.tick();
- while (customKeypad.available()) {
- keypadEvent e = customKeypad.read();
- Serial.print((char)e.bit.KEY);
- if (e.bit.EVENT == KEY_JUST_PRESSED) Serial.println(" pressed");
- else if (e.bit.EVENT == KEY_JUST_RELEASED) Serial.println(" released");
- }
- delay(10);
- }
复制代码 |
|