Advertisement
JoshBoshGames

Create Generator Speed Control

Jul 5th, 2025
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | Gaming | 0 0
  1. --Versioning, etc.
  2. SoftwareName = "Create Generator Speed Control"
  3. SoftwareVersion = "v0.1.0"
  4.  
  5. --Config Code
  6. MaxSpeedPercent=95
  7. MinSpeedPercent=90
  8.  
  9. --HouseKeeping Code
  10. function newline()
  11.     x,y = term.getCursorPos()
  12.     term.setCursorPos(1,y+1)
  13. end
  14.  
  15. --Wrapping Relevant Peripherals
  16. stressometer = peripheral.find("Create_Stressometer")
  17. controller = peripheral.find("Create_RotationSpeedController")
  18.  
  19. --Main Loop
  20. while true do
  21.  
  22.     --Assign and calculate stress numbers
  23.     stress = stressometer.getStress()
  24.     capacity = stressometer.getStressCapacity()
  25.     stressPercentage = (stress / capacity)*100
  26.    
  27.     --Get current speed
  28.     speed = controller.getTargetSpeed()
  29.  
  30.     --Test for thresholds
  31.     if stressPercentage > 100 then
  32.         --Set Speed to 1 if overstressed
  33.         controller.setTargetSpeed(1)
  34.     elseif stressPercentage > MaxSpeedPercent then
  35.         --Reduce Speed by 1 if too high
  36.         controller.setTargetSpeed(speed-1)
  37.        
  38.     elseif stressPercentage < MinSpeedPercent then
  39.         --Increase Speed by 1 if too low
  40.         controller.setTargetSpeed(speed+1)
  41.  
  42.     end
  43.  
  44.     --Display Loop
  45.     term.clear()
  46.     term.setCursorPos(1,1)
  47.     term.write("--"..SoftwareName.."|"..SoftwareVersion.."--")
  48.     newline()
  49.     term.write("Stress "..stress.."/"..capacity.." ("..stressPercentage..")")
  50.     newline()
  51.     term.write("Speed: "..speed)  
  52.  
  53.     --Mandatory wait to reduce clocktime
  54.     os.sleep(1/20)
  55.  
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement