def GetDirection( ): #This function uses geometry to determine which direction the joystick is being pointed in X = arduinoAnalogRead(0) - 512 Y = arduinoAnalogRead(1) - 522 if (Y**2 + X**2) <= 625: #No input return 'N' if Y >= X and Y >= (-1) * X: #right return 'R' if Y >= X and Y <= (-1) * X: #up return 'U' if Y < X and Y >= (-1) * X: #down return 'D' if Y < X and Y < (-1) * X: #left return 'L'
def GetDirection(): X = arduinoAnalogRead(0) - 512 Y = arduinoAnalogRead(1) - 522 if (Y ** 2 + X ** 2) <= 625: print(X, Y) print("none") return 'N' if Y >= X and Y >= (-1) * X: print(X, Y) print("up") return 'U' if Y >= X and Y <= (-1) * X: print(X, Y) print("left") return 'L' if Y < X and Y >= (-1) * X: print(X, Y) print("right") return 'R' if Y < X and Y < (-1) * X: print(X, Y) print("down") return 'D'
def GetDirection(): #This function uses geometry to determine which direction the joystick is being pointed in X = arduinoAnalogRead(0) - 512 Y = arduinoAnalogRead(1) - 522 if (Y ** 2 + X ** 2) <= 625: # print(X, Y) # print("none") return 'N' if Y >= X and Y >= (-1) * X: # print(X, Y) # print("right") return 'R' if Y >= X and Y <= (-1) * X: # print(X, Y) # print("up") return 'U' if Y < X and Y >= (-1) * X: # print(X, Y) # print("down") return 'D' if Y < X and Y < (-1) * X: # print(X, Y) # print("left") return 'L'