Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- takes about 56 seconds for a DM Generation loop to complete
- -- if you build a bigger one, increase TimeForParticleToReachFinalBend.
- -- ColliderActivationDuration should be fine.
- -- if you build a smaller one, experiment how long it takes the particle to
- -- reach the final bend, then add 2 seconds onto it (or dont... just experiment and
- -- see what works for you :]] )
- -- Mine is 78x78 and this code works perfectly for it. (78 as in 78 electromagnets on the bottom of each side)
- PACounter = 0
- CollisionPACounter = 0
- TimeForParticleToReachFinalBend = 48
- ColliderActivationDuration = 3
- ActivationDirection = "top"
- SignalingDirection = "bottom"
- -- a little less than 1 second due to code execution
- -- taking a tiny bit of extra time.
- PACounterSleepDuration = 0.95
- function PrintTerminal(text, posX, posY)
- term.setCursorPos(posX, posY)
- term.write(text)
- end
- function IsActivated()
- return redstone.getInput(ActivationDirection)
- end
- function ResetCounters()
- PACounter = 0
- CollisionPACounter = 0
- end
- function ActivatePA(paDirection, isActivate)
- redstone.setOutput(paDirection, isActivate)
- sleep(0.2)
- end
- function SetNotifyerSignalOutput(isActive)
- redstone.setOutput(SignalingDirection, isActive)
- end
- function ManualDeactivate()
- term.clear()
- PrintTerminal("Manually Deactivating Dark Matter Generator.", 1, 0)
- ActivatePA("right", false)
- ActivatePA("left", false)
- ResetCounters()
- sleep(1)
- end
- function PAGeneratorLoop()
- while (true) do
- ActivatePA("right", false)
- ActivatePA("left", false)
- ResetCounters()
- term.clear()
- term.setCursorPos(0,0)
- if (IsActivated()) then
- SetNotifyerSignalOutput(true)
- PrintTerminal("Dark Matter generator ONLINE", 1, 1)
- PrintTerminal("Turning on Main Particle Accelerator...", 1, 2)
- ActivatePA("right", true)
- PrintTerminal("Waiting for particle to reach the final bend", 1, 3)
- while (PACounter < TimeForParticleToReachFinalBend) do
- if (IsActivated() == false) then
- ManualDeactivate()
- return
- else
- PACounter = PACounter + 1
- term.setCursorPos(1, 4)
- term.write(PACounter .. " / " .. TimeForParticleToReachFinalBend)
- sleep(PACounterSleepDuration)
- end
- end
- PrintTerminal("Particle has reached final bend", 1, 4)
- PrintTerminal("Activating collision PA", 1, 5)
- ActivatePA("left", true)
- while (CollisionPACounter < ColliderActivationDuration) do
- if (IsActivated() == false) then
- ManualDeactivate()
- return
- else
- CollisionPACounter = CollisionPACounter + 1
- term.setCursorPos(1, 6)
- term.write(CollisionPACounter .. " / " .. ColliderActivationDuration)
- sleep(PACounterSleepDuration)
- end
- end
- PrintTerminal("Particles collided in the past ".. ColliderActivationDuration.. " secs.", 1, 7)
- PrintTerminal("Deactivating both PAs", 1, 8)
- ActivatePA("right", false)
- ActivatePA("left", false)
- ResetCounters()
- sleep(1)
- else
- SetNotifyerSignalOutput(false)
- term.clear()
- PrintTerminal("Dark Matter generator offline.", 1, 1)
- sleep(1)
- end
- end
- end
- function MainProgram()
- while true do
- PAGeneratorLoop()
- end
- end
- MainProgram()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement