Difference between revisions of "Matrix - Joystick"

From FriendlyELEC WiKi
Jump to: navigation, search
(特性)
(使用方法)
Line 9: Line 9:
 
* 2.54mm spacing pin
 
* 2.54mm spacing pin
  
==使用方法==
+
==How To==
===连接===
+
===Connection===
*连接到Tiny4412 SDK (1506)
+
*Connect to Tiny4412 SDK (1506)
::1) 需要Tiny4412 SDK先连接[[Matrix - Analog to Digital Converter]]配件
+
::1) Please connect the Tiny4412 SDK to [[Matrix - Analog to Digital Converter]]
::2) 然后,Joystick与[[Matrix - Analog to Digital Converter]]配件相连接:
+
::2) Please connect the Joystick to [[Matrix - Analog to Digital Converter]]:
::::GND针脚接地
+
::::GND to ground
::::V针脚接5V
+
::::V to 5V
::::VRX针脚连接Analog to Digital Converter的AIN0针脚
+
::::VRX to Analog to Digital Converter's AIN0
::::VRY针脚连接Analog to Digital Converter的AIN1针脚
+
::::VRY to Analog to Digital Converter's AIN1
::::SW针脚连接Analog to Digital Converter的AIN2针脚
+
::::SW to Analog to Digital Converter's AIN2
  
  
===Linux下的C示例===
+
===Code Sample in C Under Linux===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
#include <stdio.h>
 
#include <stdio.h>
Line 78: Line 78:
 
</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 86: Line 86:
 
make
 
make
 
</syntaxhighlight>
 
</syntaxhighlight>
将编译生成的PS2rocker通过ftp上传到开发板上运行即可测试。
+
Copy your compiled bin to your board and you are ready to go.
  
 
==相关资料==
 
==相关资料==

Revision as of 06:09, 6 August 2015

查看中文

1 Introduction

Joystick

This module consists of two Sliding rheostats and one button. When you move the joystick the sliding rheostats' resistance will change and the corresponding x/y values will change too. When you push the joystick the SW level will turn low.

2 Features

  • two sliding rheostat and one button
  • 2.54mm spacing pin

3 How To

3.1 Connection

  • Connect to Tiny4412 SDK (1506)
1) Please connect the Tiny4412 SDK to Matrix - Analog to Digital Converter
2) Please connect the Joystick to Matrix - Analog to Digital Converter:
GND to ground
V to 5V
VRX to Analog to Digital Converter's AIN0
VRY to Analog to Digital Converter's AIN1
SW to Analog to Digital Converter's AIN2


3.2 Code Sample in C Under Linux

#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include "libfahw.h"
 
#define SW_TRIGGER          (5)
#define PS2_READ_TIMES      (10)
 
static int devFD;
void PS2Handler(int signNum)
{
    if (signNum == SIGINT) {
        printf("Quit reading PS2 rocker\n");
        pcf8591DeInit(devFD);
    }
    exit(0);
}
 
int main(int argc, char ** argv)
{
        int mode = 0x0;
 
        if ((devFD = pcf8591Init()) == -1) {
        printf("Fail to init pcf8591 AD\n");
        return -1;
    }
    if (pcf8591SetCtrl(devFD, PCF8591_INIT_AD_CONTROL) == -1) {
        printf("Fail to Set pcf8591 control AD\n");
        pcf8591DeInit(devFD);
        return -1;
    }
 
    int i = 0;
        int x, y, z;
        signal(SIGINT, PS2Handler);
        for (i=0; i<PS2_READ_TIMES; i++) {
                x = pcf8591Read(devFD, mode, PCF8591_AIN_CHANNEL0);
                y = pcf8591Read(devFD, mode, PCF8591_AIN_CHANNEL1);
                z = pcf8591Read(devFD, mode, PCF8591_AIN_CHANNEL2);
                if (z > SW_TRIGGER) {
                        z = 0;
                } else {
                        z = 0;
                } else {
                        z = 1;
                }
                printf("X=%3d Y=%3d Z=%d\n", x, y, z);
                sleep(1);
        }
        pcf8591DeInit(devFD);
        return 0;
}

3.3 Compile and Run

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

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

4 相关资料