Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wireless Redstone by Islanderon
- -- Version 1.0.2
- -- WARNING: Requires the WR api to be named 'wr'.
- local function openRednet()
- local listOfSides = rs.getSides()
- local listofPossibles = {}
- local counter1 = 0
- while true do
- counter1 = counter1 +1
- if peripheral.isPresent(tostring(listOfSides[counter1])) and peripheral.getType(listOfSides[counter1]) == "modem" then
- table.insert(listofPossibles,tostring(listOfSides[counter1]))
- end
- if counter1 == 6 and table.maxn(listofPossibles) == 0 then
- print("no wifi present")
- return nil
- end
- if counter1 == 6 and table.maxn(listofPossibles) ~= 0 then
- rednet.open(listofPossibles[1])
- return listofPossibles[1]
- end
- end
- end
- function fromboolean(input)
- if input == true then
- return "true"
- else
- return "false"
- end
- end
- function toboolean(input)
- if input == "true" then
- return true
- else
- return false
- end
- end
- function find(str, match, startIndex) --Finds @match in @str optionally after @startIndex
- if not match then return nil end
- str = tostring(str)
- local _ = startIndex or 1
- local _s = nil
- local _e = nil
- local _len = match:len()
- while true do
- local _t = str:sub( _ , _len + _ - 1)
- if _t == match then
- _s = _
- _e = _ + _len - 1
- break
- end
- _ = _ + 1
- if _ > str:len() then break end
- end
- if _s == nil then return nil else return _s, _e end
- end
- function seperate(str, divider) -- Seperate function by tommas
- if not divider then return nil end
- str = tostring(str)
- local start = {}
- local endS = {}
- local n=1
- repeat
- if n==1 then
- start[n], endS[n] = find(str, divider)
- else
- start[n], endS[n] = find(str, divider, endS[n-1]+1)
- end
- n=n+1
- until start[n-1]==nil
- local subs = {}
- for n=1, #start+1 do
- if n==1 then
- subs[n] = str:sub(1, start[n]-1)
- elseif n==#start+1 then
- subs[n] = str:sub(endS[n-1]+1)
- else
- subs[n] = str:sub(endS[n-1]+1, start[n]-1)
- end
- end
- return subs
- end
- openRednet()
- valid = 0
- function runprogram()
- term.clear()
- term.setCursorPos(1,1)
- if valid == 1 then
- print "Invalid Choice"
- end
- print "Pick One:"
- print "[1] Sender"
- print "[2] Receiver"
- print ""
- event, choice = os.pullEvent()
- if event == "key" and choice == 2 then -- Sending
- write "Frequency: "
- freq = io.read()
- term.clear()
- term.setCursorPos(1,1)
- print ("Now sending redstone input to frequency "..freq..", hold CTRL-T to end.")
- while true do
- os.pullEvent("redstone")
- states = {redstone.getInput("left"), redstone.getInput("right"), redstone.getInput("back"), redstone.getInput("front"), redstone.getInput("top"), redstone.getInput("bottom")}
- wr.sendState(freq, "left", states[1])
- wr.sendState(freq, "right", states[2])
- wr.sendState(freq, "back", states[3])
- wr.sendState(freq, "front", states[4])
- wr.sendState(freq, "top", states[5])
- wr.sendState(freq, "bottom", states[6])
- print ("SENT: Redstone change")
- end
- elseif event == "key" and choice == 3 then -- Receiving
- write "Frequency: "
- freq = io.read()
- term.clear()
- term.setCursorPos(1,1)
- print ("Now receiving data on frequency "..freq..", hold CTRL-T to end.")
- while true do
- rec = wr.recState(freq, true)
- rec[2] = fromboolean(rec[2])
- print (rec[1].." : "..rec[2])
- end
- else
- valid = 1
- runprogram()
- end
- end
- runprogram()
Add Comment
Please, Sign In to add comment