readJoystick

Read the status of the joystick

Description

example

joystickPress = readJoystick (mysh) returns the position of the joystick. The function returns a value between 0 to 5 depending on the position of the joystick.

Following are the values returned for the corresponding joystick positions:

  • 0 - Not pressed

  • 1 - Center

  • 2 - Left

  • 3 - Up

  • 4 - Right

  • 5 - Down

The above positions are with respect to the reference position of the Sense HAT. HDMI port of Raspberry Pi facing downwards is the reference position.

example

joystickPress = readJoystick(mysh,buttonPosition) returns ‘1’, if the joystick is at the specified position and returns ‘0’ otherwise. The values you can provide for button position are: ‘Up’, ‘Down’, ‘Left’, ‘Right’ and ‘Center’.

Examples

collapse all

Read the position of the joystick.

readJoystick(mysh)
ans = 1

The function returns the position of the joystick. In this example, it is assumed that you have pressed the joystick to the ‘center’ position.

You can find if the joystick is at the specified location. To check if the Joystick is at the position ‘up’, enter the following command.

readJoystick(mysh,'up')
ans=1

The function returns ‘1’, if the Joystick is the specified position, in this example ‘up’.

Input Arguments

collapse all

Connection to a SenseHAT board, specified as a sensehat object.

The value of the button position.

Output Arguments

collapse all

This argument returns the position of the joystick pressed (value between 0 to 5) or returns ‘1’ if the specified joystick position is pressed. The value is returned in uint8 format.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2016b