from machine import UART, Pin
import time
# Configure UART
uart = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
# Function to send commands
def send_command(command):
uart.write(command + "\n")
print("Command Sent:", command)
time.sleep(0.1)
# Read responses
def read_response():
if uart.any():
response = uart.read().decode('utf-8').strip()
print("Position Received:", response)
# Commands to send
commands = ["LEFT", "UP", "RIGHT", "DOWN"]
# Main loop
while True:
for command in commands:
send_command(command)
time.sleep(1) # Delay for processing
read_response()