from machine import Pin, ADC
import time

# Joystick
Joystick_Axis_X = ADC(Pin(26))
Joystick_Axis_Y = ADC(Pin(27))
Joystick_Push_button = Pin(28, Pin.IN)

# Button right
Button_Right = Pin(15, Pin.IN)

# Button left
Button_Left = Pin(16, Pin.IN)

# Buttons
Buttons_A = Pin(0, Pin.IN)
Buttons_B = Pin(1, Pin.IN)
Buttons_C = Pin(2, Pin.IN)
Buttons_D = Pin(5, Pin.IN)
Buttons_E = Pin(4, Pin.IN)
Buttons_F = Pin(3, Pin.IN)

while True:
    # Joystick reading
    Joystick_Axis_X_Value = Joystick_Axis_X.read_u16()
    Joystick_Axis_Y_Value = Joystick_Axis_Y.read_u16()
    Joystick_Push_button_Value = Joystick_Push_button.value()

    # Button right reading
    Button_Right_Value = Button_Right.value()
    
    # Button left reading
    Button_Left_Value = Button_Left.value()
    
    # Buttons reading
    Buttons_A_Value = Buttons_A.value()
    Buttons_B_Value = Buttons_B.value()
    Buttons_C_Value = Buttons_C.value()
    Buttons_D_Value = Buttons_D.value()
    Buttons_E_Value = Buttons_E.value()
    Buttons_F_Value = Buttons_F.value()

    # Joystick data transmission
    if Joystick_Axis_X_Value < 20000:
        print("LEFT")
    if Joystick_Axis_X_Value > 40000:
        print("RIGHT")
    if Joystick_Axis_Y_Value < 20000:
        print("DOWN")
    if Joystick_Axis_Y_Value > 40000:
        print("UP")
    if (Joystick_Axis_X_Value > 20000) and (Joystick_Axis_X_Value < 40000) and (Joystick_Axis_Y_Value > 20000) and (Joystick_Axis_Y_Value < 40000):
        print("STOP")
    if Joystick_Push_button_Value == 1:
        print("PB")
        
    # Button right data transmission
    if Button_Right_Value == 1:
        print("CLOSE")
    
    # Button left data transmission
    if Button_Left_Value == 1:
        print("RASP")
    
    # Buttons data transmission
    if Buttons_A_Value == 1:
        print("A")
    if Buttons_B_Value == 1:
        print("B")
    if Buttons_C_Value == 1:
        print("C")
    if Buttons_D_Value == 1:
        print("D")
    if Buttons_E_Value == 1:
        print("E")
    if Buttons_F_Value == 1:
        print("F")

    # Delay
    time.sleep(0.2)
