Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- local modem = peripheral.find("modem")
- if not monitor then
- print("Erreur: Moniteur non trouvé.")
- return
- end
- if not modem then
- print("Erreur: Modem non trouvé.")
- return
- end
- rednet.open(peripheral.getName(modem))
- monitor.setTextScale(1)
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- local function displayStatsOnMonitor()
- while true do
- local senderId, stats, protocol = rednet.receive("powah")
- if protocol == "powah" then
- local energyStored = stats.energyStored
- local energyCapacity = stats.energyCapacity
- local energyPercent = stats.energyPercent
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.setTextColor(colors.white)
- monitor.write("Cellule d'Énergie Powah\n")
- monitor.write("---------------------------------------------\n")
- monitor.write("Énergie Stockée: " ..
- energyStored .. " / " .. energyCapacity .. " FE (" .. energyPercent .. "%)\n")
- local barWidth = 20
- local barFill = math.floor(barWidth * (energyStored / energyCapacity))
- local barEmpty = barWidth - barFill
- monitor.setCursorPos(1, 4)
- monitor.write("Energie: ")
- monitor.setBackgroundColor(colors.green)
- monitor.write(string.rep(" ", barFill))
- monitor.setBackgroundColor(colors.red)
- monitor.write(string.rep(" ", barEmpty))
- monitor.setBackgroundColor(colors.black)
- monitor.setCursorPos(1, 6)
- monitor.write(energyStored .. " RF (" .. energyPercent .. "%)")
- end
- sleep(1)
- end
- end
- displayStatsOnMonitor()
Advertisement
Add Comment
Please, Sign In to add comment