Advertisement
Fabrimat

Energy Cell Switcher

Feb 1st, 2015 (edited)
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.18 KB | None | 0 0
  1. local m = peripheral.wrap("monitor_151")
  2. print("Starting the program...")
  3. sleep(1)
  4. while true do
  5. rsleft = redstone.getAnalogInput("left")
  6. rsright = redstone.getAnalogInput("right")
  7. print("-------")
  8. print("Restarting the control")
  9.         if rsleft==15 and rsright==15 then
  10.                 redstone.setOutput("top",false)
  11.                 redstone.setOutput("bottom",true)
  12.                 redstone.setOutput("back",true)
  13.                 print("-------")
  14.                                 print("All Energy Cells are full")
  15.                 print("Using the Left Energy Cell")
  16.         else
  17.                 if rsleft==0 and rsright==0 then
  18.                         redstone.setOutput("top",true)
  19.                         redstone.setOutput("bottom",true)
  20.                         redstone.setOutput("back",false)
  21.                         print("-------")
  22.                         print("No energy")
  23.                         print("Both Energy Cells are depleted")
  24.                 else
  25.                         if rsleft~=0 and rsleft ~=15 and rsright~=0 and rsright~=15 and rsleft==rsright then
  26.                                 redstone.setOutput("top",false)
  27.                                 redstone.setOutput("bottom",true)
  28.                                 redstone.setOutput("back",false)
  29.                                 print("-------")
  30.                                 print("The Energy Cells have equal energies")
  31.                                 print("Using the Left Energy Cell")
  32.                         else
  33.                                 if rsleft~=0 and rsleft ~=15 and rsright~=0 and rsright~=15 and rsleft>rsright then
  34.                                         redstone.setOutput("top",false)
  35.                                         redstone.setOutput("bottom",true)
  36.                                         redstone.setOutput("back",false)
  37.                                         print("-------")
  38.                                         print("The Left Energy Cell has greater energy than that of the Right")
  39.                                         print("Using the Left Energy Cell")
  40.                                 else
  41.                                         if rsleft~=0 and rsleft ~=15 and rsright~=0 and rsright~=15 and rsleft<rsright then
  42.                                                 redstone.setOutput("top",true)
  43.                                                 redstone.setOutput("bottom",false)
  44.                                                 redstone.setOutput("back",false)
  45.                                                 print("-------")
  46.                                                 print("The Right Energy Cell has greater energy than that of the Left")
  47.                                                 print("Using the Right Energy Cell")
  48.                                         else
  49.                                                                                                 if rsleft==0 and rsright~=0 then
  50.                                                                                                         redstone.setOutput("top",true)
  51.                                                                                                         redstone.setOutput("bottom",false)
  52.                                                                                                         redstone.setOutput("back",false)
  53.                                                                                                         print("-------")
  54.                                                                                                         print("The Left Energy Cell is depleted")
  55.                                                                                                         print("Using the Right Energy Cell")
  56.                                                                                                 else
  57.                                                                                                         if rsleft~=0 and rsright==0 then
  58.                                                                                                                 redstone.setOutput("top",false)
  59.                                                                                                                 redstone.setOutput("bottom",true)
  60.                                                                                                                 redstone.setOutput("back",false)
  61.                                                                                                                 print("-------")
  62.                                                                                                                 print("The Right Energy Cell is depleted")
  63.                                                                                                                 print("Using the Left Energy Cell")
  64.                                                                                                         else
  65.                                                                                                                 if rsleft~=15 and rsright==15 then
  66.                                                                                                                         redstone.setOutput("top",true)
  67.                                                                                                                         redstone.setOutput("bottom",false)
  68.                                                                                                                         redstone.setOutput("back",true)
  69.                                                                                                                         print("-------")
  70.                                                                                                                         print("The Right Energy Cell is full")
  71.                                                                                                                         print("Using the Right Energy Cell")
  72.                                                                                                                 else
  73.                                                                                                                         if rsleft==15 and rsright~=15 then
  74.                                                                                                                                 redstone.setOutput("top",false)
  75.                                                                                                                                 redstone.setOutput("bottom",true)
  76.                                                                                                                                 redstone.setOutput("back",true)
  77.                                                                                                                                 print("-------")
  78.                                                                                                                         print("The Left Energy Cell is full")
  79.                                                                                                                         print("Using the Left Energy Cell")
  80.                                                                                                                         else
  81.                                                                                                                                 print("-------")
  82.                                                                                                                                 print("Error")
  83.                                                                                                                                 print("Error Report")
  84.                                                                                                                                 print(redstone.getAnalogInput("left"))
  85.                                                                                                                                 print(redstone.getAnalogInput("right"))
  86.                                                                                                                                 redstone.setOutput("top",true)
  87.                                                                                                                                 redstone.setOutput("bottom",true)
  88.                                                                                                                                 redstone.setOutput("back",true)
  89.                                                                                                                                 break
  90.                                                                                                                         end
  91.                                                                                                                 end
  92.                                                                                                         end
  93.                                                                                                 end
  94.                                         end
  95.                                 end
  96.                         end
  97.                 end
  98.         end
  99.  
  100.  
  101. m.clear()
  102. m.setCursorPos(15,2)
  103. m.setTextColor(colors.orange)
  104. m.write("Energy Cells")
  105. m.setCursorPos(4,5)
  106. m.write("Left Cell: ")
  107. m.setCursorPos(21,5)
  108. m.write("Right Cell: ")
  109. m.setCursorPos(15,5)
  110.  
  111. if rsleft==15 then
  112.     m.setTextColor(colors.green)
  113.     m.write("100%")
  114. else
  115.     if rsleft==7 then
  116.         m.setTextColor(colors.orange)
  117.         m.write("50%")
  118.     else
  119.         if rsleft==0 then
  120.             m.setTextColor(colors.red)
  121.             m.write("0%")
  122.         else
  123.             if rsleft==14 then
  124.                 m.setTextColor(colors.green)
  125.                 m.write("100%")
  126.             else
  127.                 if rsleft==13 then
  128.                     m.setTextColor(colors.green)
  129.                     m.write("85%")
  130.                 else
  131.                     if rsleft==12 then
  132.                         m.setTextColor(colors.green)
  133.                         m.write("80%")
  134.                     else
  135.                         if rsleft==11 then
  136.                             m.setTextColor(colors.green)
  137.                             m.write("70%")
  138.                         else
  139.                             if rsleft==10 then
  140.                                 m.setTextColor(colors.orange)
  141.                                 m.write("65%")
  142.                             else
  143.                                 if rsleft==9 then
  144.                                     m.setTextColor(colors.orange)
  145.                                     m.write("60%")
  146.                                 else
  147.                                     if rsleft==8 then
  148.                                         m.setTextColor(colors.orange)
  149.                                         m.write("55%")
  150.                                     else
  151.                                         if rsleft==6 then
  152.                                             m.setTextColor(colors.orange)
  153.                                             m.write("40%")
  154.                                         else
  155.                                             if rsleft==5 then
  156.                                                 m.setTextColor(colors.red)
  157.                                                 m.write("30%")
  158.                                             else
  159.                                                 if rsleft==4 then
  160.                                                     m.setTextColor(colors.red)
  161.                                                     m.write("25%")
  162.                                                 else
  163.                                                     if rsleft==3 then
  164.                                                         m.setTextColor(colors.red)
  165.                                                         m.write("20%")
  166.                                                     else
  167.                                                      if rsleft==2 then
  168.                                                         m.setTextColor(colors.red)
  169.                                                         m.write("15%")
  170.                                                     else
  171.                                                         if rsleft==1 then
  172.                                                             m.setTextColor(colors.red)
  173.                                                             m.write("5%")
  174.                                                         else
  175.                                                             m.setTextColor(colors.red)
  176.                                                             m.write("Error")
  177.                                                         end
  178.                                                     end
  179.                                                 end
  180.                                             end
  181.                                         end
  182.                                     end
  183.                                 end
  184.                             end
  185.                         end
  186.                     end
  187.                 end
  188.             end
  189.         end
  190.     end
  191. end
  192. end
  193.  
  194. m.setCursorPos(33,5)
  195. if rsright==15 then
  196.     m.setTextColor(colors.green)
  197.     m.write("100%")
  198. else
  199.     if rsright==7 then
  200.         m.setTextColor(colors.orange)
  201.         m.write("50%")
  202.     else
  203.         if rsright==0 then
  204.             m.setTextColor(colors.red)
  205.             m.write("0%")
  206.         else
  207.             if rsright==14 then
  208.                 m.setTextColor(colors.green)
  209.                 m.write("100%")
  210.             else
  211.                 if rsright==13 then
  212.                     m.setTextColor(colors.green)
  213.                     m.write("85%")
  214.                 else
  215.                     if rsright==12 then
  216.                         m.setTextColor(colors.green)
  217.                         m.write("80%")
  218.                     else
  219.                         if rsright==11 then
  220.                             m.setTextColor(colors.green)
  221.                             m.write("70%")
  222.                         else
  223.                             if rsright==10 then
  224.                                 m.setTextColor(colors.orange)
  225.                                 m.write("65%")
  226.                             else
  227.                                 if rsright==9 then
  228.                                     m.setTextColor(colors.orange)
  229.                                     m.write("60%")
  230.                                 else
  231.                                     if rsright==8 then
  232.                                         m.setTextColor(colors.orange)
  233.                                         m.write("55%")
  234.                                     else
  235.                                         if rsright==6 then
  236.                                             m.setTextColor(colors.orange)
  237.                                             m.write("40%")
  238.                                         else
  239.                                             if rsright==5 then
  240.                                                 m.setTextColor(colors.red)
  241.                                                 m.write("30%")
  242.                                             else
  243.                                                 if rsright==4 then
  244.                                                     m.setTextColor(colors.red)
  245.                                                     m.write("25%")
  246.                                                 else
  247.                                                     if rsright==3 then
  248.                                                         m.setTextColor(colors.red)
  249.                                                         m.write("20%")
  250.                                                     else
  251.                                                      if rsright==2 then
  252.                                                         m.setTextColor(colors.red)
  253.                                                         m.write("15%")
  254.                                                     else
  255.                                                         if rsright==1 then
  256.                                                             m.setTextColor(colors.red)
  257.                                                             m.write("5%")
  258.                                                         else
  259.                                                             m.setTextColor(colors.red)
  260.                                                             m.write("Error")
  261.                                                         end
  262.                                                     end
  263.                                                 end
  264.                                             end
  265.                                         end
  266.                                     end
  267.                                 end
  268.                             end
  269.                         end
  270.                     end
  271.                 end
  272.             end
  273.         end
  274.     end
  275. end
  276. end
  277.  
  278. sleep(2)
  279. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement