Difference between revisions of "Matrix - Joystick"

From FriendlyELEC WiKi
Jump to: navigation, search
(使用方法)
(相关资料)
Line 88: Line 88:
 
Copy your compiled bin to your board and you are ready to go.
 
Copy your compiled bin to your board and you are ready to go.
  
==相关资料==
+
==Resources==

Revision as of 06:10, 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 Resources