Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- SimpleRednetRedstone by thatParadox
- -- www.youtube.com/thatparadox
- --
- --
- -- Designed for elevators but could be useful for all sorts of creations. This program let's you select from a list on an Advanced Monitor which computer you would like to activate a redstone signal. It works Wirelessly using Rednet.
- --
- -- Installation:
- -- Place an Advanced Computer and attach a Wireless Modem and, if you want one, an Advanced Monitor.
- -- Copy and paste into the computer: pastebin get f9T5ee5S startup
- -- Press: Enter
- -- Push and hold CRTL + R until computer reboots.
- -- Computer will ask you "Which level is this?". Enter a number that when pressed on the Monitor will activate the redstone output on this computer.
- --
- -- Notes:
- -- Only one computer at a time will emit the redstone signal.
- -- Computer will emit redstone on all sides
- -- program will automatically detect your monitor and modem.
- -- You don't have to have a monitor attached if you only want the computer to receive signals but it will need a wireless modem
- -- The red number on the monitor is the computer that is currently emitting the redstone
- -- The number surrounded by > and < is the number of this computer
- -- You can change the rednet protocol if already in use by changing the number below in RedProtoc
- RedProtoc = 42 -- change to use different rednet protocol
- -- Detects Monitor
- mon = peripheral.find("monitor")
- --Detects Modem
- for k,v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "modem" then
- rednet.open(v)
- end
- end
- -- Draws the background image on the monitor
- function drawBackground()
- if mon ~= nil then
- mon.setBackgroundColor(colors.black)
- mon.clear()
- x,y = mon.getSize()
- for yc = 1,y do
- if yc%2 == 1 then
- mon.setBackgroundColor(colors.yellow)
- else
- mon.setBackgroundColor(colors.lightGray)
- end
- for xc = 2,x-1 do
- mon.setCursorPos(xc, yc)
- mon.write(" ")
- end
- mon.setCursorPos(x/2,yc)
- end
- end
- end
- -- Draws the numbers on the Monitor
- function drawButtons()
- if mon ~= nil then
- x,y = mon.getSize()
- for i=1,y do
- if i%2 == 1 then
- mon.setBackgroundColor(colors.yellow)
- else
- mon.setBackgroundColor(colors.lightGray)
- end
- mon.setTextColor(colors.black)
- if tonumber(isActive) ~= nil and tonumber(isActive) == i then
- mon.setTextColor(colors.red)
- end
- mon.setCursorPos(x/2+1, i)
- mon.write( tostring(i) )
- end
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(1, tonumber(level))
- mon.write(">")
- mon.setCursorPos(x, tonumber(level))
- mon.write("<")
- end
- end
- -- Makes the button flash when pressed
- function buttonSelect(buttonPosY)
- if mon ~= nil then
- x,y = mon.getSize()
- mon.setBackgroundColor(colors.gray)
- for xc = 2,x-1 do
- mon.setCursorPos(xc, param3)
- mon.write(" ")
- end
- mon.setTextColor(colors.orange)
- mon.setCursorPos(x/2+1, buttonPosY)
- mon.write(tostring(buttonPosY))
- sleep(0.3)
- drawBackground()
- drawButtons()
- end
- end
- -- Makes redstone signal activate or deactivate on all sides
- function rsAllSides(state)
- for k,v in pairs(rs.getSides()) do
- rs.setOutput(v, state)
- end
- end
- if fs.exists("level") == false then --checks for if the level has been defined yet
- print("Which level is this?")
- write("> ")
- level = read()
- term.clear()
- term.setCursorPos(1,1)
- file = fs.open("level", "w")
- file.write(level)
- file.close()
- else
- file = fs.open("level", "r")
- level = file.readAll()
- file.close()
- end
- if fs.exists("isActive") then -- Checks if there should be an active redstone signal
- file = fs.open("isActive","r")
- isActive = tostring(file.readAll())
- file.close()
- if tonumber(isActive) == tonumber(level) then
- rsAllSides(true)
- else
- rsAllSides(false)
- end
- end
- drawBackground()
- drawButtons()
- while true do
- event, param1, param2, param3 = os.pullEvent()
- if event == "rednet_message" and tonumber(param3) == RedProtoc then -- Rednet message received
- if tonumber(param2) == tonumber(level) then -- checks if message was for this computer to activate redstone
- rsAllSides(true)
- isActive = level
- else -- turns off redstone if message was not for this computer
- rsAllSides(false)
- isActive = param2
- end
- elseif event == "monitor_touch" then -- Monitor has been touched
- if tonumber(param3) == tonumber(level) then -- checks if this computer was selected by monitor touch to activate redstone
- rsAllSides(true)
- rednet.broadcast(param3,RedProtoc)
- else -- turns off redstone if this computer wasn't selected by Monitor Touch and broadcasts the selected number
- rsAllSides(false)
- rednet.broadcast(param3,RedProtoc)
- end
- isActive = param3
- buttonSelect(param3)
- end
- drawBackground()
- drawButtons()
- file = fs.open("isActive", "w") -- writes selected floor to a file in case there is a reboot
- file.write(isActive)
- file.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement