Advertisement
giwdul

receive_data_reactor_CC

Jul 8th, 2023 (edited)
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. -- Receive data from send_data_reactor_CC and display it on a monitor
  2.  
  3. local modem = peripheral.wrap("left")
  4. local mon = peripheral.wrap("back")
  5. local maxPower = 150000 -- Votre puissance maximale
  6.  
  7. local gaugeWidth = 3 -- Largeur de la jauge en blocs
  8. local gaugeMargin = 1 -- Marge en haut et en bas de la jauge
  9. local width, height = mon.getSize() -- Taille totale de l'écran
  10.  
  11. while true do
  12.     rednet.open("left")
  13.     local senderID, power, protocol = rednet.receive()
  14.     rednet.close("left")
  15.  
  16.     -- Nettoie la zone de la jauge
  17.     mon.setBackgroundColor(colors.gray)
  18.     for i = 1, height do
  19.         mon.setCursorPos((width - gaugeWidth) / 2 + 1, i)
  20.         mon.write(string.rep(" ", gaugeWidth))
  21.     end
  22.  
  23.     -- Calcul de la taille de la jauge
  24.     local gaugeHeight = math.floor((power / maxPower) * (height - 2 * gaugeMargin))
  25.  
  26.     -- Affiche la jauge
  27.     mon.setBackgroundColor(colors.green)
  28.     for i = 1, gaugeHeight do
  29.         mon.setCursorPos((width - gaugeWidth) / 2 + 1, height - gaugeMargin - i + 1)
  30.         mon.write(string.rep(" ", gaugeWidth))
  31.     end
  32.  
  33.     -- Affiche les valeurs
  34.     mon.setCursorPos((width - string.len("Max: " .. maxPower)) / 2 + 1, gaugeMargin) -- Positionne le texte au-dessus de la jauge
  35.     mon.setBackgroundColor(colors.black)
  36.     mon.setTextColor(colors.white)
  37.     mon.write("Max: " .. maxPower)
  38.     mon.setCursorPos((width - string.len("Current: " .. power)) / 2 + 1, height - gaugeMargin + 1) -- Positionne le texte en dessous de la jauge
  39.     mon.write("Current: " .. power)
  40. end
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement