I am having some interesting behaviour with my sense hat. I wrote some code to be invoked on button press with the joystick. I noticed it seems to be being run twice. So, I took some code from teh getting started tutorial and modified it a touch.
If I run the code below. For every button press of the joystick I get the direction printed twice. Is this intended behaviour and I missed something? It seems far too consistent for a hardware fault IMO.
If this is intended, how do I react to the button press but only call the function once and not twice?
Here is the code...
Code: Select all
from sense_hat import SenseHat
sense = SenseHat()
# Define the functions
def up():
print 'up'
def down():
print 'down'
def left():
print 'left'
def right():
print 'right'
def middle():
print 'middle'
# Tell the program which function to associate with which direction
sense.stick.direction_up = up
sense.stick.direction_down = down
sense.stick.direction_left = left
sense.stick.direction_right = right
sense.stick.direction_middle = middle
while True:
pass # This keeps the program running to receive joystick events