Read the status 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.
Read Joystick Status
Read the position of the joystick.
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.
Read Joystick Status with Button 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.
The function returns ‘1’, if the Joystick is the specified position, in this example ‘up’.
mysh — Connection to SenseHAT
Sense HAT object
Connection to a SenseHAT board, specified as a sensehat object.
joystickPress — Position of the joystick
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
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
You can also deploy
readJoystickon the Raspberry Pi™ hardware in MATLAB® Online™.
Introduced in R2016b