Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Battery LCD display - Ramdor 2013 - v1.1
- -- Handles any number of tier1 or tier2 nuclear readers
- -- Handles any number of cards
- -- Outputs redstone signals on all unused faces (ie those without nuclear readers)
- --
- -- v1.1 - fix to redstone.setBundledOutput(side,nRed) derp
- -- v1.0 - release
- --
- -- You may edit/copy/redistribute/whatever this
- -- code in any way. Just a credit listing this
- -- pastebin link (pastebin.com/WhYwt813) will be fine :)
- --
- -- seems like the id for energy sensor location card
- -- changed to LSB 2. Swap the two following lines if cards are
- -- not found
- local sEnergySensorLocCardID = "00000000-0000-0000-0000-000000000002"
- -- local sEnergySensorLocCardID = "00000000-0000-0000-0000-000000000000"
- -- The number of leds to use
- -- maximum 16.
- local nTotalLeds = 12
- term.clear()
- term.setCursorPos(1,1)
- print("Battery Display - Ramdor 2013 - v1.0")
- print("CTRL-T to terminate")
- local nReaders = 0
- local nWait = 5
- local nrs = {}
- local nrSides = {}
- for i, side in pairs(rs.getSides()) do
- if peripheral.getType(side) == "nuclearReader" then
- table.insert(nrs, peripheral.wrap(side))
- nrSides[side] = true
- nReaders = nReaders + 1
- else
- nrSides[side] = false
- end
- end
- if (nReaders==0) then
- print("No readers found")
- do return end
- end
- local nr
- local nSlots
- local data
- local nMax
- local nEnergy
- local fPerc
- local nLeds
- local nRed
- local nCards
- local bRunning = true
- while(bRunning) do
- nMax = 0
- nEnergy = 0
- nCards = 0
- for i,nr in pairs(nrs) do
- nSlots = nr.getSlots()
- for n=1,nSlots do
- id,state,title,data = nr.get(n)
- if(id == sEnergySensorLocCardID) then
- nMax = nMax + tonumber(data["maxStorageL"])
- nEnergy = nEnergy + tonumber(data["energyL"])
- nCards = nCards + 1
- end
- end
- end
- if(nCards>0) then
- -- we found some cards
- fPerc = (nEnergy / nMax) * 100.0
- nLeds = math.floor((nEnergy / nMax) * nTotalLeds)
- nRed = (2 ^ nLeds) - 1
- -- output to all sides that do not have a nuclear reader
- for i, side in pairs(rs.getSides()) do
- if(not nrSides[side]) then
- redstone.setBundledOutput(side,nRed)
- end
- end
- term.setCursorPos(1,4)
- term.write(nEnergy.." eu of "..nMax.." eu ")
- term.setCursorPos(1,5)
- term.write(string.format("%06.2f ",fPerc).."% ")
- term.setCursorPos(1,6)
- term.write(nLeds.." leds ")
- os.sleep(nWait)
- else
- term.setCursorPos(1,4)
- term.write("No cards found ")
- term.setCursorPos(1,5)
- term.write(" ")
- term.setCursorPos(1,6)
- term.write(" ")
- os.sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement