-
|
Hi, I'm trying to write a short code snippet for a menu. I want to navigate through programs using the left and right buttons, then run the selected program by pressing the center button. After the program finishes, I’d like the menu to return to the last selected program. I checked the forum for solutions and tried the example below using hub.menu, but we're starting it with the Bluetooth button, which could cause an issue in FLL because Bluetooth has to be turned off. hub = base.hub # InventorHub() nesnesi
durum = 0
# Robot ekranında başlangıçta 0 gözüksün
hub.display.number(int(durum))
# 30 saniyelik süre için
first_job_started = False
countdown_watch = StopWatch() # Start/stop later
while True:
pressed = hub.buttons.pressed()
hub.light.on(Color.GREEN)
# Eğer ilk görev başladıysa 30 sn sayacını kontrol et
if first_job_started:
elapsed = countdown_watch.time() // 1000
if elapsed >= 30:
hub.light.on(Color.RED) # 30 sn sonu LED kırmızı
if not pressed:
wait(10)
continue
# SOL TUŞ => Durum bir arttır (9'dan sonra 1), ekranda göster
if Button.LEFT in pressed:
durum += 1
if durum > 9:
durum = 1
hub.display.number(int(durum)) # Ekrana sadece rakam
# Tuş bırakılana kadar bekle (debounce)
while Button.LEFT in hub.buttons.pressed():
wait(10)
# SAĞ TUŞ => Mevcut durumu çalıştır (1..9)
elif Button.BLUETOOTH in pressed:
# İlk defa görev başlıyorsa sayaç reset (30 sn takibi)
if not first_job_started and (1 <= durum <= 9):
first_job_started = True
countdown_watch.reset() # Sayaç sıfır
if durum == 1: sonar()
elif durum == 2: yya()
elif durum == 3: ornektoplama()
elif durum == 4: coralnursery()
elif durum == 5: batikgemi()
elif durum == 6: trident()
elif durum == 7: gemibirak()
elif durum == 8: balinabesle()
elif durum == 9: fener()
else:
print("Henüz geçerli bir görev seçilmedi (0)")
while Button.RIGHT in hub.buttons.pressed():
wait(10)
wait(10) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Maybe some interesting ideas here: https://github.com/orgs/pybricks/discussions/1401 |
Beta Was this translation helpful? Give feedback.
-
|
Thank you @dlech Actually, I had seen this discussion before, but another suggestion within it solved my problem. We use the center button to start and the Bluetooth button to stop, which turned out to be quite effective. |
Beta Was this translation helpful? Give feedback.
Maybe some interesting ideas here: https://github.com/orgs/pybricks/discussions/1401