GamearooCodes

Traffic Light Script

Apr 30th, 2023 (edited)
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 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. term.clear()
  11. print("Traffic lights are starting! Lights are in flash mode")
  12. rs.setBundledOutput(sides.back, {[colors.cyan] = 200})
  13. os.sleep(60);
  14. term.clear()
  15. print("Traffic lights are starting all lights are red!")
  16. rs.setBundledOutput(sides.back, {[3] = 200})
  17. os.sleep(1)
  18. rs.setBundledOutput(sides.back, {[3] = 0})
  19. os.sleep(8)
  20. redlight.setState(-1423, 74, -578, "StraightGreen", true, false)
  21. redlight.setState(-1419, 74, -578, "StraightGreen", true, false)
  22. redlight.setState(-1423, 74, -578, "StraightRed", false, false)
  23. redlight.setState(-1419, 74, -578, "StraightRed", false, false)
  24.  
  25.  
  26. function sleep(n)
  27.     os.sleep(n)
  28.   end
  29. console = "East Left"
  30.   time = os.date("*t")
  31.   cycledtime = time.hour .. ":" .. time.min
  32. local loop1 = thread.create(function()
  33.     while true  do
  34.    
  35.       time2 = os.date("*t")
  36.       term.clear()
  37.       print("Time Cycled: " .. cycledtime)
  38.       print("Current Time: " .. time2.hour .. ":" .. time2.min)
  39.     print("Current Cycle " .. console);
  40.     sleep(1)
  41.     end
  42.   end)
  43.  
  44.   local loop2 = thread.create(function()
  45.     while true do
  46.         time3 = os.date("*t")
  47.         cycledtime = time3.hour .. ":" .. time3.min
  48.         console = "Left Turn"
  49.         rs.setBundledOutput(sides.back, {[colors.blue] = 0, [colors.black] = 200})
  50.         redlight.setState(-1404, 74, -589, "NoRightTurn", true, false)
  51.        
  52.         sleep(12)
  53.         rs.setBundledOutput(sides.back, {[colors.black] = 0})
  54.         sleep(3)
  55.         rs.setBundledOutput(sides.back, {[colors.red] = 200})
  56.         sleep(1)
  57.         redlight.setState(-1404, 74, -589, "NoRightTurn", false, false)
  58.         console = "Striaght"
  59.         rs.setBundledOutput(sides.back, {[colors.red] = 0, [colors.green] = 200})
  60.         sleep(30)
  61.         rs.setBundledOutput(sides.back, {[colors.green] = 0})
  62.         sleep(3)
  63.         rs.setBundledOutput(sides.back, {[colors.blue] = 200})
  64.         sleep(1)
  65.  
  66.  
  67.  
  68.     end
  69.  
  70.   end)
  71.   thread.waitForAny({loop1, loop2})
Advertisement
Add Comment
Please, Sign In to add comment