Difference between revisions of "Matrix - Joystick"
From FriendlyELEC WiKi
Line 4: | Line 4: | ||
[[File:Joystick01.png|thumb|Joystick]] | [[File:Joystick01.png|thumb|Joystick]] | ||
我们把游戏手柄上用的摇杆拿出来,做成单独的配件。摇杆是由两个滑动变阻器和一个按键组成。当拨动摇杆时,滑动变阻器的阻值就发生变化,对应的X/Y电压值也随之变化,而用力按下摇杆就会触发按键按下,对应的SW信号变为低电平。 | 我们把游戏手柄上用的摇杆拿出来,做成单独的配件。摇杆是由两个滑动变阻器和一个按键组成。当拨动摇杆时,滑动变阻器的阻值就发生变化,对应的X/Y电压值也随之变化,而用力按下摇杆就会触发按键按下,对应的SW信号变为低电平。 | ||
+ | This joystick consists of two Sliding rheostats and one button. | ||
+ | |||
==特性== | ==特性== | ||
* X和Y轴,一个按键 | * X和Y轴,一个按键 |
Revision as of 05:50, 6 August 2015
1 Introduction
我们把游戏手柄上用的摇杆拿出来,做成单独的配件。摇杆是由两个滑动变阻器和一个按键组成。当拨动摇杆时,滑动变阻器的阻值就发生变化,对应的X/Y电压值也随之变化,而用力按下摇杆就会触发按键按下,对应的SW信号变为低电平。 This joystick consists of two Sliding rheostats and one button.
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上传到开发板上运行即可测试。