From 07c8fc873f7537085eb4644fb345395b94e5d767 Mon Sep 17 00:00:00 2001 From: Arlan Prado Date: Fri, 9 Apr 2021 21:16:49 -0700 Subject: [PATCH] Added deadzone for whammy and formatted code Added a function to set the joystick within range -127 to 127 for better formatting. Dead zone for whammy bar added. Prevents star power from being charged from star sustains. --- code.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/code.py b/code.py index 7a97113..fe2752d 100644 --- a/code.py +++ b/code.py @@ -80,6 +80,17 @@ 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} +def setToJoyStickRange(stickVal): + return int(stickVal * 127 * 2 -127) + +def whammyDeadZone(whammyVal): + whammyDeadZoneVal = -90 + whammyVal = setToJoyStickRange(whammyVal) + if(whammyVal < whammyDeadZoneVal): + return whammyDeadZoneVal + else: + return whammyVal + while True: for gamenum, button in buttons.items(): if button.value: @@ -91,9 +102,9 @@ # make limit -127 to 127 # adjust your joystick until limits are -127 to 127 - gamepad.move_joysticks(int(ana_joy_x.value/64000 * 127 * 2 - 127), - int(ana_joy_y.value/65000 * 127 * 2 - 127), - int((ana_whammy.value-30000)/25000 * 127 * 2 - 127), None) + gamepad.move_joysticks(setToJoyStickRange(ana_joy_x.value/64000), + setToJoyStickRange(ana_joy_y.value/65000), + whammyDeadZone((ana_whammy.value-30000)/25000), None) #time.sleep(0.1) #print(((ana_whammy.value-30000)/25000))