GamearooCodes

Traffic Light

May 1st, 2023
1,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. local component = require("component");
  2.  
  3. local redlight = component.traffic_light_card;
  4. local os = require("os")
  5. local term = require("term")
  6. local sides = require("sides")
  7. local colors = require("colors")
  8. local thread = require("thread")
  9. local rs = component.redstone
  10.  
  11.  
  12.  
  13.  
  14. function sleep(n)
  15.     os.sleep(n)
  16.   end
  17.  
  18.   term.clear()
  19. print("Traffic lights are starting! Lights are in flash mode")
  20. rs.setBundledOutput(sides.back, {[colors.cyan] = 200});
  21.  
  22. sleep(80)
  23.  
  24. term.clear()
  25. print("Traffic lights are starting all lights are red!")
  26. rs.setBundledOutput(sides.back, {[3] = 200})
  27. sleep(1)
  28. rs.setBundledOutput(sides.back, {[3] = 0})
  29. sleep(8)
  30.  
  31.  
  32. mode = "normal"
  33. running = "yes"
  34.  
  35. console = "East Left"
  36.   time = os.date("*t")
  37.   cycledtime = time.hour .. ":" .. time.min
  38. local loop1 = thread.create(function()
  39.     while true  do
  40.    
  41.       time2 = os.date("*t")
  42.  
  43.       if(time2.hour == 21) or (time2.hour == 22) or (time2.hour == 23) or (time2.hour == 0) or (time2.hour == 1) or (time2.hour == 2) or (time2.hour == 3) or (time2.hour == 4) or (time2.hour == 5) and (mode == "normal") then
  44.         mode = "flash"
  45.         if(running == "no") then
  46.           rs.setBundledOutput(sides.back, {[colors.yellow] = 0, [colors.pink] = 200})
  47.         end
  48.       else
  49.         if(mode == "flash") and (running == "no") then
  50.           if(time2.hour == 6) or (time2.hour == 7) or (time2.hour == 8) or (time2.hour == 9) or (time2.hour == 10) or (time2.hour == 11) or (time2.hour == 12) or (time2.hour == 13) or (time2.hour == 14) or (time2.hour == 15) or (time2.hour == 16) or (time2.hour == 17) or (time2.hour == 18) or (time2.hour == 19) or (time2.hour == 20) then
  51.           rs.setBundledOutput(sides.back, {[3] = 200, [colors.pink] = 0})
  52.           sleep(1)
  53.           rs.setBundledOutput(sides.back, {[3] = 0})
  54.           sleep(8)
  55.           running = "yes"
  56.           mode = "normal"
  57.           end
  58.         end
  59.       end
  60.  
  61.  
  62.       term.clear()
  63.       print("Time Cycled: " .. cycledtime)
  64.       print("Current Time: " .. time2.hour .. ":" .. time2.min)
  65.     print("Current Cycle " .. console);
  66.     sleep(1)
  67.     end
  68.   end)
  69.  
  70.   local loop2 = thread.create(function()
  71.     while true do
  72.       if(mode == "normal") then
  73.         time3 = os.date("*t")
  74.         cycledtime = time3.hour .. ":" .. time3.min
  75.        console = "Stright"
  76.        rs.setBundledOutput(sides.back, {[colors.yellow] = 0, [colors.black] = 0, [colors.brown] = 200})
  77.        sleep(33)
  78.        rs.setBundledOutput(sides.back, {[colors.yellow] = 255})
  79.        sleep(5)
  80.        rs.setBundledOutput(sides.back, {[colors.brown] = 0})
  81.        sleep(3)
  82.        rs.setBundledOutput(sides.back, {[colors.green] = 200})
  83.        sleep(1)
  84.        console = "U-Turn"
  85.        rs.setBundledOutput(sides.back, {[colors.green] = 0, [colors.red] = 200})
  86.        sleep(12)
  87.        rs.setBundledOutput(sides.back, {[colors.red] = 0})
  88.        sleep(3)
  89.        rs.setBundledOutput(sides.back, {[colors.black] = 200})
  90.        
  91.        sleep(1)
  92.       else
  93.         if(running == "yes") then
  94.        
  95.        print("oof")
  96.         running = "no"
  97.         sleep(1)
  98.         else
  99.           sleep(1)
  100.         end
  101.        
  102.       end
  103.  
  104.  
  105.     end
  106.  
  107.   end)
  108.   thread.waitForAny({loop1, loop2})
Advertisement
Add Comment
Please, Sign In to add comment