Arduino Keypads 项目使用教程

Arduino Keypads 项目使用教程

arduino_keypadsarduino libraries for keypad interface on I2C bus项目地址:https://gitcode.com/gh_mirrors/ar/arduino_keypads

1. 项目的目录结构及介绍

目录结构

arduino_keypads/
├── examples/
│   ├── Basic/
│   ├── MultipleKey/
│   ├── Password/
│   └── README.md
├── src/
│   ├── Keypad.cpp
│   └── Keypad.h
├── .gitignore
├── LICENSE
├── README.md
└── library.properties

目录介绍

  • examples/: 包含多个示例项目,展示了如何使用 Keypad 库。
    • Basic/: 基本示例,演示如何检测单个按键。
    • MultipleKey/: 演示如何检测多个按键同时按下。
    • Password/: 演示如何使用按键输入密码。
  • src/: 包含 Keypad 库的核心源文件。
    • Keypad.cpp: Keypad 库的实现文件。
    • Keypad.h: Keypad 库的头文件。
  • .gitignore: Git 忽略文件配置。
  • LICENSE: 项目许可证。
  • README.md: 项目说明文档。
  • library.properties: Arduino 库属性文件,包含库的元数据。

2. 项目的启动文件介绍

启动文件

项目的启动文件通常位于 examples/ 目录下。以 Basic/ 示例为例,启动文件为 Basic.ino

启动文件内容

#include <Keypad.h>

const byte ROWS = 4; // 行数
const byte COLS = 4; // 列数
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; // 行引脚
byte colPins[COLS] = {5, 4, 3, 2}; // 列引脚

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();
  if (key){
    Serial.println(key);
  }
}

启动文件介绍

  • #include <Keypad.h>: 引入 Keypad 库。
  • const byte ROWS = 4;: 定义键盘的行数。
  • const byte COLS = 4;: 定义键盘的列数。
  • char keys[ROWS][COLS]: 定义键盘按键的映射。
  • byte rowPins[ROWS]: 定义行引脚。
  • byte colPins[COLS]: 定义列引脚。
  • Keypad keypad: 创建 Keypad 对象。
  • void setup(): 初始化串口通信。
  • void loop(): 循环检测按键并输出到串口。

3. 项目的配置文件介绍

配置文件

项目的配置文件为 library.properties

配置文件内容

name=Keypad
version=3.1.1
author=Mark Stanley, Alexander Brevig
maintainer=Mark Stanley, Alexander Brevig
sentence=Allows you to connect a keypad to an Arduino and read key presses.
paragraph=This library allows you to connect a keypad to an Arduino and read key presses. It supports multiple keypresses and is based on the Keypad tutorial.
category=Device Control
url=https://github.com/Chris--A/Keypad
architectures=*
includes=Keypad.h

配置文件介绍

  • name: 库的名称。
  • version: 库的版本。
  • author: 库的作者。
  • maintainer: 库的维护者。
  • sentence: 库的简短描述。
  • paragraph: 库的详细描述。
  • category: 库的分类。
  • url: 库的 GitHub 地址。
  • architectures: 支持的架构。

arduino_keypadsarduino libraries for keypad interface on I2C bus项目地址:https://gitcode.com/gh_mirrors/ar/arduino_keypads

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

华情游

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值