Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local i = 0
- local data = false
- local hold = false
- local normal = "normal"
- local reverse = "reverse"
- local mode = ""
- local function pulse(side, ticks)
- rs.setOutput(side, true)
- sleep(ticks / 10)
- rs.setOutput(side, false)
- end
- local function countNormal()
- pulse("left", 2)
- while true do
- data = rs.getInput("back")
- if data and not hold == true then
- pulse("left", 2)
- i = i + 1
- print(i)
- end
- hold = data
- if rs.getInput("right") == true then
- break
- end
- os.sleep(0.01)
- end
- end
- local function program()
- write("Select mode (normal, reverse): ")
- mode = read()
- if mode == normal then
- countNormal()
- elseif mode == reverse then
- rs.setOutput("bottom", true)
- countNormal()
- rs.setOutput("bottom", false)
- else
- print("Error: mode not allowed (" .. mode ..") , retry")
- os.sleep(2)
- term.clear()
- term.setCursorPos(1, 1)
- program()
- end
- end
- program()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement