Advertisement
SythsGod

Turbine Control Startup

Oct 20th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. local t = {}
  2. local energy = {}
  3. local engaged = {}
  4. local online = {}
  5. local rpm = {}
  6. local restart = 0
  7.  
  8. function getStatus()
  9.   for i = 0, #t - 1 do
  10.     engaged[i] = t[i].getInductorEngaged()
  11.     online[i]  = t[i].getActive()
  12.     energy[i]  = t[i].getEnergyStored()
  13.     rpm[i]     = t[i].getRotorSpeed()
  14.   end
  15. end
  16.  
  17. function getConnectedTurbines()
  18.   local allDone = false
  19.   local turbine = nil
  20.   local i = 0
  21.  
  22.   repeat
  23.     turbine = peripheral.wrap("BigReactors-Turbine_" .. i)
  24.     if turbine ~= nil then
  25.       print("Hooking up turbine #" .. i)
  26.       t[i] = turbine
  27.       i = i + 1
  28.     end
  29.  
  30.     allDone = turbine == nil
  31.   until allDone
  32.  
  33.   return i
  34. end
  35.  
  36. no_turbines_error = getConnectedTurbines() == 0
  37. if no_turbines_error then
  38.   printError("No turbines found!")
  39.   break
  40. end
  41.  
  42. while true do
  43.   getStatus()
  44.  
  45.   for i = 0, #t - 1 do
  46.     t[i].setInductorEngaged(not(rpm[i] < 1780 or not (rpm[i] > 1820))) -- turn on coils when needed    
  47.   end
  48.  
  49.   restart = restart + 1
  50.   if restart == 5 then
  51.     os.reboot()
  52.   else
  53.     os.sleep(1)
  54.   end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement