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 term = require("term")
- local thread = require("thread")
- -- local m = component.modem -- get primary modem component
- local sides = require("sides")
- local computer = require("computer")
- local colors = require("colors")
- -- m.broadcast(455, "on")
- os.sleep(1)
- 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) == "flashing" 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
- term.clear()
- -- print("Traffic lights are starting! Lights are in flash mode")
- -- m.broadcast(455, colors.red, 200, sides.back)
- -- os.sleep(60);
- -- term.clear()
- -- print("Traffic lights are starting all lights are red!")
- -- m.broadcast(455, colors.green, 200, sides.back)
- -- os.sleep(1)
- -- m.broadcast(455, colors.green, 0, sides.back)
- -- os.sleep(8)
- function sleep(n)
- os.sleep(n)
- end
- console = "East Left"
- time = os.date("*t")
- cycledtime = time.hour .. ":" .. time.min
- local loop1 = thread.create(function()
- while true do
- time2 = os.date("*t")
- term.clear()
- print("Time Cycled: " .. cycledtime)
- print("Current Time: " .. time2.hour .. ":" .. time2.min)
- print("energy:" .. computer.energy())
- -- if(computer.energy() <= 1489) then
- -- m.broadcast(123, 1,1,1 , "OFF")
- -- sleep(1)
- -- computer.shutdown(false)
- -- end
- sleep(1)
- end
- end)
- -- function setBundledOutput(color, state)
- -- m.broadcast(123, color, state, sides.back)
- -- end
- HAWK = {1,2,3,4,5,6,7,8,9}
- Fire = {10,11,12,12}
- Warning = {13,14}
- local loop2 = thread.create(function()
- while true do
- setLights(HAWK, "Yellow", "flashing")
- os.sleep(5)
- setLights(Warning, "Yellow", "flashing")
- setLights(HAWK, "Yellow", "on")
- os.sleep(3)
- setLights(HAWK, "Red", "on")
- setLights(Fire, "Green", "on")
- os.sleep(10)
- setLights(Fire, "Yellow", "on")
- os.sleep(3)
- setLights(Fire, "Yellow", "flashing")
- setLights(HAWK, "Red", "flashing")
- os.sleep(10)
- setLights(Warning, "Yellow", "off")
- end
- end)
- thread.waitForAny({loop2})
Advertisement
Add Comment
Please, Sign In to add comment