Run a program while monitoring for a button to stop it #2225
-
|
So I have a main program that mimics the SPIKE hub menu where I get to choose different programs based on numbers. But the problem now is, after I run a program (say program 1), I can't stop program 1 only. I'll have to stop the entire program. What I'm looking to achieve is, if I run program 1, I want to have the ability to press a button (say center button), that only stops program 1, and I'm now able to select other program numbers without stopping the whole program. My main program look something like this. while True:
if Button.LEFT in hub.buttons.pressed():
if program > 0:
program -= 1
elif program == 0:
program = 9
wait(200)
elif Button.RIGHT in hub.buttons.pressed():
if program < 9:
program += 1
elif program == 9:
program = 0
wait(200)
elif Button.CENTER in hub.buttons.pressed():
wait(100)
# add your route here
if program == 0:
program0()
elif CURRENT_ROUTE == 1:
program1()What would be the best way to implement this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
|
Beta Was this translation helpful? Give feedback.
try: program1() except SystemExit: program_selector()