Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component");
- local redlight = component.traffic_light_card;
- local os = require("os")
- local term = require("term")
- local sides = require("sides")
- local colors = require("colors")
- local thread = require("thread")
- -- cords
- function sleep(n)
- os.sleep(n)
- end
- local rampOn = "False"
- local lastState = "off"
- console = "East Left"
- time = os.date("*t")
- cycledtime = time.hour .. ":" .. time.min
- function start()
- redlight.setState(-1336, 64, -582, "Green", true, false) --3
- redlight.setState(-1328, 68, -585, "Green", true, false)-- 4
- sleep(3)
- redlight.setState(-1336, 64, -582, "Green", false, false) --6
- redlight.setState(-1328, 68, -585, "Green", false, false) -- 4
- redlight.setState(-1336, 64, -582, "Yellow", true, false) -- 3
- redlight.setState(-1328, 68, -585, "Yellow", true, false) -- 4
- sleep(2)
- redlight.setState(-1336, 64, -582, "Yellow", false, false) --3
- redlight.setState(-1328, 68, -585, "Yellow", false, false) --4
- redlight.setState(-1336, 64, -582, "Red", true, false) --3
- redlight.setState(-1328, 68, -585, "Red", true, false) --4
- redlight.setState(-1336, 65, -582, "Red", true, false) --5
- sleep(1)
- lastState = "on"
- end
- 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("Ramps Are " .. lastState);
- if(time2.hour == 6) or (time2.hour == 7) or (time2.hour == 8) or (time2.hour == 18) or (time2.hour == 19) or (time2.hour == 20) then
- print("2")
- if (rampOn == "False") then
- print("3")
- rampOn = "True"
- redlight.setState(-1388, 70, -586, "Yellow", true, true) -- 1
- redlight.setState(-1387, 70, -585, "Yellow", true, true) -- 2
- start()
- end
- else
- print("4")
- if(rampOn == "True") then
- print("66")
- print("ok")
- rampOn = "False"
- redlight.setState(-1387, 70, -585, "Yellow", false, true) -- 1
- redlight.setState(-1387, 70, -585, "Yellow", false, true) -- 2
- end
- print("5")
- end
- sleep(1)
- end
- end)
- function checkTime(time)
- print("1")
- print("end")
- end
- function running()
- print("1")
- end
- local loop2 = thread.create(function()
- while true do
- time3 = os.date("*t")
- cycledtime = time3.hour .. ":" .. time3.min
- if(rampOn == "True") and (lastState == "on") then
- print("2")
- redlight.setState(-1336, 64, -582, "Red", false, false) --3
- redlight.setState(-1328, 68, -585, "Red", false, false) --4
- redlight.setState(-1336, 65, -582, "Red", false, false) --5
- redlight.setState(-1336, 64, -582, "Green", true, false) --3
- redlight.setState(-1328, 68, -585, "Green", true, false) --4
- sleep(0.5)
- redlight.setState(-1336, 64, -582, "Green", false, false) --3
- redlight.setState(-1328, 68, -585, "Green", false, false) --4
- redlight.setState(-1336, 64, -582, "Red", true, false) --3
- redlight.setState(-1328, 68, -585, "Red", true, false) --4
- redlight.setState(-1336, 65, -582, "Red", true, false) --5
- sleep(3)
- else
- if(rampOn == "False") and (lastState == "on") then
- redlight.clearStates(-1336, 64, -582) --3
- redlight.clearStates(-1328, 68, -585) --4
- redlight.clearStates(-1336, 65, -582) --5
- redlight.clearStates(-1336, 65, -582) --1
- redlight.clearStates(-1336, 65, -582) --2
- lastState = "off"
- end
- sleep(1)
- end
- sleep(1)
- end
- end)
- thread.waitForAny({loop1, loop2})
Advertisement
Add Comment
Please, Sign In to add comment