FLL/menu.py
2025-11-09 17:50:54 +01:00

44 lines
958 B
Python

# menu.py
import usys
from pybricks.tools import hub_menu, wait
import batteria
from giro_leo_prova import main as run_R
from robot_local import robot
from run_01 import main as run_1
from run_02 import main as run_2
PROGRAMMI = {"1": run_1, "2": run_2, "R": run_R}
def run_with_play(hub, fn, *args, **kwargs):
try:
hub.display.char(">")
return fn(*args, **kwargs)
finally:
hub.display.text("")
def run_once():
labels = list(PROGRAMMI.keys())
if not labels:
print("Nessun programma.")
wait(1500)
return
# if len(labels) == 1: # no menu se solo 1 programma
# run_with_play(robot.hub, PROGRAMMI[labels[0]], robot)
# return
scelta = hub_menu(*labels)
run_with_play(robot.hub, PROGRAMMI[scelta], robot)
while True:
run_once()
# while True:
# try:
# run_once()
# except Exception as e:
# usys.print_exception(e)
# wait(3000)