Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- monitor prep
- mon = peripheral.wrap("left")
- mon.setTextScale(1)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- -- defining variables
- b1 = 0
- b2 = 0
- -- button creation function
- function button(x_pos, y_pos, x_end, y_end, text)
- mon.setCursorPos(x_pos, y_pos)
- mon.write(text)
- -- x_end, y_end = mon.getCursorPos()
- length = x_end - x_pos
- height = y_end - y_pos
- return x_pos, y_pos, length, height
- end
- -- button 1 on click funct.
- function b1on(x_pos, y_pos, x_end, y_end, text, rs_side)
- b1 = 1
- mon.setBackgroundColor(colors.lime)
- button(x_pos, y_pos, x_end, y_end, text)
- rs.setOutput((rs_side), true)
- end
- -- button 1 off click
- function b1off(x_pos, y_pos, x_end, y_end, text, rs_side)
- b1 = 0
- mon.setBackgroundColor(colors.red)
- button(x_pos, y_pos, x_end, y_end, text)
- rs.setOutput((rs_side), false)
- end
- -- button 2 on click
- function b2on(x_pos, y_pos, x_end, y_end, text, rs_side)
- b2 = 1
- mon.setBackgroundColor(colors.lime)
- button(x_pos, y_pos, x_end, y_end, text)
- rs.setOutput((rs_side), true)
- end
- --button 2 off click
- function b2off(x_pos, y_pos, x_end, y_end, text, rs_side)
- b2 = 0
- mon.setBackgroundColor(colors.red)
- button(x_pos, y_pos, x_end, y_end, text)
- rs.setOutput((rs_side), false)
- end
- --button properties
- mon.setBackgroundColor(colors.red)
- b1_prop = { button(5, 10, 13, 10, " Hello there ") }
- b2_prop = { button(20, 10, 27, 10, " General Kenobi ") }
- -- touch detect loop
- while true do
- event, _, x_pos, y_pos = os.pullEvent("monitor_touch")
- --button 1 trigger
- if x_pos >= b1_prop[1]
- and x_pos <= b1_prop[3]
- and y_pos >= b1_prop[2]
- and y_pos <= b1_prop[4]
- and b1 == 0
- then
- b1on(5, 10, 13, 10, " Hello there ", "top")
- elseif
- b1 == 1
- then
- b1off(5, 10, 13, 10, " Hello there ", "top")
- -- button 2 trigger
- elseif x_pos >= b2_prop[1]
- and x_pos <= b2_prop[3]
- and y_pos >= b2_prop[2]
- and y_pos <= b2_prop[4]
- and b2 == 0
- then
- b2on(20, 10, 27, 10, " General Kenobi ", "right")
- elseif
- b2 == 1
- then
- b2off(20, 10, 27, 10, " General Kenobi ", "right")
- --else
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement