Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Versioning, etc.
- SoftwareName = "Create Generator Speed Control"
- SoftwareVersion = "v0.1.0"
- --Config Code
- MaxSpeedPercent=95
- MinSpeedPercent=90
- --HouseKeeping Code
- function newline()
- x,y = term.getCursorPos()
- term.setCursorPos(1,y+1)
- end
- --Wrapping Relevant Peripherals
- stressometer = peripheral.find("Create_Stressometer")
- controller = peripheral.find("Create_RotationSpeedController")
- --Main Loop
- while true do
- --Assign and calculate stress numbers
- stress = stressometer.getStress()
- capacity = stressometer.getStressCapacity()
- stressPercentage = (stress / capacity)*100
- --Get current speed
- speed = controller.getTargetSpeed()
- --Test for thresholds
- if stressPercentage > 100 then
- --Set Speed to 1 if overstressed
- controller.setTargetSpeed(1)
- elseif stressPercentage > MaxSpeedPercent then
- --Reduce Speed by 1 if too high
- controller.setTargetSpeed(speed-1)
- elseif stressPercentage < MinSpeedPercent then
- --Increase Speed by 1 if too low
- controller.setTargetSpeed(speed+1)
- end
- --Display Loop
- term.clear()
- term.setCursorPos(1,1)
- term.write("--"..SoftwareName.."|"..SoftwareVersion.."--")
- newline()
- term.write("Stress "..stress.."/"..capacity.." ("..stressPercentage..")")
- newline()
- term.write("Speed: "..speed)
- --Mandatory wait to reduce clocktime
- os.sleep(1/20)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement