Gazer29

RemoteControlv1

May 15th, 2021 (edited)
262
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Radio Control v1 by Gazer29
  2.  
  3. local component = require("component")
  4. local term = require ("term")
  5. local trainRemote = component.ir_remote_control
  6. local RUNNING = true
  7. local flag = false
  8.  
  9. function helpdisplay()
  10.     print("Radio Control v1")
  11.     print("Commands:")
  12.     print("'Any number'    - Changes Throttle")
  13.     print("'stop'       - Ends program")
  14. end
  15.  
  16. ----------- Main loop ------------ 
  17.  
  18. trainRemote.setBrake(0)
  19.  
  20. while RUNNING do
  21.     term.clear()
  22.     helpdisplay()
  23.     user = nil
  24.     user = io.read()
  25.     if user == "stop" then 
  26.         print("STOPPING...")
  27.         os.sleep(1)
  28.         RUNNING = false
  29.         term.clear()
  30.         end
  31.     if user == "h" then
  32.         print("Horn")
  33.         trainRemote.horn()
  34.         end
  35.     if user == "b" then
  36.         print("Bell")
  37.         if flag == false then
  38.             trainRemote.bell(1)
  39.             flag = true
  40.             else
  41.             trainRemote.bell(0)
  42.             flag = false
  43.             end
  44.         end
  45.     if nil ~= tonumber(user) then
  46.         input = tonumber(user)
  47.         if -1 <= input and input <= 1 then
  48.             print("Setting Throttle: ", user)
  49.             trainRemote.setThrottle(input)
  50.             end
  51.         end
  52.     os.sleep(0.5)
  53. end
  54.  
  55. trainRemote.setThrottle(0)
  56. trainRemote.setBrake(1)
  57.    
RAW Paste Data