Advertisement
blawhar

newtest

May 24th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. function initialize()
  2. in1=peripheral.wrap("flux_gate_102")
  3. out1=peripheral.wrap("flux_gate_101")
  4. cap1=peripheral.wrap("draconic_rf_storage_28")
  5. mon=peripheral.wrap("right")
  6. isCap1={empty=false,full=false,outp=false,inp=false,c=false}
  7. maxIn=50000000000
  8. maxOut=5000000
  9.  
  10. start=false
  11. i=0
  12. count=0
  13. gate=true
  14.  
  15. end
  16.  
  17. function disp()
  18. while true do
  19.  
  20. term.clear()
  21. term.setCursorPos(1,1)
  22. print(start)
  23. 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'))
  24. print("i: "..i.." ,count: "..count)
  25.  
  26. mon.clear()
  27. mon.setBackgroundColor(colors.black)
  28. mon.setTextColor(colors.white)
  29. mon.setCursorPos(2,2)
  30. mon.write("+")
  31. mon.setCursorPos(4,2)
  32. mon.write("-")
  33. mon.setCursorPos(6,2)
  34. mon.write(i)
  35. mon.setCursorPos(2,4)
  36. mon.write("start")
  37. sleep(0.1)
  38. end
  39. end
  40.  
  41.  
  42.  
  43. function gates()
  44. while true do
  45.  
  46. if start then
  47. if gate then
  48. count=0
  49. isCap1.outp=true
  50. gate=false
  51. end
  52. end
  53.  
  54.  
  55. if count==i then
  56. start=false
  57. gate=true
  58. end
  59.  
  60. -- cap1 empty/full begin
  61. if cap1.getEnergyStored()==cap1.getMaxEnergyStored() then
  62. isCap1.full=true
  63. else
  64. isCap1.full=false
  65. end
  66.  
  67. if cap1.getEnergyStored()==0 then
  68. isCap1.empty=true
  69. else
  70. isCap1.empty=false
  71. end
  72.  
  73. -- cap1 empty/full end
  74.  
  75. --cap1 set in/out flow begin
  76. if isCap1.outp then
  77. out1.setSignalLowFlow(maxOut)
  78. else
  79. out1.setSignalLowFlow(0)
  80. end
  81.  
  82.  
  83. if isCap1.inp then
  84. in1.setSignalLowFlow(maxIn)
  85. else
  86. in1.setSignalLowFlow(0)
  87. end
  88.  
  89.  
  90. if isCap1.empty and isCap1.outp then
  91. isCap1.outp=false
  92. isCap1.c=true
  93. end
  94.  
  95. if isCap1.full and isCap1.inp then
  96. isCap1.inp=false
  97. end
  98.  
  99. -- cap1 fill/unfill start/stop begin
  100. --fill
  101. if isCap1.empty and not isCap1.outp then
  102. isCap1.inp=true
  103. end
  104. --unfill
  105. if isCap1.full and not isCap1.inp and start then
  106. isCap1.outp=true
  107. count=count+1
  108. end
  109.  
  110. -- cap1 fill/unfill start/stop end
  111.  
  112. sleep(0.1)
  113. end
  114. end
  115.  
  116.  
  117.  
  118.  
  119.  
  120. function buttons()
  121. while true do
  122.  
  123. event, side, x, y=os.pullEvent("monitor_touch")
  124. print(x.." "..y)
  125. if x>1 and x < 3 and y==2 then
  126. i=i+1
  127. elseif x>3 and x<5 and y==2 then
  128. if i>0 then
  129. i=i-1
  130. end
  131. elseif x>1 and x<6 and y==4 then
  132. start=true
  133. end
  134.  
  135. end
  136. end
  137.  
  138. initialize()
  139. --print(cap1.getEnergyStored())
  140.  
  141. parallel.waitForAny(buttons,disp,gates)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement