Okay so if I understand completely what you are trying to do, then you want your code to be running, while also listening for a disk to be inserted or removed form the system. If the disk is inserted start all of the computers, if it is removed, then shut them all down.
Applying it to your code:
local on = true --# I will explain the importance of this below
while true do
local myTimer = os.startTimer(5) --# starting a timer to fire after 5 seconds
local evt = {os.pullEvent()} --# catching the events and all the parameters in a table
if event[1] == "timer" and event[2] == myTimer and on then --# checking to see if the event is a "timer" event, and checking if the timer event is one we are looking for, I will explain "on" below
--# this is essentially replacing the sleep that you had at the end of your original code
CapEnergyStored = Capacitor[1].getEnergyStored()
EnergyStored = (CapEnergyStored) * (CapCount)
if Debug == true then
print(EnergyStored)
end
if EnergyStored <= EmptyLevel or EnergyStored == 0 then
Reactor[1].setAllControlRodLevels(11)
Turbine[1].setFluidFlowRateMax(1270)
Turbine[2].setFluidFlowRateMax(1270)
elseif EnergyStored >= EmptyLevel and EnergyStored <= LowLevel then
Reactor[1].setAllControlRodLevels(11)
Turbine[1].setFluidFlowRateMax(1260)
Turbine[2].setFluidFlowRateMax(1260)
elseif EnergyStored >= LowLevel and EnergyStored <= MedLevel then
Reactor[1].setAllControlRodLevels(37)
Turbine[1].setFluidFlowRateMax(1260)
Turbine[2].setFluidFlowRateMax(550)
elseif EnergyStored >= MedLevel and EnergyStored < HighLevel then
Reactor[1].setAllControlRodLevels(61)
Turbine[1].setFluidFlowRateMax(1260)
Turbine[2].setFluidFlowRateMax(0)
elseif EnergyStored >= HighLevel and EnergyStored <= FullLevel then
Reactor[1].setAllControlRodLevels(82)
Turbine[1].setFluidFlowRateMax(550)
Turbine[2].setFluidFlowRateMax(0)
elseif EnergyStored >= FullLevel then
Reactor[1].setAllControlRodLevels(100)
end
elseif evt[1] == "disk" then
--# a disk was just added to the system
local computers = peripheral.find("computer")
for k,v in pairs(computers) do --# begin looping through and turning on all computers
v.turnOn()
end
on = true --# i will explain the importance of this below
elseif evt[1] == "disk_eject" then
--# a disk was just removed from the system
local computers = peripheral.find("computer")
for k,v in pairs("computer") do --# begin looping through and turning off all computers
v.shutdown()
end
on = false --# I will explain the importance of this below
end
os.stopTimer(myTimer) --# I will further explain this below
end
So the "on" variable, keeps track of whether or not there is a disk in a disk drive, with the assumption that when the computer is first turned on there is one (defined as true in the beginning). So in the first if statement it checks the event to see if the event was the correct timer event, and it checks if the variable "on" is true. If it is then it will and the other two checks were true, then it will run the section of the code. If it is not, then it will go onto the next two checks. The first of the next two checks checks to see if the event was a disk being added to the system. If it is then it turns on all the computers and sets the variable to true, which causes the main part of the program to run. If that check is false, then it goes onto the last one which checks for if a disk was removed. If a disk was removed, then it shuts all the computer down, and sets the variable to false, which disables the main part of the program, while still listening for a disk to be added.
Importance of os.stopTimer: I really do not know how to explain this… but I will try using examples.
while true do
local myTimer = os.startTimer(1)
os.pullEvent()
print("hi")
If you were to run that code, if you did not hit any button after running it, you would notice it would print "hi" every one second. However, if you were to hit a key, which fires a event, it would then start printing "hi" every half of a second. This is because the original timer is still running, but you have created another one before it has fired. So you have 2 timers running with a 1 second interval.
I think I have hit everything. If you need anything specific feel free to ask. :D/>
edit:
For anyone who is looking back on any of this code just know there is some errors in it. I wrote it at midnight one night, and am too lazy to fix all of them right now. This is more showing what goes where than anything, it is not for copy paste use. :P/>