Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ========================
- -- == redtest
- -- ========================
- -- -------------------
- -- getIOAll
- -- -------------------
- function dumpIOAll()
- sides = {"front", "back", "top", "bottom", "left", "right"}
- i_rslt = ""
- o_rslt = ""
- for i, s in ipairs(sides) do
- i_rslt = i_rslt .. string.format("%2d", rs.getAnalogInput(s))
- o_rslt = o_rslt .. string.format("%2d", rs.getAnalogOutput(s))
- end
- print("[fbudlr]/in[" .. i_rslt .. "]/out[" .. o_rslt .. "]")
- end
- -- -------------------
- -- setOffAll
- -- -------------------
- function setOffAll()
- sides = {"front", "back", "top", "bottom", "left", "right"}
- for i, s in ipairs(sides) do
- rs.setOutput(s, false)
- rs.setAnalogOutput(s, 0)
- end
- end
- -- -------------------
- -- setOnAll
- -- -------------------
- function setOnAll()
- sides = {"front", "back", "top", "bottom", "left", "right"}
- for i, s in ipairs(sides) do
- rs.setOutput(s, true)
- rs.setAnalogOutput(s, 15)
- end
- end
- -- -------------------
- -- key_tbl
- -- -------------------
- key_tbl = {}
- key_tbl[keys.f] = { dir="front" , side="front" }
- key_tbl[keys.b] = { dir="back" , side="back" }
- key_tbl[keys.u] = { dir="top(up)" , side="top" }
- key_tbl[keys.d] = { dir="bottom(down)", side="bottom" }
- key_tbl[keys.l] = { dir="left" , side="left" }
- key_tbl[keys.r] = { dir="right" , side="right" }
- -- -------------------
- -- output_tbl
- -- -------------------
- tmp_tbl = {
- "zero","one","two","three","four","five","six","seven","eight","nine",
- "a","b","c","d","e","f" }
- output_tbl = {}
- for i, v in ipairs(tmp_tbl) do
- output_tbl[v] = { digital=false, analog= i-1 }
- end
- output_tbl.f.digital = true
- -- -------------------
- -- main
- -- -------------------
- dumpIOAll()
- while true do
- local event, p1 = os.pullEvent()
- if "redstone" == event then
- dumpIOAll()
- elseif "key" == event then
- if nil ~= key_tbl[p1] then
- print("output for " .. key_tbl[p1].dir)
- term.write("(0-9 a-f (x->all[0] z->all[15] other->cancel)>")
- _, key = os.pullEvent("key")
- key_char = keys.getName(key)
- if "x" == key_char then
- setOffAll()
- dumpIOAll()
- elseif "z" == key_char then
- setOnAll()
- dumpIOAll()
- elseif nil ~= output_tbl[key_char] then
- pressed_key = output_tbl[key_char]
- rs.setOutput (key_tbl[p1].side, pressed_key.digital)
- rs.setAnalogOutput(key_tbl[p1].side, pressed_key.analog )
- dumpIOAll()
- else
- print("cancelled")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement