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()
- mon.setBackgroundColor(colors.white)
- mon.setTextColor(colors.gray)
- modem.open(2)
- function roundTo(number, scale)
- local num = number
- for i=1,scale do
- num = num * 10
- end
- num = math.floor(num)
- for i=1,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
- if num >= 0 then return (rountTo(num, 2)) end
- if num <= -1000 then return ("-" .. roundTo(((0-num) / 1000), 2) .. " k") end
- if num <= -1000000 then return ("-" .. roundTo(((0-num) / 1000000), 2) .. " M") end
- if num <= -1000000000 then return ("-" .. roundTo(((0-num) / 1000000000), 2) .. " G") end
- if num <= -1000000000000 then return ("-" .. roundTo(((0-num) / 1000000000000), 2) .. " T") end
- end
- function draw(data)
- mon.clear()
- mon.setTextScale(3)
- local stockedEnergy = numberToText(data["en"]) .. " RF"
- mon.setCursorPos(math.floor((monX / 2) - (string.len(stockedEnergy) / 2)), 1)
- mon.write(stockedEnergy)
- local producedEnergy = numberToText(data["enPT"]) .. " RF/t"
- mon.setCursorPos(math.floor((monX / 2) - (string.len(producedEnergy) / 2)), 2)
- mon.write(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(data)
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement