Difference between revisions of "Matrix - Joystick"
From FriendlyELEC WiKi
Line 57: | Line 57: | ||
z = 0; | z = 0; | ||
} else { | } else { | ||
− | |||
z = 0; | z = 0; | ||
} else { | } else { | ||
Line 75: | Line 74: | ||
cd fa-hardware | cd fa-hardware | ||
cd demo | cd demo | ||
− | cd | + | cd matrix-joystick |
make | make | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 将编译生成的PS2rocker通过ftp上传到开发板上运行即可测试。 | |
==相关资料== | ==相关资料== |
Revision as of 06:15, 27 July 2015
Contents
1 介绍
我们把游戏手柄上用的摇杆拿出来,做成单独的配件。摇杆是由两个滑动变阻器和一个按键组成。当拨动摇杆时,滑动变阻器的阻值就发生变化,对应的X/Y电压值也随之变化,而用力按下摇杆就会触发按键按下,对应的SW信号变为低电平。
2 特性
- X和Y轴,一个按键
- 2.54mm排针接口,接线方便,通用性强
3 使用方法
3.1 连接
- 连接到Tiny4412 SDK (1506)
- 首先,你需要去掉Tiny4412 SDK 1506底板上面的BP1_EN的跳线帽
- 然后,将配件S针脚连接到GPIO PIN1, V接5V,G接地
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上传到开发板上运行即可测试。