Corbinhol

Generator Controller

Feb 18th, 2022 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.04 KB | None | 0 0
  1. --Variables
  2. os.execute("clear");
  3. local component = require("component");
  4. local sides = require("sides");
  5. local thread = require("thread");
  6. local gpu = component.gpu;
  7.  
  8. local generator = component.proxy(component.get("4518"));
  9. local potatoCloche = component.proxy(component.get("fd88"));
  10. local hempCloche = component.proxy(component.get("c9a6"));
  11. local mainPower = component.proxy(component.get("1719"));
  12. local breaker = component.proxy(component.get("7d13"));
  13. local stopButton = component.proxy(component.get("9f76"));
  14.  
  15. local capacitor1 = component.proxy(component.get("12d2"));
  16. local capacitor2 = component.proxy(component.get("bc7e"));
  17.  
  18. local hempChest1 = component.proxy(component.get("0d86"));
  19. local hempChest2 = component.proxy(component.get("1888"));
  20.  
  21. local potatChest1 = component.proxy(component.get("21c3"));
  22. local potatChest2 = component.proxy(component.get("8b69"));
  23. local tank = component.ie_tank;
  24.  
  25. local generatorStatus = "Offline";
  26. local mainPowerStatus = "Disconnected";
  27. local breakerStatus = "Disconnected";
  28. local potatoStatus1 = "Disabled";
  29. local hempStatus1 = "Disabled";
  30. local potatoStatus2 = "Disabled";
  31. local hempStatus2 = "Disabled";
  32. local fuelLoaded;
  33. --Functions
  34.  
  35. function stopGenerator()
  36.   generator.setOutput(sides.up, 15);
  37.   generatorStatus = "Offline";
  38. end
  39.  
  40. function startGenerator()
  41.   generator.setOutput(sides.up, 0);
  42.   generatorStatus = "Online";
  43. end
  44.  
  45. function stopPotatoCloche1()
  46.   potatoCloche.setOutput(sides.right, 15);
  47.   potatoStatus1 = "Disabled";
  48. end
  49.  
  50. function startPotatoCloche1()
  51.   potatoCloche.setOutput(sides.right, 0);
  52.   potatoStatus1 = "Enabled";
  53. end
  54.  
  55. function stopPotatoCloche2()
  56.   potatoCloche.setOutput(sides.left, 15);
  57.   potatoStatus2 = "Disabled";
  58. end
  59.  
  60. function startPotatoCloche2()
  61.   potatoCloche.setOutput(sides.left, 0);
  62.   potatoStatus2 = "Enabled";
  63. end
  64.  
  65. function stopHempCloche1()
  66.   hempCloche.setOutput(sides.right, 15);
  67.   hempStatus1 = "Disabled";
  68. end
  69.  
  70. function startHempCloche1()
  71.   hempCloche.setOutput(sides.right, 0);
  72.   hempStatus1 = "Enabled";
  73. end
  74.  
  75. function stopHempCloche2()
  76.   hempCloche.setOutput(sides.left, 15);
  77.   hempStatus2 = "Disabled";
  78. end
  79.  
  80. function startHempCloche2()
  81.   hempCloche.setOutput(sides.left, 0);
  82.   hempStatus2 = "Enabled";
  83. end
  84.  
  85.  
  86. function disconnectMainPower()
  87.   mainPower.setOutput(sides.up, 0);
  88.   mainPowerStatus = "Disconnected";
  89. end
  90.  
  91. function connectMainPower()
  92.   mainPower.setOutput(sides.up, 15);
  93.   mainPowerStatus = "Connected";
  94. end
  95.  
  96. function disconnectBreaker()
  97.   breaker.setOutput(sides.left, 0);
  98.   breakerStatus = "Disconnected";
  99. end
  100.  
  101. function connectBreaker()
  102.   breaker.setOutput(sides.left, 15);
  103.   breakerStatus = "Connected";
  104. end
  105.  
  106. function checkPotats()
  107.   if potatoStatus1 == "Disabled" then
  108.       if potatChest1.getStackInSlot(sides.back,8) == nil then
  109.           startPotatoCloche1()
  110.           printF("Potatos 1 Empty...Starting Cloches");
  111.       end
  112.   end
  113.  
  114.   if potatoStatus1 == "Enabled" then
  115.     if potatChest1.getStackInSlot(sides.back,8) ~= nil then
  116.         stopPotatoCloche1()
  117.         printF("Potatos 1 Full...Emptying Cloches");
  118.       end
  119.   end
  120.  
  121.   if potatoStatus2 == "Disabled" then
  122.       if potatChest2.getStackInSlot(sides.back,8) == nil then
  123.           startPotatoCloche2()
  124.           printF("Potatos 2 Empty...Starting Cloches");
  125.       end
  126.   end
  127.  
  128.   if potatoStatus2 == "Enabled" then
  129.     if potatChest2.getStackInSlot(sides.back,8) ~= nil then
  130.         stopPotatoCloche2()
  131.         printF("Potatos 2 Full...Emptying Cloches");
  132.       end
  133.   end
  134. end
  135.  
  136. function checkHemp()
  137.   if hempStatus1 == "Disabled" then
  138.       if hempChest1.getStackInSlot(sides.front,8) == nil then
  139.           startHempCloche1()
  140.           printF("Hemp 1 Empty...Starting Cloches")
  141.       end
  142.   end
  143.  
  144.   if hempStatus1 == "Enabled" then
  145.     if hempChest1.getStackInSlot(sides.front,8) ~= nil then
  146.         stopHempCloche1()
  147.         printF("Hemp 1 Full...Emptying Cloches");
  148.     end
  149.   end
  150.  
  151.   if hempStatus2 == "Disabled" then
  152.       if hempChest2.getStackInSlot(sides.front,8) == nil then
  153.           startHempCloche2()
  154.           printF("Hemp 2 Empty...Starting Cloches")
  155.       end
  156.   end
  157.  
  158.   if hempStatus2 == "Enabled" then
  159.     if hempChest2.getStackInSlot(sides.front,8) ~= nil then
  160.         stopHempCloche2()
  161.         printF("Hemp 2 Full...Emptying Cloches");
  162.     end
  163.   end    
  164. end
  165. local msg;
  166. function printF(input)
  167.   msg = input;
  168. end
  169.  
  170.  function updateScreen()
  171.     gpu.setForeground(0xFFFFFF);
  172.     gpu.set(2, 1, "==================================");
  173.     gpu.set(2, 2, "Power Control System [Ver 1.0]");
  174.     gpu.set(2, 3, "By Yogi And Shaggy");
  175.     gpu.set(2, 4, "==================================");
  176.     gpu.set(2, 6, "Generator Status: ");
  177.     gpu.set(2, 8, "Potato Status 1: ");
  178.     gpu.set(2, 10, "Potato Status 2: ");
  179.     gpu.set(2, 12, "Hemp Status 1: ");
  180.     gpu.set(2, 14, "Hemp Status 2: ");
  181.     gpu.set(2, 16, "Breaker Status: ")
  182.     gpu.set(2, 18, "Main Power Connected: " );
  183.     gpu.set(2, 20, "Bioiesel Amount: ");
  184.     gpu.set(2, 22, "==================================");
  185.  
  186.     if generatorStatus == "Offline" then
  187.       gpu.setForeground(0xFF0000);
  188.     else
  189.       gpu.setForeground(0x50C878);
  190.     end
  191.     gpu.set(21, 6, generatorStatus .. "     ");
  192.  
  193.    if potatoStatus1 == "Disabled" then
  194.       gpu.setForeground(0xFF0000);
  195.     else
  196.       gpu.setForeground(0x50C878);
  197.     end
  198.     gpu.set(20, 8, potatoStatus1 .. "     ");
  199.  
  200.     if potatoStatus2 == "Disabled" then
  201.       gpu.setForeground(0xFF0000);
  202.     else
  203.       gpu.setForeground(0x50C878);
  204.     end
  205.     gpu.set(20, 10, potatoStatus2 .. "     ");
  206.  
  207.     if hempStatus1 == "Disabled" then
  208.       gpu.setForeground(0xFF0000);
  209.     else
  210.       gpu.setForeground(0x50C878);
  211.     end
  212.     gpu.set(17, 12, hempStatus1 .. "     ");
  213.  
  214.     if hempStatus2 == "Disabled" then
  215.       gpu.setForeground(0xFF0000);
  216.     else
  217.       gpu.setForeground(0x50C878);
  218.     end
  219.     gpu.set(17, 14, hempStatus2 .. "     ");
  220.  
  221.     if breakerStatus == "Disconnected" then
  222.       gpu.setForeground(0x50C878);
  223.     else
  224.       gpu.setForeground(0xFF0000);
  225.     end
  226.     gpu.set(18, 16, breakerStatus .. "     ");
  227.  
  228.     if mainPowerStatus == "Disconnected" then
  229.       gpu.setForeground(0xFF0000);
  230.     else
  231.       gpu.setForeground(0x50C878);
  232.     end
  233.     gpu.set(24, 18, mainPowerStatus .. "     ");
  234.  
  235.     if fuelLoaded < 1000 then
  236.       gpu.setForeground(0xFFFF00)
  237.     elseif fuelLoaded > 1000 and fuelLoaded <400000 then
  238.       gpu.setForeground(0xFFFF00)
  239.     else gpu.setForeground(0x50C878);
  240.     end
  241.     gpu.set(19, 20, tostring(math.floor(fuelLoaded) .. "     "));
  242.   end
  243.  
  244. --Startup
  245. print("System Starting...");
  246. print("Loading Program: Yaggys Generator Control");
  247. print("Connecting Breaker");
  248. print("Please Wait...")
  249. connectBreaker();
  250. os.sleep(16);
  251. disconnectBreaker();
  252. print("Disconnecting Breaker");
  253. print("Kickstarting System...")
  254. print("Starting Generator...");
  255. startGenerator();
  256. print("Starting Cloches...");
  257. startPotatoCloche1();
  258. startPotatoCloche2();
  259. startHempCloche1();
  260. startHempCloche2();
  261. print("Generators Started...Waiting until power levels are sufficient...");
  262. while capacitor1.getEnergyStored() + capacitor2.getEnergyStored() < 7900000 do
  263.   os.sleep(1);
  264. end
  265. print("Power Levels Sufficient...");
  266. stopHempCloche1();
  267. stopPotatoCloche1();
  268. stopHempCloche2();
  269. stopPotatoCloche2();
  270. print("Connecting Main Power...");
  271. connectMainPower();
  272. print("Power Successfully Started!")
  273. print("===========================");
  274.   os.execute("resolution 50 25")
  275. --Main Loop
  276. local run = true;
  277. while run do
  278.   os.sleep(1);
  279.   if stopButton.getInput(sides.right) == 15 then
  280.       run = false
  281.   end
  282.   checkPotats();
  283.   checkHemp();
  284.   fuelLoaded = tank.getAmount();
  285.   updateScreen()
  286. end
  287. --Shutting Down
  288. os.execute("clear");
  289. gpu.setForeground(0xFFFFFF);
  290. print("Stopping System...");
  291. print("Disconnecting Main Power");
  292. disconnectMainPower();
  293. print("Stopping Cloches");
  294. stopHempCloche1();
  295. stopPotatoCloche1();
  296. stopHempCloche2();
  297. stopPotatoCloche2();
  298. print("Shutting Down Generator...");
  299. stopGenerator();
  300. os.execute("resolution 160 50");
  301. --Main Power Control
Add Comment
Please, Sign In to add comment