FairfaxGamingYT

DDI

Aug 25th, 2024 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.70 KB | None | 0 0
  1. local component = require("component");
  2. local traffic = component.traffic_light_card
  3. local os = require("os")
  4. local thread = require("thread")
  5.  
  6. trafficLight = {}
  7. lightPOS = traffic.listBlockPos()
  8.  
  9. for i = 1, #lightPOS do
  10.   trafficLight[i] = lightPOS[i]
  11. end
  12.  
  13. function setLights(id,state,mode,forceClear)
  14.   -- F is the boolean for Flashing, S is the boolean for Steady/On
  15.   local f = false
  16.   local s = false
  17.  
  18.   --  Clear signal if flag to forceClear isn't set to false
  19.   if forceClear ~= false then
  20.     if (type(id) == "table") then
  21.       for itr = 1, #id do
  22.         traffic.clearStates(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3])
  23.       end
  24.     elseif (type(id) == "string") then
  25.       traffic.clearStates(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3])
  26.     end
  27.   end
  28.  
  29.   --  Determine mode
  30.   if mode ~= nil then
  31.     --    Flashing
  32.     if string.lower(mode) == "flashing" then
  33.       s = true
  34.       f = true
  35.     --   Steady
  36.     elseif string.lower(mode) == "on" then
  37.       s = true
  38.       f = false
  39.       --    Off
  40.     else
  41.       s = false
  42.       f = false
  43.     end
  44.   else
  45.     s = false
  46.     f = false
  47.   end
  48.  
  49.   --  Apply to signal
  50.   if (type(id) == "table" and state ~= nil) then
  51.     for itr = 1, #id do
  52.       traffic.setState(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3],state,s,f)
  53.     end
  54.  
  55.   elseif (type(id) == "string" and state ~= nil) then
  56.     traffic.setState(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3],state,s,f)
  57.   end
  58. end
  59.  
  60. -- first pase
  61. local left = {1,2,3,4}
  62. local striaght = {5,6,7,8,8,10,11}
  63. -- second pase
  64. local right = {12,13,14,15}
  65. local stragt2 = {16,17,18,19}
  66.  
  67. setLights(left, "RedArrowLeft", "on")
  68. setLights(striaght, "Red", "on")
  69. setLights(right, "RedArrowRight", "on")
  70. setLights(stragt2, "Red", "on")
  71. local loop2 = thread.create(function()
  72.     while true do
  73.      
  74.  
  75.         print("DDI @ US 65 & SR 248 P1")
  76.         setLights(left, "GreenArrowLeft", "on")
  77.         setLights(striaght, "Green", "on")
  78.         os.sleep(30)
  79.         setLights(left, "YellowArrowLeft", "on")
  80.         setLights(striaght, "Yellow", "on")
  81.         os.sleep(3)
  82.         setLights(left, "RedArrowLeft", "on")
  83. setLights(striaght, "Red", "on")
  84.         os.sleep(1)
  85.         print("DDI @ US 65 & SR 248 P2")
  86.         setLights(right, "GreenArrowRight", "on")
  87.         setLights(stragt2, "Green", "on")
  88.         os.sleep(30)
  89.         setLights(right, "YellowArrowRight", "on")
  90.         setLights(stragt2, "Yellow", "on")
  91.         os.sleep(3)
  92.         setLights(right, "RedArrowRight", "on")
  93. setLights(stragt2, "Redw", "on")
  94.         os.sleep(1)
  95.  
  96.  
  97.  
  98.  
  99.  
  100.     end
  101.  
  102.   end)
  103.   thread.waitForAny({loop2})
  104.  
  105.  
Advertisement
Add Comment
Please, Sign In to add comment