xo33ab

receiver

Dec 2nd, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. local m = peripheral.find("monitor")
  2. local side_bundle = ("front")
  3.  
  4. local t = {
  5.     purple = {
  6.         desc = "Purple ",
  7.         side = "right",
  8.         flux_level = 0,
  9.         flux_max = 7,
  10.         output = colours.purple, -- used for bundle
  11.         enderio_output = pink
  12.     },
  13.  
  14.     lime = {
  15.         desc = "Lime   ",
  16.         side = "bottom",
  17.         flux_level = 0,
  18.         flux_max = 7,
  19.         output = colours.lime, --
  20.         enderio_output = cyan
  21.     },
  22.  
  23.     orange = {
  24.         desc = "Orange ",
  25.         side = "left",
  26.         flux_level = 0,
  27.         flux_max = 7,
  28.         output = colours.orange, --
  29.         enderio_output = yellow
  30.     },
  31.  
  32.     brown = {
  33.         desc = "Central",
  34.         side = "top",
  35.         flux_level = 0,
  36.         flux_max = 5,
  37.         output = colours.brown, --
  38.         enderio_output = black
  39.     }
  40. }
  41.  
  42. ---------------------------
  43. --Rednet sender, receiver
  44. ---------------------------
  45. peripheral.find("modem",rednet.open)
  46.  
  47. local function receiveTable()
  48.     id, msg = rednet.receive()
  49.     t = textutils.unserialise(msg)
  50.     print("Rednet received")
  51. end
  52.  
  53.  
  54. ---------------------------
  55. --Monitor related stuff
  56. ---------------------------
  57. --term.redirect(m)
  58.  
  59. local monitors = {peripheral.find("monitor")}
  60.  
  61.  
  62. m.setCursorPos(0,0)
  63. m.setBackgroundColor(colors.black)
  64. m.setTextColor(colors.white)
  65. m.clear()
  66. m.setTextScale(3)
  67.  
  68.  
  69. ----------------------------
  70. --Prints Table for debugging
  71. ----------------------------
  72. local function printTable(e)
  73.     if type(e) == "table" then
  74.         for k,v in pairs(e) do
  75.             print(k,v)
  76.             printTable(v)       -- recursively repeat the same procedure
  77.             sleep(2)
  78.         end
  79.     else
  80.     end
  81. end
  82.  
  83. ---------------------------
  84. --Updates table
  85. ---------------------------
  86. local function getUpdate()
  87.     for k,v in pairs(t) do
  88.     v.flux_level = rs.getAnalogInput(v.side)
  89.     end
  90. end
  91.  
  92. ---------------------------
  93. --Emits bundled redstone when flux max is exceeded
  94. ---------------------------
  95. local function stopProduction()
  96.     for k,v in pairs(t) do
  97.         sleep(0)
  98.         if v.flux_level >= v.flux_max then
  99.         rs.setBundledOutput(side_bundle,colours.combine(rs.getBundledOutput("front"),v.output))
  100.         rs.setAnalogOutput(v.side,1)
  101.         print("Stoped:", v.desc, v.flux_level)
  102.         else
  103.         sleep(0)
  104.         rs.setBundledOutput(side_bundle,colours.subtract(rs.getBundledOutput("front"), v.output))
  105.         rs.setAnalogOutput(v.side,0)
  106.         print("Good")
  107.         end
  108.     end
  109. end
  110.  
  111. ---------------------------
  112. --Visual table
  113. ---------------------------
  114. local w = 0
  115. local h = 0
  116.  
  117. local function displayFlux()
  118.     for k,v in pairs(t) do
  119.     h = h + 1
  120.     if h > 4 then h = 1 end
  121.     m.setCursorPos(1,h)
  122.     m.setBackgroundColor(v.output)
  123.     m.write(v.desc)
  124.  
  125.     m.setBackgroundColor(colors.black)
  126.     m.setCursorPos(8,h)
  127.  
  128.     if v.flux_level < v.flux_max * 0.5 then
  129.     m.setBackgroundColor(colors.green)
  130.     m.write(v.flux_level.."/"..v.flux_max)
  131.     elseif v.flux_level < v.flux_max * 0.8 then
  132.     m.setBackgroundColor(colors.yellow)
  133.     m.write(v.flux_level.."/"..v.flux_max)
  134.     else
  135.     m.setBackgroundColor(colors.red)
  136.     m.write(v.flux_level.."/"..v.flux_max)
  137.     end
  138. end
  139. end
  140.  
  141.  
  142. ---------------------------
  143. --Starts the script
  144. ---------------------------
  145. local n = 0
  146. local function start()
  147.     while true do
  148.            n = n + 1
  149.            print("--------------------------------")
  150.            print("--------------------------------",n)
  151.            receiveTable()
  152.            displayFlux()
  153.     end
  154. end
  155.  
  156. start()
Advertisement
Add Comment
Please, Sign In to add comment