Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("top")
- local mon = peripheral.wrap("bottom")
- local monX, monY = mon.getSize()
- modem.open(2)
- function roundTo(number, scale)
- local num = number
- for i=0,scale do
- num = num * 10
- end
- num = math.floor(num)
- for i=0,scale do
- num = num / 10
- end
- return num
- end
- function numberToText(number)
- local num = tonumber(number)
- if num == nil then return "nil" end
- if num >= 1000000000000 then return (roundTo((num/1000000000000), 2) .. " T") end
- if num >= 1000000000 then return (roundTo((num/1000000000), 2) .. " G") end
- if num >= 1000000 then return (roundTo((num/1000000), 2) .. " M") end
- if num >= 1000 then return (roundTo((num/1000), 2) .. " k") end
- end
- function draw(data)
- mon.clear()
- mon.setTextScale(3)
- local stockedEnergy = numberToText(data["en"])
- mon.setCursorPos(math.floor(monX / 2 - string.len(stockedEnergy) / 2), 1)
- mon.setTextColor(colors.lime)
- mon.write(stockedEnergy .. " RF")
- local producedEnergy = numberToText(data["enPT"])
- mon.setCursorPos(math.floor(monX / 2 - string.len(producedEnergy) / 2), 2)
- mon.setTextColor(colors.yellow)
- mon.write(producedEnergy .. " RF/t")
- end
- while true do
- modem.transmit(1,2,"getEnergy")
- local event, mS, sC, rC,
- data, sD = os.pullEvent("modem_message")
- print(data["en"] .. " - " .. data["enPT"])
- draw(data)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement