Python Forum
[PyGame] Limiting a Joystick value -1 to +1, to a value between 0 an 127 with 64 being center?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Limiting a Joystick value -1 to +1, to a value between 0 an 127 with 64 being center?
#3
(Dec-10-2017, 05:04 AM)Mekire Wrote: This all you are asking for?

That's exactly what I was looking for! Thank you very much for the to the point example.

The value "127" can be substituted with a variable and an additional parameter to the function can be added to make it usable with other max values other than 127 to make it more portable.

def scale(joy_val, max_val):
    return int(round((joy_val+1)/2.0 * max_val))
so it can be called with

scale(joystick.get_axis(0), 127)
and function just the same.
Reply


Messages In This Thread
RE: Limiting a Joystick value -1 to +1, to a value between 0 an 127 with 64 being center? - by japreja - Dec-10-2017, 06:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rasp Pi Analog Joystick mmagner2022 1 2,320 Feb-07-2022, 10:19 PM
Last Post: Larz60+
  [PyGame] Converting PyGame 2 axis joystick float to 360 angle archieab 1 3,315 Sep-26-2018, 05:40 PM
Last Post: archieab
  [PyGame] Using joystick module from PyGame archieab 6 16,112 Sep-25-2018, 06:13 PM
Last Post: archieab
  [PyGame] Joystick Input microphone_head 2 9,333 Sep-16-2018, 06:02 AM
Last Post: microphone_head

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020