There is a website called https://www.element14.com/community/community/raspberry-pi/raspberry-pi-accessories/blog/2017/01/23/raspberry-pi-sense-hat-enabling-the-joystick which takes you through how to make the joystick work and how to make a programme which responds to the joystick being moved, to move a dot around the screen.
To make the joy stick work, type the following into the terminal:
cd /usr/lib/python2.7/dist-packages/sense_hat
then:
sudo rm __init__.py sense_hat.py __init__.pyc sense_hat.pyc
then:
sudo wget https://raw.githubusercontent.com/RPi-Distro/python-sense-hat/master/sense_hat/__init__.py
sudo wget https://raw.githubusercontent.com/RPi-Distro/python-sense-hat/master/sense_hat/sense_hat.py
sudo wget https://raw.githubusercontent.com/RPi-Distro/python-sense-hat/master/sense_hat/stick.py
then:
sudo nano sense_hat.py
then look on line 17, and the code should look like this:
from .stick import SenseStick
but you need to delete the dot, and line 17 should look like this:
from .stick import SenseStick
then you need to press ctrl+o then enter to save changes and ctrl+x to exit nano
An example of code using the joystick:
from sense_hat import SenseHat
sense = SenseHat()
while True:
for x in sense.stick.get_events():
if x.direction == 'up':
sense.show_letter("U")
elif x.direction == 'down':
sense.show_letter("D")
elif x.direction == 'left':
sense.show_letter("L")
elif x.direction == 'right':
sense.show_letter("R")
elif x.direction == 'middle':
sense.show_letter("M")