Difference between revisions of "Matrix - Joystick"
From FriendlyELEC WiKi
Line 3: | Line 3: | ||
==Introduction== | ==Introduction== | ||
[[File:Joystick01.png|thumb|Joystick]] | [[File:Joystick01.png|thumb|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. | |
− | This | + | |
==特性== | ==特性== |
Revision as of 06:00, 6 August 2015
1 Introduction
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 特性
- X和Y轴,一个按键
- 2.54mm排针接口,接线方便,通用性强
3 使用方法
3.1 连接
- 连接到Tiny4412 SDK (1506)
- 1) 需要Tiny4412 SDK先连接Matrix - Analog to Digital Converter配件
- 2) 然后,Joystick与Matrix - Analog to Digital Converter配件相连接:
- GND针脚接地
- V针脚接5V
- VRX针脚连接Analog to Digital Converter的AIN0针脚
- VRY针脚连接Analog to Digital Converter的AIN1针脚
- SW针脚连接Analog to Digital Converter的AIN2针脚
3.2 Linux下的C示例
#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 编译并运行示例
git clone http://github.com/friendlyarm/fa-hardware.git cd fa-hardware cd demo cd matrix-joystick make
将编译生成的PS2rocker通过ftp上传到开发板上运行即可测试。