Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bitwise = {0={false,false,false,false},1={false,false,false,true},2={false,false,true,false},3={false,false,true,true},4={false,true,false,false},5={false,true,false,true},6={false,true,true,false},7={false,true,true,true},8={true,false,false,false},9={true,false,false,true},10={true,false,true,false},11={true,false,true,true},12={true,true,false,false},13={true,true,false,true},14={true,true,true,false},15={true,true,true,true},} --#yeah this is ugly as sin, but I couldn't be bothered to program a bitwise comparator right now
- local currentout = {false, false, false, false}
- local function getRSBundleInput(side)
- local input={}
- for i, j in ipairs(bitwise[rs.getAnalogInput(side)]) do
- if j then input[#input+1]=i end
- end
- return input
- end
- local function setRSBundleOutput(side, value)
- value=value % 15 --#ignores colours bigger than light blue as they are not supported
- for i,j in ipairs(bitwise[value]) do
- if j~= currentout.i then --#only if the output is changing
- local output=i
- if j then output=output+8 end --#low outputs are set as 1-4, high outputs are 9-12
- rs.setAnalogOutput(side, output)
- currentout.i=j
- sleep(0.05)
- end
- end
- end
- --usage
- local inputs = getRSBundleInput("left") --#returns eg {1,3,4} if white, purple and lightblue are high
- setRSBundleOutput("right", colours.white+colours.orange) --#sets white and orange high, purple and lightblue low
Advertisement
Add Comment
Please, Sign In to add comment