Code Monkey home page Code Monkey logo

joystick's Introduction

Joystick

Kaluma library for joystick module.

Wiring

Here is a wiring example for joystick.

Raspberry Pi Pico Joystick
3V3 VCC (+)
GND GND
GP15 SW (SEL)
GP26 (ACD0) X (HOR)
GP27 (ACD1) Y (VER)

wiring

Install

npm install https://github.com/niklauslee/joystick

Usage

Here is an example code.

const x = 26;  // GP26 (ACD0)
const y = 27;  // GP27 (ACD1)
const sw = 15; // GP15

const {Joystick} = require('joystick');
const joy = new Joystick(x, y, sw);

setInterval(() => {
  let val = joy.read();
  let valX = val[0].toFixed(2);
  let valY = val[1].toFixed(2);
  let valS = val[2];
  console.log(`x:${valX}, y:${valY}, sw:${valS}`);
}, 500);

API

Class: Joystick

new Joystick(x, y, sw)

  • x <number> : The pin number which support ADC function and it shall be connected to X (HOR) pin of the joystick.
  • y <number> : The pin number which support ADC function and it shall be connected to Y (VER) pin of the joystick.
  • sw <number> : The pin number which support GPIO and it shall be connected to SW (SEL) pin of the joystick.

Internally set the SW pin to INPUT_PULLUP mode. If you have an external pull-up resistor for SW pin, then you need to change the mode after the instantiation.

joystick.read()

  • Return <number[3]>: Number array with the X, Y and SW value. X and Y value range is from 0 to 1.0 (middle is 0.5) and SW value is the 1 (normal) or 0 (pressed).

joystick's People

Contributors

niklauslee avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.