Difference between revisions of "Matrix - Button"
From FriendlyELEC WiKi
Line 1: | Line 1: | ||
[[Matrix - Button/zh|查看中文]] | [[Matrix - Button/zh|查看中文]] | ||
− | [[File: | + | ==介绍== |
+ | [[File:Btn01.jpg|thumb|按键]] | ||
+ | 该按键在未按时输出高电平,按下后输出低电平。 | ||
− | + | ==特性== | |
− | + | * 使用标准的3 PIN接口 | |
− | + | * 尺寸为 8x24mm | |
+ | ==使用方法== | ||
+ | ===连接=== | ||
+ | *连接到Tiny4412 SDK (1506) | ||
+ | ::将配件S针脚连接到GPIO PIN1, V接5V,G接地 | ||
− | + | ===Linux下的C示例=== | |
+ | <syntaxhighlight lang="c"> | ||
+ | #include <stdio.h> | ||
+ | #include "libfahw.h" | ||
− | + | static struct sensor button[] = { | |
+ | { | ||
+ | TINY4412_GPIO_PIN1, | ||
+ | IRQ_TYPE_EDGE_FALLING, | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | int i; | ||
+ | int retSize = -1; | ||
+ | char value[ARRAY_SIZE(button)]; | ||
+ | int devFD = -1; | ||
+ | if ((devFD =sensorInit(button, ARRAY_SIZE(button))) == -1) { | ||
+ | printf("Fail to init sensor\n"); | ||
+ | return -1; | ||
+ | } | ||
+ | printf("Press the button...\n"); | ||
+ | if (( retSize = sensorRead(devFD, value, ARRAY_SIZE(button)) ) == -1) { | ||
+ | printf("Fail to read sensors\n"); | ||
+ | } | ||
+ | if (retSize > 0) { | ||
+ | i = 0; | ||
+ | for (i=0; i<retSize; i++) { | ||
+ | printf("Button[%d]:%d\n", i, value[i]); | ||
+ | } | ||
+ | } | ||
+ | sensorDeinit(devFD); | ||
+ | return 0; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ===编译并运行示例=== | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | git clone http://github.com/friendlyarm/fa-hardware.git | ||
+ | cd fa-hardware | ||
+ | cd demo | ||
+ | cd button | ||
+ | make | ||
+ | </syntaxhighlight> | ||
+ | 将编译生成的button通过ftp上传到开发板上运行即可测试。 | ||
+ | |||
+ | ==相关资料== |
Revision as of 05:45, 16 July 2015
Contents
1 介绍
该按键在未按时输出高电平,按下后输出低电平。
2 特性
- 使用标准的3 PIN接口
- 尺寸为 8x24mm
3 使用方法
3.1 连接
- 连接到Tiny4412 SDK (1506)
- 将配件S针脚连接到GPIO PIN1, V接5V,G接地
3.2 Linux下的C示例
#include <stdio.h> #include "libfahw.h" static struct sensor button[] = { { TINY4412_GPIO_PIN1, IRQ_TYPE_EDGE_FALLING, } }; int main(void) { int i; int retSize = -1; char value[ARRAY_SIZE(button)]; int devFD = -1; if ((devFD =sensorInit(button, ARRAY_SIZE(button))) == -1) { printf("Fail to init sensor\n"); return -1; } printf("Press the button...\n"); if (( retSize = sensorRead(devFD, value, ARRAY_SIZE(button)) ) == -1) { printf("Fail to read sensors\n"); } if (retSize > 0) { i = 0; for (i=0; i<retSize; i++) { printf("Button[%d]:%d\n", i, value[i]); } } sensorDeinit(devFD); return 0; }
3.3 编译并运行示例
git clone http://github.com/friendlyarm/fa-hardware.git cd fa-hardware cd demo cd button make
将编译生成的button通过ftp上传到开发板上运行即可测试。