scarlabeboy

conso test ia

Sep 5th, 2025 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. local deviceName = "fluxnetworks:flux_plug_2" -- adapte avec le nom exact
  2. local plug = peripheral.wrap(deviceName)
  3. local monitor = peripheral.find("monitor")
  4.  
  5. if not plug or not monitor then
  6.   print("Périphérique ou écran non détecté")
  7.   return
  8. end
  9.  
  10. monitor.clear()
  11. monitor.setTextScale(1)
  12.  
  13. local previousEnergy = plug.getEnergy()
  14. local delay = 5 -- secondes entre chaque mesure
  15.  
  16. while true do
  17.   local currentEnergy = plug.getEnergy()
  18.   local capacity = plug.getEnergyCapacity()
  19.  
  20.   local energyChange = currentEnergy - previousEnergy
  21.   previousEnergy = currentEnergy
  22.  
  23.   local consumption = -energyChange / delay -- consommation approximative (RF/s)
  24.  
  25.   monitor.clear()
  26.   monitor.setCursorPos(1,1)
  27.   monitor.write("Flux Plug Energy Monitor")
  28.  
  29.   monitor.setCursorPos(1,3)
  30.   monitor.write(string.format("Energie: %d / %d RF", currentEnergy, capacity))
  31.  
  32.   monitor.setCursorPos(1,5)
  33.   monitor.write(string.format("Consommation: %.2f RF/s", consumption))
  34.  
  35.   os.sleep(delay)
  36. end
  37.  
Advertisement
Add Comment
Please, Sign In to add comment