JoystickAdapter

class JoystickAdapter : public InputInterface
#include <JoystickAdapter.h>

Adapter class to handle analog joystick input for an LCD menu.

This adapter reads the horizontal and vertical axes of a joystick and converts them into menu commands.

The joystick centre value defaults to 512 and can be customised along with the dead-zone margin to accommodate different hardware.

Public Functions

inline JoystickAdapter(LcdMenu *menu, uint8_t horizontalPin, uint8_t verticalPin, uint16_t center = 512, uint16_t margin = 100, byte leftCmd = BACK, byte rightCmd = RIGHT, byte upCmd = UP, byte downCmd = DOWN)

Construct a new JoystickAdapter.

The adapter can be customised by providing command codes for each direction. By default the horizontal axis maps to BACK and RIGHT and the vertical axis to UP and DOWN. Pressing the joystick triggers ENTER.

Parameters:
  • menu – Pointer to the LcdMenu instance

  • horizontalPin – Analog pin connected to the horizontal axis

  • verticalPin – Analog pin connected to the vertical axis

  • center – Centre value of the joystick (default 512)

  • margin – Dead zone margin around the centre (default 100)

  • leftCmd – Command for the left direction (default BACK)

  • rightCmd – Command for the right direction (default RIGHT)

  • upCmd – Command for the up direction (default UP)

  • downCmd – Command for the down direction (default DOWN)

inline virtual void observe() override

Private Functions

inline int8_t readAxis(int value) const

Private Members

const uint8_t hPin

Analog pin for horizontal axis.

const uint8_t vPin

Analog pin for vertical axis.

const uint16_t center

Joystick center value.

const uint16_t margin

Dead zone around the centre value.

const byte leftCmd

Command for moving left.

const byte rightCmd

Command for moving right.

const byte upCmd

Command for moving up.

const byte downCmd

Command for moving down.

int8_t lastHoriz = 0
int8_t lastVert = 0