Posts: 1
Joined: Thu Dec 07, 2017 2:27 pm

Sense HAT help

Thu Dec 07, 2017 2:33 pm

I'm very new to this and I'd like some help. I have a Sense Hat on my Rpi3 and I'd like to run a python program, script when I push the button on the joystick. Or even better, assigning a different programs to all 5 movements of the joystick. How do I write that?
I just started with Python few days ago, so I'll need "for dummies" instructions.
Any help much appreciated.

User avatar
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Sense HAT help

Thu Dec 07, 2017 3:32 pm

You can get started by looking through this resource: ... -sense-hat

Get a bit more familiar with everything and then look at the code example at the bottom of this page:

That should give you everything you need to know for the joystick. If this is for Astro Pi by the way make sure your code doesn't rely on the Joystick, see the rules poster which was included in the kit.

Posts: 1553
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Sense HAT help

Sun Dec 10, 2017 11:43 am

This may or may not help, it's what I did in python to make use of the joystick. Up down adjusts the brightness of the Sense Hat LED matrix. Dimmed or not dimmed. That's just a small bit of code from my full file. Hopefully I didn't leave anything important out. I do other things with the other positions but posting it all would likely confuse things.

Code: Select all

sense = SenseHat()
sense.low_light = True

def pushed_down(event):
    if event.action == ACTION_PRESSED:
       sense.low_light = True
def pushed_up(event):
    if event.action == ACTION_PRESSED:
       sense.low_light = False

sense.stick.direction_up = pushed_up
sense.stick.direction_down = pushed_down
sense.stick.direction_left = pushed_left
sense.stick.direction_right = pushed_right
sense.stick.direction_middle = pushed_middle

Return to “Astro Pi”