Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import time
- # 2 main traffic light 3 ways to go per tf_light
- # form traffic_light's name = {direction : status[status<1,0,-1> ,delay time<second>]}
- traffic_light_1 = {
- 'Straight' : [None,None],
- 'Left' : [None,None],
- 'Right' : [None,None]
- }
- traffic_light_2 = {
- 'Straight' : [None,None],
- 'Left' : [None,None],
- 'Right' : [None,None],
- }
- #3 status Red, Yellow and Green don't miss anything
- #time will add later except Yellow it alway has 3 seconds only
- status = { "Red":None,
- "Yellow": 3,
- "Green":None
- }
- # Green --> Yellow --> Red
- # ^ |
- # | |
- # ------------------------
- def change_status(current_status): # use to change status
- if (current_status == 0):
- return 1
- elif (current_status == -1):
- return 0
- if (current_status == 1):
- return -1
- def status_value(status): # use to print out the screen
- if status == 1:
- return "Green"
- elif status == 0:
- return "Red"
- if status == -1:
- return "Yellow"
- def synchronize_2(status):# sychronize 2 traffic light so its can run smoothly
- if status == 1:
- return 0
- elif status == 0 :
- return 1
- if status == -1 :
- return 0
- def synchronize_1(status):
- devices = ['traffic_light_1' , 'traffic_light_2' ]
- #setup first time :
- traffic_light = input("Which one you want to set up <traffic_light_1 or traffic_light_2> : ")
- if traffic_light in devices:
- if traffic_light == "traffic_light_1":
- traffic_light_1["Straight"][0] = input("Update status for ", traffic_light," straight direction: ")
- else :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement