Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the positions and sizes of the buttons
- local leftButton = {x = 5, y = 5, width = 10, height = 3}
- local rightButton = {x = 20, y = 5, width = 10, height = 3}
- -- Function to draw a button
- local function drawButton(button, label, bgColor, textColor)
- term.setBackgroundColor(bgColor)
- term.setTextColor(textColor)
- term.setCursorPos(button.x, button.y)
- term.clearLine()
- term.setCursorPos(button.x + math.floor((button.width - #label) / 2), button.y + math.floor(button.height / 2))
- term.write(label)
- end
- -- Function to check if a point is within a button
- local function isWithinButton(button, x, y)
- return x >= button.x and x < button.x + button.width and y >= button.y and y < button.y + button.height
- end
- -- Function to handle button clicks
- local function handleButtonClick(x, y)
- if isWithinButton(leftButton, x, y) then
- redstone.setOutput("left", true)
- sleep(0.5)
- redstone.setOutput("left", false)
- elseif isWithinButton(rightButton, x, y) then
- redstone.setOutput("right", true)
- sleep(0.5)
- redstone.setOutput("right", false)
- end
- end
- -- Main function to draw buttons and handle input
- local function main()
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Click the buttons to send redstone signals:")
- drawButton(leftButton, "Left", colors.blue, colors.white)
- drawButton(rightButton, "Right", colors.green, colors.white)
- while true do
- local event, button, x, y = os.pullEvent("monitor_touch")
- handleButtonClick(x, y)
- end
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement