ThatGravyBoat

Speed Controller

Feb 1st, 2022 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. --Speed Controller
  2. --Consts--
  3. local motor = peripheral.find("electric_motor")
  4.  
  5. term.clear()
  6. term.scroll(-2)
  7.  
  8. while true do
  9. term.scroll(-1)
  10. print("Enter Speed: ")
  11. local input = read()
  12.  
  13. if input:match("^%-?%d+$") then
  14. local num = tonumber(input, 10)
  15. if num > 256 or num < -256 then
  16. print("[ERROR]: Invalid Number, Number must be between 256 and -256")
  17. else
  18. motor.setSpeed(num)
  19. print("[INFO]: Speed was successfully set to " .. num)
  20. end
  21. else
  22. print("[ERROR]: Input was not a number.")
  23. end
  24. sleep(2)
  25. term.clear()
  26. end
Advertisement
Add Comment
Please, Sign In to add comment