Advertisement
Guest User

control

a guest
Oct 25th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. --Big Reactor control program
  2. --Program by Archmon1 for computerCraft1.6
  3.  
  4. --Cell should be placed like 2 blocks to the left
  5. --of the computer. Then a comparitor from vanilla
  6. --in between the thermal expantion cell and the
  7. --computerCraft computer but this is configurable
  8. --Just by changeing the cellRedstone var below.
  9.  
  10. --The redstone to start the reactor is by default
  11. --set to top but this can be configured by
  12. --changing reactorRedstone below.  I had to use a
  13. --block of cobble in order to relay the signal
  14. --to the reactor.
  15.  
  16. --This program could very well be used to control
  17. --a set of generators or dynamos with out
  18. --much modifcation.
  19.  
  20. --Enjoy.
  21.  
  22.  
  23.  
  24.  
  25. ---------------------------
  26. --var declare/inital set
  27. ---------------------------
  28. var = reactor
  29. reactor ="false"
  30. var = reactorRedstone
  31. reactorRedstone = "top"
  32. rs.setOutput(reactorRedstone, false)
  33. var = cellRedstone
  34. cellRedstone = "left"
  35. var = sleepvar
  36. sleepvar = 10
  37.  
  38. ---------------------------
  39. --Functions
  40. ---------------------------
  41. function signal()
  42.   rsStrength = rs.getAnalogInput(cellRedstone)
  43. --  print("redstone strength = ", rsStrength)  --Test Line
  44. end
  45.  
  46. ---------------------------
  47. --Program Start
  48. ---------------------------
  49. print("Program Start")
  50. print("Starting redstone level ", rs.getAnalogInput(cellRedstone))
  51. if rs.getAnalogInput(cellRedstone) < 15 then
  52.   print ("redstone on")  --prints only if cell not full
  53. end
  54. ---------------------------
  55. --Main Loop start
  56. ---------------------------
  57.  
  58. while true do
  59.   signal()  --Function
  60.   if rsStrength >= 15 then  --Activates when cell full
  61.     print("Cell Full, waiting for cell to drain")
  62.     reactor="false"  --sets var for while loop ahead
  63.     rs.setOutput(reactorRedstone, false)  --turns off reactor
  64.     --While forces if loop to wait till power drops
  65.     while reactor ~= "true" do
  66.       if rsStrength <= 3 then
  67.         reactor="true"  --Breaks While loop inside if loop
  68.         print("Power needed, reactor starting")
  69. --        print("redstone strength = ", rsStrength)  --Test line
  70.       else  --Runs until power is low
  71.         signal()  --Function
  72. --        print("Waiting for need of power")  --Test Line
  73. --        print("Redstone currently ", rsStrength) --Test Line
  74.         sleep(sleepvar)
  75.       end
  76.     end
  77.   end
  78.  
  79.   if rsStrength < 15 then --Still inside while true do
  80. --    print("redstone on")  --testing line
  81.     rs.setOutput(reactorRedstone, true)--Turns reactor on, but no message spam
  82.   end
  83. sleep(sleepvar)
  84. end
  85. ------------------------
  86. --end program
  87. ------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement