MMrmcnich
Posts: 15
Joined: Mon Apr 16, 2018 6:33 pm

Pressed and Held actions in the same direction using SenseHat joystick?

Thu Apr 26, 2018 8:26 pm

I am currently working on a weather station sort of thing for scientific use and the device is supposed to be portable so actions will happen upon joystick events while it runs off boot. Now I don't want to display too much info when the joystick is in one direction in fact I would rather have one reading per direction. However, this is obviously also very limiting and so I was wondering if I could have right direction pressed do one thing and have right direction held do another. If it is possible wouldn't I also need to make it tell how long if held? Here is what I am thinking if it works:

Code: Select all

if event.action == 'held' and event.direction == 'right':
The first concerning thing is immediately on press when you try to hold it wouldn't it activate the pressed rather than held. I would also like to add if this doesn't work is there any roundabout way to achieve this or no?

User avatar
bensimmo
Posts: 3111
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Pressed and Held actions in the same direction using SenseHat joystick?

Thu Apr 26, 2018 9:03 pm

I've not actually use the joystick but for reference
https://pythonhosted.org/sense-hat/api/#joystick

Others have though :-)

MMrmcnich
Posts: 15
Joined: Mon Apr 16, 2018 6:33 pm

Re: Pressed and Held actions in the same direction using SenseHat joystick?

Thu Apr 26, 2018 9:09 pm

bensimmo wrote:
Thu Apr 26, 2018 9:03 pm
I've not actually use the joystick but for reference
https://pythonhosted.org/sense-hat/api/#joystick

Others have though :-)
Thanks but I have actually looked at the entire documentation and much more and however I cannot find anything on doing two different actions in the same direction. Sadly I am in the process of getting a new SenseHat the other one is having big issues and along with compass calibration not working and the joystick no longer working the color of letters displayed on the screen goes wonky and is not the color I set it too. Even worse it kept reading everything like temperature, etc, as 0. It looks as if it is having some serious connection issues.

User avatar
bensimmo
Posts: 3111
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Pressed and Held actions in the same direction using SenseHat joystick?

Fri Apr 27, 2018 8:23 am

The event gives and action
action - The action that occurred, as a string ("pressed", "released", "held")
Just react on the direction and the action depending on the event.


So wait for an event, then that calls the function (direction) and then check which event ?
So expand the last example.
There maybe simpler ways and you can set up funtions for each event & function ?


You can still play around and get the code working without a SenseHAT,
just switch to sense_emu on the import on use the one on screen.

Return to “Astro Pi”

Who is online

Users browsing this forum: No registered users and 1 guest