Advertisement
Justin_P69

Testprogram

Aug 27th, 2023
1,611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. -- Replace these with the actual monitor and modem addresses
  2. local monitorAddress = "right"
  3. local modemAddress = "left"
  4.  
  5. local monitor = peripheral.wrap(monitorAddress)
  6. local computerID = os.getComputerID()
  7.  
  8. function drawProgressBar(x, y, percentage)
  9.     monitor.setCursorPos(x, y)
  10.     monitor.setBackgroundColor(colors.white)
  11.     monitor.clearRow(y)
  12.     monitor.setBackgroundColor(colors.blue)
  13.     local width = math.floor(percentage / 100 * (monitor.getSize()))
  14.     monitor.setCursorPos(x, y)
  15.     monitor.write(string.rep(" ", width))
  16.     monitor.setBackgroundColor(colors.white)
  17. end
  18.  
  19. function readRFAndDisplay()
  20.     while true do
  21.         local energyInfo = peripheral.call(modemAddress, "getEnergyInfo")
  22.         if energyInfo then
  23.             local rfPercentage = math.floor((energyInfo.energyStored / energyInfo.maxEnergyStored) * 100)
  24.             monitor.clear()
  25.             drawProgressBar(1, 1, rfPercentage)
  26.             monitor.setCursorPos(1, 2)
  27.             monitor.setTextColor(colors.black)
  28.             monitor.write("RF: " .. rfPercentage .. "%")
  29.         end
  30.         sleep(5)
  31.     end
  32. end
  33.  
  34. -- Main program
  35. monitor.setBackgroundColor(colors.white)
  36. monitor.clear()
  37. monitor.setTextScale(1)
  38. readRFAndDisplay()
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement