The Joystick class constructs objects that represent a single Joystick sensor attached to the physical board.

This list will continue to be updated as more Joystick devices are confirmed.

Parameters

  • General Options

    PropertyTypeValue/DescriptionDefaultRequired
    pinsArray of Pins["A*", ...]. Analog pins connected to X and Yyes
    invertBooleantrue, false. Invert both axesfalseno
    invertXBooleantrue, false. Invert the X axisfalseno
    invertYBooleantrue, false. Invert the Y axisfalseno

Shape

Property NameDescriptionRead Only
idA user definable id value. Defaults to a generated uidNo
x-1, 1.Yes
y-1, 1.Yes

Component Initialization

Analog

new five.Joystick({
  // [ x, y ]
  pins: ["A0", "A1"]
});

Joystick

Adafruit Joystick

SparkFun Joystick

Sparkfun Shield

new five.Joystick({
  pins: ["A0", "A1"], 
  invertY: true
});

SparkFun JoyStick Shield

Esplora

new five.Joystick({
  controller: "ESPLORA"
});

Esplora

Axis Inversion

Default
var joy = new Joystick({ 
  pins: ["A0", "A1"], 
});

Produces the following default axes:

    -1
-1   *   1
     1      
Invert Y
var joy = new Joystick({ 
  pins: ["A0", "A1"], 
  invertY: true 
});

Produces an inverted Y axis, with a default X axis:

     1
-1   *   1
    -1      
Invert X
var joy = new Joystick({ 
  pins: ["A0", "A1"], 
  invertX: true 
});

Produces an inverted X axis, with a default Y axis:

   -1
1   *  -1
    1      
Invert Both
var joy = new Joystick({ 
  pins: ["A0", "A1"], 
  invert: true 
});

Produces an both inverted X and Y axes:

    1
1   *  -1
   -1      

API

There are no special API functions for this class.

Events

  • change The "change" event is emitted whenever the value of an axis changes.

  • data The "data" event is fired as frequently as the user defined freq will allow in milliseconds.

Examples

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub