Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables
- os.execute("clear");
- local component = require("component");
- local sides = require("sides");
- local thread = require("thread");
- local gpu = component.gpu;
- local generator = component.proxy(component.get("4518"));
- local potatoCloche = component.proxy(component.get("fd88"));
- local hempCloche = component.proxy(component.get("c9a6"));
- local mainPower = component.proxy(component.get("1719"));
- local breaker = component.proxy(component.get("7d13"));
- local stopButton = component.proxy(component.get("9f76"));
- local capacitor1 = component.proxy(component.get("12d2"));
- local capacitor2 = component.proxy(component.get("bc7e"));
- local hempChest1 = component.proxy(component.get("0d86"));
- local hempChest2 = component.proxy(component.get("1888"));
- local potatChest1 = component.proxy(component.get("21c3"));
- local potatChest2 = component.proxy(component.get("8b69"));
- local tank = component.ie_tank;
- local generatorStatus = "Offline";
- local mainPowerStatus = "Disconnected";
- local breakerStatus = "Disconnected";
- local potatoStatus1 = "Disabled";
- local hempStatus1 = "Disabled";
- local potatoStatus2 = "Disabled";
- local hempStatus2 = "Disabled";
- local fuelLoaded;
- --Functions
- function stopGenerator()
- generator.setOutput(sides.up, 15);
- generatorStatus = "Offline";
- end
- function startGenerator()
- generator.setOutput(sides.up, 0);
- generatorStatus = "Online";
- end
- function stopPotatoCloche1()
- potatoCloche.setOutput(sides.right, 15);
- potatoStatus1 = "Disabled";
- end
- function startPotatoCloche1()
- potatoCloche.setOutput(sides.right, 0);
- potatoStatus1 = "Enabled";
- end
- function stopPotatoCloche2()
- potatoCloche.setOutput(sides.left, 15);
- potatoStatus2 = "Disabled";
- end
- function startPotatoCloche2()
- potatoCloche.setOutput(sides.left, 0);
- potatoStatus2 = "Enabled";
- end
- function stopHempCloche1()
- hempCloche.setOutput(sides.right, 15);
- hempStatus1 = "Disabled";
- end
- function startHempCloche1()
- hempCloche.setOutput(sides.right, 0);
- hempStatus1 = "Enabled";
- end
- function stopHempCloche2()
- hempCloche.setOutput(sides.left, 15);
- hempStatus2 = "Disabled";
- end
- function startHempCloche2()
- hempCloche.setOutput(sides.left, 0);
- hempStatus2 = "Enabled";
- end
- function disconnectMainPower()
- mainPower.setOutput(sides.up, 0);
- mainPowerStatus = "Disconnected";
- end
- function connectMainPower()
- mainPower.setOutput(sides.up, 15);
- mainPowerStatus = "Connected";
- end
- function disconnectBreaker()
- breaker.setOutput(sides.left, 0);
- breakerStatus = "Disconnected";
- end
- function connectBreaker()
- breaker.setOutput(sides.left, 15);
- breakerStatus = "Connected";
- end
- function checkPotats()
- if potatoStatus1 == "Disabled" then
- if potatChest1.getStackInSlot(sides.back,8) == nil then
- startPotatoCloche1()
- printF("Potatos 1 Empty...Starting Cloches");
- end
- end
- if potatoStatus1 == "Enabled" then
- if potatChest1.getStackInSlot(sides.back,8) ~= nil then
- stopPotatoCloche1()
- printF("Potatos 1 Full...Emptying Cloches");
- end
- end
- if potatoStatus2 == "Disabled" then
- if potatChest2.getStackInSlot(sides.back,8) == nil then
- startPotatoCloche2()
- printF("Potatos 2 Empty...Starting Cloches");
- end
- end
- if potatoStatus2 == "Enabled" then
- if potatChest2.getStackInSlot(sides.back,8) ~= nil then
- stopPotatoCloche2()
- printF("Potatos 2 Full...Emptying Cloches");
- end
- end
- end
- function checkHemp()
- if hempStatus1 == "Disabled" then
- if hempChest1.getStackInSlot(sides.front,8) == nil then
- startHempCloche1()
- printF("Hemp 1 Empty...Starting Cloches")
- end
- end
- if hempStatus1 == "Enabled" then
- if hempChest1.getStackInSlot(sides.front,8) ~= nil then
- stopHempCloche1()
- printF("Hemp 1 Full...Emptying Cloches");
- end
- end
- if hempStatus2 == "Disabled" then
- if hempChest2.getStackInSlot(sides.front,8) == nil then
- startHempCloche2()
- printF("Hemp 2 Empty...Starting Cloches")
- end
- end
- if hempStatus2 == "Enabled" then
- if hempChest2.getStackInSlot(sides.front,8) ~= nil then
- stopHempCloche2()
- printF("Hemp 2 Full...Emptying Cloches");
- end
- end
- end
- local msg;
- function printF(input)
- msg = input;
- end
- function updateScreen()
- gpu.setForeground(0xFFFFFF);
- gpu.set(2, 1, "==================================");
- gpu.set(2, 2, "Power Control System [Ver 1.0]");
- gpu.set(2, 3, "By Yogi And Shaggy");
- gpu.set(2, 4, "==================================");
- gpu.set(2, 6, "Generator Status: ");
- gpu.set(2, 8, "Potato Status 1: ");
- gpu.set(2, 10, "Potato Status 2: ");
- gpu.set(2, 12, "Hemp Status 1: ");
- gpu.set(2, 14, "Hemp Status 2: ");
- gpu.set(2, 16, "Breaker Status: ")
- gpu.set(2, 18, "Main Power Connected: " );
- gpu.set(2, 20, "Bioiesel Amount: ");
- gpu.set(2, 22, "==================================");
- if generatorStatus == "Offline" then
- gpu.setForeground(0xFF0000);
- else
- gpu.setForeground(0x50C878);
- end
- gpu.set(21, 6, generatorStatus .. " ");
- if potatoStatus1 == "Disabled" then
- gpu.setForeground(0xFF0000);
- else
- gpu.setForeground(0x50C878);
- end
- gpu.set(20, 8, potatoStatus1 .. " ");
- if potatoStatus2 == "Disabled" then
- gpu.setForeground(0xFF0000);
- else
- gpu.setForeground(0x50C878);
- end
- gpu.set(20, 10, potatoStatus2 .. " ");
- if hempStatus1 == "Disabled" then
- gpu.setForeground(0xFF0000);
- else
- gpu.setForeground(0x50C878);
- end
- gpu.set(17, 12, hempStatus1 .. " ");
- if hempStatus2 == "Disabled" then
- gpu.setForeground(0xFF0000);
- else
- gpu.setForeground(0x50C878);
- end
- gpu.set(17, 14, hempStatus2 .. " ");
- if breakerStatus == "Disconnected" then
- gpu.setForeground(0x50C878);
- else
- gpu.setForeground(0xFF0000);
- end
- gpu.set(18, 16, breakerStatus .. " ");
- if mainPowerStatus == "Disconnected" then
- gpu.setForeground(0xFF0000);
- else
- gpu.setForeground(0x50C878);
- end
- gpu.set(24, 18, mainPowerStatus .. " ");
- if fuelLoaded < 1000 then
- gpu.setForeground(0xFFFF00)
- elseif fuelLoaded > 1000 and fuelLoaded <400000 then
- gpu.setForeground(0xFFFF00)
- else gpu.setForeground(0x50C878);
- end
- gpu.set(19, 20, tostring(math.floor(fuelLoaded) .. " "));
- end
- --Startup
- print("System Starting...");
- print("Loading Program: Yaggys Generator Control");
- print("Connecting Breaker");
- print("Please Wait...")
- connectBreaker();
- os.sleep(16);
- disconnectBreaker();
- print("Disconnecting Breaker");
- print("Kickstarting System...")
- print("Starting Generator...");
- startGenerator();
- print("Starting Cloches...");
- startPotatoCloche1();
- startPotatoCloche2();
- startHempCloche1();
- startHempCloche2();
- print("Generators Started...Waiting until power levels are sufficient...");
- while capacitor1.getEnergyStored() + capacitor2.getEnergyStored() < 7900000 do
- os.sleep(1);
- end
- print("Power Levels Sufficient...");
- stopHempCloche1();
- stopPotatoCloche1();
- stopHempCloche2();
- stopPotatoCloche2();
- print("Connecting Main Power...");
- connectMainPower();
- print("Power Successfully Started!")
- print("===========================");
- os.execute("resolution 50 25")
- --Main Loop
- local run = true;
- while run do
- os.sleep(1);
- if stopButton.getInput(sides.right) == 15 then
- run = false
- end
- checkPotats();
- checkHemp();
- fuelLoaded = tank.getAmount();
- updateScreen()
- end
- --Shutting Down
- os.execute("clear");
- gpu.setForeground(0xFFFFFF);
- print("Stopping System...");
- print("Disconnecting Main Power");
- disconnectMainPower();
- print("Stopping Cloches");
- stopHempCloche1();
- stopPotatoCloche1();
- stopHempCloche2();
- stopPotatoCloche2();
- print("Shutting Down Generator...");
- stopGenerator();
- os.execute("resolution 160 50");
- --Main Power Control
Add Comment
Please, Sign In to add comment