SparkFun Qwiic Joystick SKU: COM-15168 - modification

Hi

Can the ‘UP’ & ‘DOWN’ orientation be swapped simply in the code?

Many thanks in advance

The python code https://github.com/sparkfun/Qwiic_Joyst … tick.py#L1 modification would be:

import smbus

import time

bus = smbus.SMBus(1)

addr = 0x20

def main():

global bus_data, X, Y

while True:

qwiicjoystick()

def qwiicjoystick():

global bus_data, X, Y

try:

bus_data = bus.read_i2c_block_data(addr, 0x03, 5)

except Exception as e:

print(e)

X = (bus_data[0] << 8 | bus_data[1]) >> 6

Y = ((bus_data[2] << 8 | bus_data[3]) >> 6) * -1 # Reverse the sign for the Y-axis values

print(X, Y, " Button = ", bus_data[4])

time.sleep(0.05)

if X < 450:

direction = RIGHT

elif 575 < X:

direction = LEFT

if Y < 450:

direction = DOWN

elif 575 < Y:

direction = UP

if Select_Button == 1:

terminate()

if name == ‘main’:

main()

That should work…all it does it multiply Y*-1 to invert the sign of its value