Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. #!/usr/bin/python
  2. import time
  3. # 2 main traffic light 3 ways to go per tf_light
  4. # form traffic_light's name = {direction : status[status<1,0,-1> ,delay time<second>]}
  5. traffic_light_1 = {
  6.                     'Straight' : [None,None],
  7.                     'Left' : [None,None],
  8.                     'Right' : [None,None]
  9.                     }
  10. traffic_light_2 = {
  11.                     'Straight' : [None,None],
  12.                     'Left' : [None,None],
  13.                     'Right' : [None,None],
  14.                     }
  15. #3 status Red, Yellow and Green don't miss anything
  16. #time will add later except Yellow it alway has 3 seconds only
  17. status = {  "Red":None,
  18.             "Yellow": 3,
  19.             "Green":None
  20.         }
  21.        
  22. # Green --> Yellow -->  Red
  23. # ^                      |
  24. # |                      |
  25. # ------------------------
  26.  
  27.  
  28. def change_status(current_status): # use to change status
  29.     if (current_status == 0):
  30.         return 1
  31.     elif (current_status == -1):
  32.         return 0
  33.     if (current_status == 1):
  34.         return -1
  35.  
  36. def status_value(status): # use to print out the screen
  37.     if status == 1:
  38.         return "Green"
  39.     elif status == 0:
  40.         return "Red"
  41.     if status == -1:
  42.         return "Yellow"
  43.  
  44. def synchronize_2(status):# sychronize 2 traffic light so its can run smoothly
  45.     if status == 1:
  46.         return 0
  47.     elif status == 0 :
  48.         return 1
  49.     if status == -1 :
  50.         return 0
  51. def synchronize_1(status):
  52.    
  53. devices = ['traffic_light_1' , 'traffic_light_2' ]
  54.  
  55.  
  56. #setup first time :
  57. traffic_light = input("Which one you want to set up <traffic_light_1 or traffic_light_2> : ")
  58. if traffic_light in devices:
  59.     if  traffic_light == "traffic_light_1":
  60.         traffic_light_1["Straight"][0] = input("Update status for ", traffic_light," straight direction: ")
  61.     else :
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement