Advertisement
Fraeric123

OnOffSwitch

May 18th, 2025 (edited)
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | Gaming | 0 0
  1. local component = require("component")
  2. local sides = require("sides")
  3. local term = require("term")
  4.  
  5. local outputSide = sides.top
  6. local rsAddress = nil
  7.  
  8. for address, ctype in component.list("redstone") do
  9.     rsAddress = address
  10.     break
  11. end    
  12.  
  13. if rsAddress == nil then
  14.     print("No redstone IO")
  15.     exit()
  16. end
  17.  
  18. local rs = component.proxy(rsAddress)
  19.  
  20. function zapnout()
  21.     term.clear()
  22.     rs.setOutput(outputSide, 15)
  23.     print("Redstone zapnut.")
  24.     os.sleep(0.5)
  25.     menu()
  26. end
  27.  
  28. function vypnout()
  29.     term.clear()
  30.     rs.setOutput(outputSide, 0)
  31.     print("Redstone vypnut.")
  32.     os.sleep(0.5)
  33.     menu()
  34. end
  35.  
  36. function menu()
  37.     term.clear()
  38.     print("Redstone ovládání")
  39.     print("1 - Zapnout")
  40.     print("2 - Vypnout")
  41.    
  42.     local input = io.read()
  43.     if input == "1" then
  44.         zapnout()
  45.     elseif input == "2" then
  46.         vypnout()
  47.     else
  48.         print("Neplatná volba.")
  49.     end
  50. end
  51.  
  52. menu()
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement
OSZAR »