Voorbeeld
Stoplicht
Last updated
Was this helpful?
Stoplicht
Last updated
Was this helpful?
Was this helpful?
TOESTANDEN = {"VOET_ROOD": 0, "WACHT_OP_ROOD": 1, "WACHTEN": 2, "VOET_GROEN": 3, "VOET_ORANJE": 4}
huidige_toestand = TOESTANDEN["VOET_ROOD"]if huidige_toestand == TOESTANDEN["VOET_ROOD"]:
# Stoplicht blijft op rood staan
# We detecteren hier of de knop wordt ingedrukt
if knop_ingedrukt:
huidige_toestand = TOESTANDEN["WACHT_OP_ROOD"]
elif huidige_toestand == TOESTANDEN["WACHT_OP_ROOD"]:
# Blijf in deze toestand tot het autostoplicht op rood staat
if auto_rood:
huidige_toestand = TOESTANDEN["WACHTEN"]
TOESTANDEN = {"VOET_ROOD": 0, "WACHT_OP_ROOD": 1, "WACHTEN": 2, "VOET_GROEN": 3, "VOET_ORANJE": 4}
huidige_toestand = TOESTANDEN["VOET_ROOD"]
while True:
if huidige_toestand == TOESTANDEN["VOET_ROOD"]:
# Stoplicht blijft op rood staan
# Zet het stoplicht op rood als dat nodig is
# We detecteren hier of de knop wordt ingedrukt
if knop_ingedrukt:
huidige_toestand = TOESTANDEN["WACHT_OP_ROOD"]
elif huidige_toestand == TOESTANDEN["WACHT_OP_ROOD"]:
# Blijf in deze toestand tot het autostoplicht op rood staat
if auto_rood:
huidige_toestand = TOESTANDEN["WACHTEN"]
elif huidige_toestand == TOESTANDEN["WACHTEN"]:
# Blijf in deze toestand tot 2 seconden verstreken zijn
if tijd_voorbij:
huidige_toestand = TOESTANDEN["VOET_GROEN"]
elif huidige_toestand == TOESTANDEN["WACHTEN"]:
# Blijf in deze toestand tot het autostoplicht op rood staat
if tijd_voorbij:
huidige_toestand = TOESTANDEN["VOET_GROEN"]
elif huidige_toestand == TOESTANDEN["VOET_GROEN"]:
# Zet stoplicht op groen als dat nodig is
# Blijf 10 seconden in deze toestand
if tijd_voorbij:
huidige_toestand = TOESTANDEN["VOET_ORANJE"]
elif huidige_toestand == TOESTANDEN["VOET_ORANJE"]:
# Zet stoplicht op oranje als dat nodig is
# Blijf 10 seconden in deze toestand
if tijd_voorbij:
huidige_toestand = TOESTANDEN["VOET_ROOD"]