2021-07-10 arduino 用于矩阵键盘的 开源库函数 keypad.h使用说明

先实例化一个键盘:
确定行引脚
确定列引脚

const byte rows = 4; //4行
const byte cols = 4; //4列
char keys[rows][cols] = {
  {'1','2','3','A'},
  {'4','5','6','K'},
  {'7','8','9','M'},
  {'#','0','*','O'}
};
byte rowPins[rows] = {5, 4, 3, 2}; //连接到行的引脚connect to the row pinouts of the keypad
byte colPins[cols] = {8, 7, 6}; //连接到列的引脚connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );//构建库函数,参数是制作键盘矩阵地图,行引脚,列引脚,行数,列数)

库函数

初始化并使硬件键盘产生映射(键盘地图 keys[rows][cols])
void begin(make Keymap(userKeymap))
请参见文件->示例->键盘->示例-> CustomKeypad

接受按键返回值
char getKey()

返回按键的状态(4个)
空闲,按下,释放,保持
KeyState getState()

按键状态的切换
boolean keyStateChanged()

设置用户必须按住按钮直到触发HOLD状态的毫秒数。
setHoldTime(unsigned int time)

设置延迟时间来实现键盘软件防抖动
setDebounceTime(unsigned int time)

增加键盘监听事件
addEventListener(keypadEvent)
监听键盘是按下,释放,还是保持?
详见下面具体示例2。

具体例子说明

接受键入示例:

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'0','1','2','3'},
  {'4','5','6','7'},
  {'8','9','A','B'},
  {'C','D','E','F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //例化键盘,例化名为customKeypad, 矩阵
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值