Andreas Garmannslund / Mbed 2 deprecated SimplePlatformGame

Dependencies:   N5110 PinDetect PowerControl mbed

Embed: (wiki syntax)

« Back to documentation index

Joystick Class Reference

Joystick class. More...

#include <Joystick.h>

Public Member Functions

 Joystick (PinName x, PinName y, PinName button)
 Creates a new Joystick object.
 ~Joystick ()
 Deconstructor.
void update ()
 Updates the current direction and button status of the joystick.
void calibrate ()
 Calibrates the joystick.
int getDirection ()
 Returns the current JoystickDirection based on last update.
int readButton ()
 Reads the value of the button.

Static Public Attributes

static const float DEAD_ZONE = 0.1
 Square set around the center of the joystick where the input is ignored.

Detailed Description

Joystick class.

Definition at line 17 of file Joystick.h.


Constructor & Destructor Documentation

Joystick ( PinName  x,
PinName  y,
PinName  button 
)

Creates a new Joystick object.

Parameters:
xPin connected to the horizontal potentiometer of the joystick
yPin connected to the vertical potentiometer of the joystick
buttonPin connected to the button of the thumb joystick

Definition at line 7 of file Joystick.cpp.

~Joystick (  )

Deconstructor.

Frees allocated memory

Definition at line 14 of file Joystick.cpp.


Member Function Documentation

void calibrate (  )

Calibrates the joystick.

The joystick must be centered while this function is called

Definition at line 23 of file Joystick.cpp.

int getDirection (  )

Returns the current JoystickDirection based on last update.

Returns:
The current JoystickDirection.

Definition at line 40 of file Joystick.h.

int readButton (  )

Reads the value of the button.

Returns:
1 if pressed, 0 otherwise

Definition at line 45 of file Joystick.h.

void update (  )

Updates the current direction and button status of the joystick.

Definition at line 31 of file Joystick.cpp.


Field Documentation

const float DEAD_ZONE = 0.1 [static]

Square set around the center of the joystick where the input is ignored.

The axes are treated seperately. Can be varied from 0 (no dead-zone) to 0.5 (max value for dx and dy).

Definition at line 48 of file Joystick.h.