Advertisement
AlexMastang

Minecraft Redstone LCD Firmware

Jul 3rd, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.10 KB | None | 0 0
  1. local i = 0
  2. local data = false
  3. local hold = false
  4. local normal = "normal"
  5. local reverse = "reverse"
  6. local mode = ""
  7.  
  8. local function pulse(side, ticks)
  9.     rs.setOutput(side, true)
  10.     sleep(ticks / 10)
  11.     rs.setOutput(side, false)
  12. end
  13.  
  14.  
  15. local function countNormal()    
  16.     pulse("left", 2)
  17.  
  18.     while true do
  19.         data = rs.getInput("back")
  20.    
  21.         if data and not hold == true then
  22.             pulse("left", 2)
  23.             i = i + 1
  24.             print(i)
  25.         end
  26.         hold = data
  27.    
  28.         if rs.getInput("right") == true then
  29.             break
  30.         end
  31.         os.sleep(0.01)
  32.     end
  33. end
  34.  
  35.  
  36. local function program()
  37.     write("Select mode (normal, reverse): ")
  38.     mode = read()
  39.    
  40.     if mode == normal then
  41.         countNormal()
  42.     elseif mode == reverse then
  43.         rs.setOutput("bottom", true)
  44.         countNormal()
  45.         rs.setOutput("bottom", false)
  46.     else
  47.         print("Error: mode not allowed (" .. mode ..") , retry")
  48.         os.sleep(2)
  49.         term.clear()
  50.         term.setCursorPos(1, 1)
  51.         program()
  52.     end
  53. end
  54.  
  55. program()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement