Skip to content

Commit

Permalink
Added a rounddown function
Browse files Browse the repository at this point in the history
This function prevents the whammy value from acting as its changing when it isn't. Outputs more consistent values.
  • Loading branch information
ArlanPrado committed Apr 10, 2021
1 parent 5857bbb commit f8ebc03
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions code.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@
buttons = {5 : btn_green, 2 : btn_red, 6 : btn_yellow, 1 : btn_blue,
9 : btn_orange, 3 : btn_star, 4 : btn_plus, 7 : btn_minus, 13 : btn_up, 14 : btn_down}

# sets the range from -127 to 127
def setToJoyStickRange(stickVal):
return int(stickVal * 127 * 2 -127)

# sets a dead zone for the whammy bar
# if the whammy value is below the specified whammy value, then return the specified whammy value
def whammyDeadZone(whammyVal):
whammyDeadZoneVal = -90
whammyVal = setToJoyStickRange(whammyVal)
Expand All @@ -91,6 +94,10 @@ def whammyDeadZone(whammyVal):
else:
return whammyVal

# rounds down the joystick value to the value specified
def roundStickVal(stickVal):
roundDownVal = 20
return int(stickVal / roundDownVal) * roundDownVal
while True:
for gamenum, button in buttons.items():
if button.value:
Expand All @@ -102,10 +109,12 @@ def whammyDeadZone(whammyVal):
# make limit -127 to 127
# adjust your joystick until limits are -127 to 127

gamepad.move_joysticks(setToJoyStickRange(ana_joy_x.value/64000),
setToJoyStickRange(ana_joy_y.value/65000),
whammyDeadZone((ana_whammy.value-30000)/25000), None)
gamepad.move_joysticks(
setToJoyStickRange(ana_joy_x.value/64000),
setToJoyStickRange(ana_joy_y.value/65000),
roundStickVal(whammyDeadZone((ana_whammy.value-30000)/25000)),
None)

#time.sleep(0.1)
#print(((ana_whammy.value-30000)/25000))
#print(roundStickVal(whammyDeadZone((ana_whammy.value-30000)/25000)))

0 comments on commit f8ebc03

Please sign in to comment.