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 thread = require("thread")
- local m = component.modem -- get primary modem component
- local sides = require("sides")
- local computer = require("computer")
- local colors = require("colors")
- m.setWakeMessage("start")
- m.broadcast(123, "on")
- os.sleep(1)
- m.open()
- local loop3 = thread.create(function()
- while true do
- local name, receiver, sender, port, distance, on = computer.pullSignal()
- if name == "modem_message" then
- if(on == "stop") then
- m.broadcast(123, 1,1,1 , "OFF")
- computer.shutdown(false)
- end
- if(on == "restart") then
- m.broadcast(123, 1,1,1 , "OFF")
- computer.shutdown(true)
- end
- end
- end
- end)
- term.clear()
- print("Traffic lights are starting! Lights are in flash mode")
- m.broadcast(123, colors.cyan, 200, sides.back)
- os.sleep(60);
- term.clear()
- print("Traffic lights are starting all lights are red!")
- m.broadcast(123, 3, 200, sides.back)
- os.sleep(1)
- m.broadcast(123, 3, 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
- local loop2 = thread.create(function()
- while true do
- time3 = os.date("*t")
- cycledtime = time3.hour .. ":" .. time3.min
- -- traffic light code here (this will be what is ran during its normal cycle)
- end
- end)
- thread.waitForAny({loop1, loop2})
Advertisement
Add Comment
Please, Sign In to add comment