cduclaux

Nuclearcraft Efficency

Nov 23rd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. --create an OS timer for waiting for key  
  2. local myTimer = os.startTimer(0)
  3.  
  4. --thresholds, to be changed as per the requirement
  5. local threshlow = 5
  6. local threshhigh = 10
  7.  
  8. --hysteresis low means that it keeps on until
  9. --it hits high threshold
  10. --hysteresis high means that it keeps on until
  11. --it hits low threshold
  12. --starts in a low state
  13. local hyst = 'low'
  14.  
  15. -- wrap the peripherals
  16. nc = peripheral.wrap('left')
  17. mon = peripheral.wrap('top')
  18.  
  19. --start us in an off state
  20. redstone.setOutput('left', false)
  21.  
  22. while true do
  23.     local event, param1 = os.pullEvent()
  24.  
  25.     if event == "timer" and param1 == myTimer then
  26.         md = nc.getMetadata()
  27.         energy = md['energy']
  28.         state = md['state']    
  29.    
  30.         stored = energy['stored']
  31.         capacity = energy['capacity']
  32.         state = state['active']
  33.         percent = math.floor((stored/capacity)*100)
  34.  
  35.         print(stored, capacity, percent)
  36.         print(state)
  37.  
  38.         if percent < threshlow then
  39.             redstone.setOutput('left', true)
  40.             hyst = 'high'
  41.         elseif percent > threshhigh then
  42.             redstone.setOutput('left', false)
  43.             hyst = 'low'
  44.         elseif hyst == 'low' then
  45.             redstone.setOutput('left', false)
  46.         else
  47.             redstone.setOutput('left', true)
  48.         end
  49.  
  50.         mon.setCursorPos(1,1)
  51.         mon.write('Thresh Low: ' .. threshlow .. '          ')    
  52.         mon.setCursorPos(1,2)
  53.         mon.write('Thresh High: ' .. threshhigh .. '         ')
  54.         mStored = math.floor(stored/100000)/10
  55.         sStored = string.format("%.1f", mStored)
  56.         mon.setCursorPos(1,3)
  57.         mon.write('Stored: ' .. sStored .. ' MRF       ')
  58.         mCapacity = math.floor(capacity/100000)/10
  59.         sCapacity = string.format("%.1f", mCapacity)
  60.         mon.setCursorPos(1,4)
  61.         mon.write('Capacity: ' .. sCapacity .. ' MRF     ')
  62.         mon.setCursorPos(1,5)
  63.         mon.write('Percent Full: ' .. percent .. '%       ')                        
  64.         mon.setCursorPos(1,6)
  65.         if state == true then
  66.             mon.write('Reactor Active   ')
  67.         else
  68.             mon.write('Reactor Inactive ')
  69.         end
  70.                
  71.         myTimer = os.startTimer(2)
  72.  
  73.     elseif event == 'char' and param1 == 'q' then
  74.         redstone.setOutput('left', false)
  75.         mon.clear()
  76.         mon.setCursorPos(1,1)
  77.         mon.write('Program Inactive')
  78.         break
  79.     end
  80. end
Add Comment
Please, Sign In to add comment