Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function initialize()
- in1=peripheral.wrap("flux_gate_102")
- out1=peripheral.wrap("flux_gate_101")
- cap1=peripheral.wrap("draconic_rf_storage_28")
- mon=peripheral.wrap("right")
- isCap1={empty=false,full=false,outp=false,inp=false,c=false}
- maxIn=50000000000
- maxOut=5000000
- start=false
- i=0
- count=0
- gate=true
- end
- function disp()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print(start)
- print("cap1:empty:"..(isCap1.empty and 'true' or 'false').." ,full:"..(isCap1.full and 'true' or 'false').." ,outp:"..(isCap1.outp and 'true' or 'false').." ,inp:"..(isCap1.inp and 'true' or 'false'))
- print("i: "..i.." ,count: "..count)
- mon.clear()
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.setCursorPos(2,2)
- mon.write("+")
- mon.setCursorPos(4,2)
- mon.write("-")
- mon.setCursorPos(6,2)
- mon.write(i)
- mon.setCursorPos(2,4)
- mon.write("start")
- sleep(0.1)
- end
- end
- function gates()
- while true do
- if start then
- if gate then
- count=0
- isCap1.outp=true
- gate=false
- end
- end
- if count==i then
- start=false
- gate=true
- end
- -- cap1 empty/full begin
- if cap1.getEnergyStored()==cap1.getMaxEnergyStored() then
- isCap1.full=true
- else
- isCap1.full=false
- end
- if cap1.getEnergyStored()==0 then
- isCap1.empty=true
- else
- isCap1.empty=false
- end
- -- cap1 empty/full end
- --cap1 set in/out flow begin
- if isCap1.outp then
- out1.setSignalLowFlow(maxOut)
- else
- out1.setSignalLowFlow(0)
- end
- if isCap1.inp then
- in1.setSignalLowFlow(maxIn)
- else
- in1.setSignalLowFlow(0)
- end
- if isCap1.empty and isCap1.outp then
- isCap1.outp=false
- isCap1.c=true
- end
- if isCap1.full and isCap1.inp then
- isCap1.inp=false
- end
- -- cap1 fill/unfill start/stop begin
- --fill
- if isCap1.empty and not isCap1.outp then
- isCap1.inp=true
- end
- --unfill
- if isCap1.full and not isCap1.inp and start then
- isCap1.outp=true
- count=count+1
- end
- -- cap1 fill/unfill start/stop end
- sleep(0.1)
- end
- end
- function buttons()
- while true do
- event, side, x, y=os.pullEvent("monitor_touch")
- print(x.." "..y)
- if x>1 and x < 3 and y==2 then
- i=i+1
- elseif x>3 and x<5 and y==2 then
- if i>0 then
- i=i-1
- end
- elseif x>1 and x<6 and y==4 then
- start=true
- end
- end
- end
- initialize()
- --print(cap1.getEnergyStored())
- parallel.waitForAny(buttons,disp,gates)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement