Advertisement
XxZajoZzO

ComputerCraft program for controlling the steam turbine

Jan 18th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. r = peripheral.find("BigReactors-Reactor")
  2. t = peripheral.wrap("BigReactors-Turbine_0")
  3. t1 = peripheral.wrap("BigReactors-Turbine_1")
  4. m = peripheral.wrap("right")
  5.  
  6. local isActive = false
  7. local rotorSpeed = 1800
  8. local rotorSpeed1 = 1800
  9. local RFGen = 0
  10. local RFGen1 = 0
  11. local steam = 0
  12. local steam1 = 0
  13.  
  14. function comma_value(amount)
  15.   local formatted = amount
  16.   local swap = false
  17.   if formatted < 0 then
  18.     formatted = formatted*-1
  19.     swap = true
  20.   end
  21.   while true do
  22.     formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
  23.     if k == 0 then
  24.       break
  25.     end
  26.   end
  27.   if swap then
  28.     formatted = "-"..formatted
  29.   end
  30.   return formatted
  31. end
  32.  
  33. r.setActive(false)
  34. t.setInductorEngaged(false)
  35. t.setActive(true)
  36. t1.setInductorEngaged(false)
  37. t1.setActive(true)
  38.  
  39. while true do
  40.  
  41.   print("Sleep")
  42.  
  43.   sleep(5)
  44.  
  45.   if rotorSpeed < 1750 then
  46.     print("Extra sleep because of slow rotor!")
  47.     sleep(5)
  48.   end
  49.  
  50.   if isActive then
  51.     if not redstone.getInput("back") then
  52.       print("Disable")
  53.       isActive = false
  54.       r.setActive(false)
  55.       sleep(0.5)
  56.       t.setInductorEngaged(false)
  57.       t1.setInductorEngaged(false)
  58.     end
  59.   else
  60.     if redstone.getInput("back") then
  61.       print("Enable")
  62.       isActive = true
  63.       r.setActive(true)
  64.       sleep(0.1)
  65.       t.setInductorEngaged(true)
  66.       t1.setInductorEngaged(true)
  67.     end
  68.   end
  69.  
  70.   m.clear()
  71.  
  72.   rotorSpeed = t.getRotorSpeed()
  73.   rotorSpeed1 = t1.getRotorSpeed()
  74.  
  75.   if isActive then
  76.  
  77.     print("Active!")
  78.    
  79.     RFGen = t.getEnergyProducedLastTick()
  80.     RFGen1 = t1.getEnergyProducedLastTick()
  81.     steam = t.getFluidFlowRate()
  82.     steam1 = t1.getFluidFlowRate()
  83.  
  84.     m.setCursorPos(1,1)
  85.    
  86.     if rotorSpeed > 1900 then
  87.       m.setTextColor(colors.red)
  88.       m.setCursorPos(1,10)
  89.       m.write("RPM Too High!! Disabling the Reactor and Enabling the Coils!")
  90.       print("RPM Too High!! Disabling the Reactor and Enabling the Coils!")
  91.       t.setInductorEngaged(true)
  92.       t1.setInductorEngaged(true)
  93.       r.setActive(false)
  94.       m.setCursorPos(1,1)
  95.     elseif rotorSpeed < 1750 then
  96.       m.setTextColor(colors.blue)
  97.       m.setCursorPos(1,10)
  98.       m.write("RPM Too Low!! Disabling the Coils and Enabling the Reactor!")
  99.       print("RPM Too Low!! Disabling the Coils and Enabling the Reactor!")
  100.       t.setInductorEngaged(false)
  101.       t1.setInductorEngaged(false)
  102.       r.setActive(true)
  103.       m.setCursorPos(1,1)
  104.     else
  105.       m.setTextColor(colors.lime)
  106.       t.setInductorEngaged(true)
  107.       t1.setInductorEngaged(true)
  108.       r.setActive(true)
  109.     end
  110.    
  111.     m.write("1. Rotor speed:"..comma_value(rotorSpeed).."RPM")
  112.     m.setCursorPos(1,2)
  113.     m.write("2. Rotor speed:"..comma_value(rotorSpeed1).."RPM")
  114.     m.setCursorPos(1,4)
  115.     m.setTextColor(colors.lime)
  116.     m.write("1. RF Generation:"..comma_value(RFGen).."RF/t")
  117.     m.setCursorPos(1,5)
  118.     m.write("2. RF Generation:"..comma_value(RFGen1).."RF/t")
  119.     m.setCursorPos(1,7)
  120.    
  121.     if steam < 1990 then
  122.     m.setTextColor(colors.red)
  123.     else
  124.     m.setTextColor(colors.lime)
  125.     end
  126.    
  127.     m.write("1. Steam Generation:"..comma_value(steam).."mB/t")
  128.     m.setCursorPos(1,8)
  129.     m.write("2. Steam Generation:"..comma_value(steam1).."mB/t")
  130.    
  131.   else
  132.  
  133.     m.setCursorPos(1,1)
  134.    
  135.     if rotorSpeed > 1900 then
  136.       m.setTextColor(colors.red)
  137.       m.setCursorPos(1,6)
  138.       m.write("RPM Too High!! Disabling the Reactor and Enabling the Coils!")
  139.       print("RPM Too High!! Disabling the Reactor and Enabling the Coils!")
  140.       t.setInductorEngaged(true)
  141.       t1.setInductorEngaged(true)
  142.       r.setActive(false)
  143.       m.setCursorPos(1,1)
  144.     elseif rotorSpeed < 1750 then
  145.       m.setTextColor(colors.blue)
  146.       m.setCursorPos(1,6)
  147.       m.write("RPM Too Low!! Disabling the Coils and Enabling the Reactor!")
  148.       print("RPM Too Low!! Disabling the Coils and Enabling the Reactor!")
  149.       t.setInductorEngaged(false)
  150.       t1.setInductorEngaged(false)
  151.       r.setActive(true)
  152.       m.setCursorPos(1,1)
  153.     else
  154.       m.setTextColor(colors.lime)
  155.       t.setInductorEngaged(false)
  156.       t1.setInductorEngaged(false)
  157.       r.setActive(false)
  158.     end
  159.    
  160.     m.write("1. Rotor speed:"..comma_value(rotorSpeed).."RPM")
  161.     m.setCursorPos(1,2)
  162.     m.write("2. Rotor speed:"..comma_value(rotorSpeed1).."RPM")
  163.     m.setCursorPos(1,4)
  164.     m.setTextColor(colors.red)
  165.     m.write("Not Active!")
  166.     m.setTextColor(colors.white)
  167.     print("Not Active!")
  168.    
  169.   end
  170.  
  171. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement