コード例 #1
0
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'
コード例 #2
0
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'
コード例 #3
0
ファイル: Snake_9.py プロジェクト: GreyOwul/School
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'