Difference between revisions of "Matrix - Button"

From FriendlyELEC WiKi
Jump to: navigation, search
(特性)
(使用方法)
Line 10: Line 10:
 
* 2.54mm spacing pin
 
* 2.54mm spacing pin
  
==使用方法==
+
==How To==
===连接===
+
===Connection===
*连接到Tiny4412 SDK (1506)
+
*Connect to Tiny4412 SDK (1506)
::将配件S针脚连接到GPIO PIN1, V接5V,G接地
+
::Connect the module's pin S to GPIO PIN1, pin V to 5V and pin G grounded
  
===Linux下的C示例===
+
===Code Sample in C Under Linux===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
#include <stdio.h>
 
#include <stdio.h>
Line 52: Line 52:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===编译并运行示例===
+
===Compile and Run===
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone http://github.com/friendlyarm/fa-hardware.git
 
git clone http://github.com/friendlyarm/fa-hardware.git
Line 60: Line 60:
 
make
 
make
 
</syntaxhighlight>
 
</syntaxhighlight>
将编译生成的button通过ftp上传到开发板上运行即可测试。
+
Copy your compiled bin to your board and you are ready to go.
  
 
==相关资料==
 
==相关资料==

Revision as of 07:07, 7 August 2015

查看中文

1 Introduction

按键

The Matrix-Button is an instant(non self-lock) button. The button's status can be read from pin S in the 3-pin 2.54 mm spacing pin header. If the button is not pressed S will output high otherwise S will output low.

2 Features

  • Instant, non self-lock
  • Tiny, easy to be used in various situations
  • 2.54mm spacing pin

3 How To

3.1 Connection

  • Connect to Tiny4412 SDK (1506)
Connect the module's pin S to GPIO PIN1, pin V to 5V and pin G grounded

3.2 Code Sample in C Under Linux

#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 Compile and Run

git clone http://github.com/friendlyarm/fa-hardware.git
cd fa-hardware
cd demo
cd matrix-button
make

Copy your compiled bin to your board and you are ready to go.

4 相关资料