【Arduino】1.6 串口的使用
2016-08-04 18:02
309 查看
4*4 矩阵键盘,可以作为简单的控制器输入,能用于复杂的arduino控制。本文主要介绍如何驱动4*4矩阵键盘。
材料
4*4矩阵键盘
Arduino Uno 1块
8P线
双排针或排针
这里简单介绍一种矩阵键盘的工作原理,4*4矩阵键盘有8个引脚,4个一组,分别对应行和列,通过按键扫描的方法,对不同行(列)分别输入高低电平,然后读取不同列(行)上的电平,从而知道键盘上的某一按键按下。
例如,当第1行输出低电平,其他行输出高电平,分别读取依次列上的状态,如果第1列为低,结果为(1,1),按键为1,如果第2列为低,则结果为(1,2)按键为2
安装4*4矩阵键盘
4*4矩阵键盘有一个8孔的排母,理论上可以直接插到0-7脚上,但0,1脚用于串口通信,所以只能选择2~13脚,这里选用了2-9脚。
首先,选取一个16 PIN 的双排针,将双排针长的那一排的一面引脚插到键盘排母里
另一面插8P线,8P线另一头按键盘正面从左到右的顺序,线接2
PIN排针,再接5 PIN排针,
2 PIN 的排针插到Arduino的8,9脚,5
PIN 的排针插到2~5脚
总的硬件电路
DSC_0560.jpg (42.41 KB, 下载次数: 307)
下载附件
2013-7-30 13:15 上传
定义Arduino IO口
byte rowPins[ROWS] = {9, 8, 7, 6}; //连接到行数字小键盘的管脚
byte colPins[COLS] = {5, 4, 3, 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] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
}
}
测试可用
库下载地址
原文地址
材料
4*4矩阵键盘
Arduino Uno 1块
8P线
双排针或排针
这里简单介绍一种矩阵键盘的工作原理,4*4矩阵键盘有8个引脚,4个一组,分别对应行和列,通过按键扫描的方法,对不同行(列)分别输入高低电平,然后读取不同列(行)上的电平,从而知道键盘上的某一按键按下。
例如,当第1行输出低电平,其他行输出高电平,分别读取依次列上的状态,如果第1列为低,结果为(1,1),按键为1,如果第2列为低,则结果为(1,2)按键为2
安装4*4矩阵键盘
4*4矩阵键盘有一个8孔的排母,理论上可以直接插到0-7脚上,但0,1脚用于串口通信,所以只能选择2~13脚,这里选用了2-9脚。
首先,选取一个16 PIN 的双排针,将双排针长的那一排的一面引脚插到键盘排母里
另一面插8P线,8P线另一头按键盘正面从左到右的顺序,线接2
PIN排针,再接5 PIN排针,
2 PIN 的排针插到Arduino的8,9脚,5
PIN 的排针插到2~5脚
总的硬件电路
DSC_0560.jpg (42.41 KB, 下载次数: 307)
下载附件
2013-7-30 13:15 上传
定义Arduino IO口
byte rowPins[ROWS] = {9, 8, 7, 6}; //连接到行数字小键盘的管脚
byte colPins[COLS] = {5, 4, 3, 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] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(9600);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
}
}
测试可用
库下载地址
原文地址
相关文章推荐
- [笔记]Arduino平台使用US-100超声波测距模块的串口模式测温实验
- Arduino串口的使用
- Arduino初初教程6(串口的使用)
- Arduino初初教程6——串口的使用
- Serial的基本使用和ArduinoIDE的串口工具——人人都能玩硬件
- 【Arduino】1.5 串口的使用
- 使用Win32 API函数实现vc和arduino简单串口通信
- 【Arduino官方教程第一辑】示例程序 4-9 串口双向调用(使用ASCII字符串)
- Arduino--基础(六)--串口的使用
- arduino串口使用print还是write?
- [笔记]Arduino平台使用US-100超声波测距模块的串口模式测距实验
- Eclipse编译Arduino程序不能使用串口函数Serial.begin解决办法
- 使用串口连接Arduino与树莓派开发板
- Arduino串口的使用
- VB使用API实现串口通讯的异常问题
- [转]如何使用串口控件MSComm在dotNet下编程
- 在KEIL C51中使用串口的重要注意事项
- 如何使用串口控件MSComm在dotNet下编程
- 串口调试程序软件GraphdCommDebugger V1.0 与使用手册
- 使用Java读取串口的程序