csmit195

Touchpoint demo

Sep 29th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. --# load the touchpoint API
  2. os.loadAPI("touchpoint")
  3.  
  4. local monitor = peripheral.wrap('top')
  5. monitor.setTextScale(0.5)
  6.  
  7. --# intialize a new button set on the top monitor
  8. local t = touchpoint.new("top")
  9.  
  10. --# add two buttons
  11. t:add("left", nil, 2, 2, 14, 11, colors.red, colors.lime)
  12. t:add("right", nil, 16, 2, 28, 11, colors.red, colors.lime)
  13.  
  14. --# draw the buttons
  15. t:draw()
  16.  
  17. while true do
  18.         --# handleEvents will convert monitor_touch events to button_click if it was on a button
  19.         local event, p1 = t:handleEvents(os.pullEvent())
  20.         if event == "button_click" then
  21.                 --# p1 will be "left" or "right", since those are the button labels
  22.                 --# toggle the button that was clicked.
  23.                 t:toggleButton(p1)
  24.                 --# and toggle the redstone output on that side.
  25.                 rs.setOutput(p1, not rs.getOutput(p1))
  26.         end
  27. end
Add Comment
Please, Sign In to add comment