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 >= 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(monX / 2 - stockedEnergy.length() / 2, 1)
- mon.write(numberToText(stockedEnergy))
- local producedEnergy = numberToText(data["enPT"])
- mon.setCursorPos(monX / 2 - producedEnergy.length() / 2, 2)
- mon.write(numberToText(producedEnergy))
- 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()
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement