import time
from machine import ADC, Pin
time.sleep(0.1) # Wait for USB to become ready
def main():
# Horisontal:
horisontal = ADC(Pin(26))
p15 = Pin(15,Pin.OUT) # Step
p14 = Pin(14,Pin.OUT) # Direction
# Vertical:
vertical = ADC(Pin(27))
p1 = Pin(1,Pin.OUT) # Step
p0 = Pin(0,Pin.OUT) # Direction
p14.value(0)
while True:
hor_value = int((horisontal.read_u16()-32759)/32759)
ver_value = int((vertical.read_u16()-32759)/32759)
# Determine the horisontally controlled motor:
if hor_value <=0:
p14.value(1)
else:
p14.value(0)
if abs(hor_value)!=0:
p15.value(1)
p15.value(0)
else:
pass
# Determine vertically controlled motor:
if ver_value <=0:
p0.value(1)
else:
p0.value(0)
if abs(ver_value)!=0:
p1.value(1)
p1.value(0)
else:
pass
print(hor_value,ver_value)
time.sleep(0.1)
if __name__ == '__main__':
main()