Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component");
- local traffic = component.traffic_light_card
- local os = require("os")
- local thread = require("thread")
- local sides = require("sides")
- local computer = require("computer")
- -- Warning this script contains bulbs from a custom edited version of traffic control to use this script fine Left2 and Right2 for yellows and remove the 2 from that and it will work
- local colors = require("colors")
- local rs = component.redstone
- function setBundledOutput(color, state)
- rs.setBundledOutput(sides.back, {[color] = state})
- end
- function getBundledoutput(color)
- return rs.getBundledInput(sides.back, color);
- end
- setBundledOutput(colors.white, 200)
- trafficLight = {}
- lightPOS = traffic.listBlockPos()
- for i = 1, #lightPOS do
- trafficLight[i] = lightPOS[i]
- end
- function setLights(id,state,mode,forceClear)
- -- F is the boolean for Flashing, S is the boolean for Steady/On
- local f = false
- local s = false
- -- Clear signal if flag to forceClear isn't set to false
- if forceClear ~= false then
- if (type(id) == "table") then
- for itr = 1, #id do
- traffic.clearStates(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3])
- end
- elseif (type(id) == "string") then
- traffic.clearStates(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3])
- end
- end
- -- Determine mode
- if mode ~= nil then
- -- Flashing
- if string.lower(mode) == "flash" then
- s = true
- f = true
- -- Steady
- elseif string.lower(mode) == "on" then
- s = true
- f = false
- -- Off
- else
- s = false
- f = false
- end
- else
- s = false
- f = false
- end
- -- Apply to signal
- if (type(id) == "table" and state ~= nil) then
- for itr = 1, #id do
- traffic.setState(trafficLight[id[itr]][1],trafficLight[id[itr]][2],trafficLight[id[itr]][3],state,s,f)
- end
- elseif (type(id) == "string" and state ~= nil) then
- traffic.setState(trafficLight[id][1],trafficLight[id][2],trafficLight[id][3],state,s,f)
- end
- end
- -- key
- -- S Stright
- -- Y stright bulb
- -- T Turn Bulb
- -- L Left
- -- R Right
- -- Middle Frame
- -- north 1 LT, 2 YS , 3 YS , 4 RT
- -- south 5 LT, 6 YS, 7 YS , 8 RT
- -- east 9 L , 10 ML , 11 MR,12 R
- -- west 13 L, 14 R
- -- first phase
- local northbound = {1,2,3,4,5,6}
- -- second phase
- local southbound = {7,8,9,10}
- -- third phase
- local westbound = {11,12,13,14}
- local eastbound = {15,16,17}
- os.sleep(60)
- -- start script
- setBundledOutput(colors.cyan, 200)
- os.sleep(8)
- local loop2 = thread.create(function()
- while true do
- print("_______ Village Intersection")
- -- phase 1 sl&ss
- setLights (northbound, "GreenArrowLeft", "on")
- setLights (northbound, "GreenArrowRight", "on")
- os.sleep (10)
- setLights (northbound, "YellowArrowLeft", "on")
- setLights (northbound, "YellowArrowRight", "on")
- os.sleep (3)
- setLights (northbound, "RedArrowLeft", "on")
- setLights (northbound, "RedArrowRight", "on")
- os.sleep (2)
- -- phase 2 sl&ss
- setLights (southbound, "Green", "on")
- setLights (southbound, "GreenArrowLeft", "on")
- os.sleep (10)
- setLights (southbound, "Yellow", "on")
- setLights (southbound, "YellowArrowLeft" "on")
- os.sleep (3)
- setLights (southbound, "Red", "on")
- setLights (southbound, "RedLeftArrow" "on)
- os.sleep (2)
- -- phase 3 sl&ss
- setLights (westbound, "Green", "on")
- setLights (westbound, "GreenArrowLeft", "on")
- os.sleep (10)
- setLights (westbound, "YellowArrowLeft", "on")
- os.sleep (3)
- setLights (eastbound, "Green", "on")
- os.sleep (10)
- setLights (eastbound, "Yellow", "on")
- os.sleep (3)
- setLights (eastbound, "Red", "on")
- os.sleep (2)
- end
- end)
- thread.waitForAny({loop2})
Advertisement
Add Comment
Please, Sign In to add comment