Advertisement
Sazra

ElevatorMonitor

May 20th, 2022 (edited)
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. --# load the touchpoint API
  2. os.loadAPI("touchpoint")
  3.  
  4. local mes
  5.  
  6. --# opens rednet
  7. rednet.open("bottom")
  8.  
  9. --# intialize a new button set on the top monitor
  10. local t = touchpoint.new("top")
  11. local monitor = peripheral.find("monitor")
  12. monitor.setTextScale(0.5)
  13.  
  14. function setMessage(nr)
  15. mes = nr
  16. print(mes)
  17. end
  18.  
  19. --# add two buttons
  20. t:add("EG", nil, 1, 1, 36, 4, colors.red, colors.lime)
  21. t:add("U1", nil, 1, 5, 36, 8, colors.red, colors.lime)
  22. t:add("U2", nil, 1, 9, 36, 12, colors.red, colors.lime)
  23. t:add("U3", nil, 1, 13, 36, 16, colors.red, colors.lime)
  24. t:add("U4", nil, 1, 17, 36, 20, colors.red, colors.lime)
  25. t:add("U5", nil, 1, 21, 36, 24, colors.red, colors.lime)
  26.  
  27. --# draw the buttons
  28. t:draw()
  29.  
  30. while true do
  31.         --# handleEvents will convert monitor_touch events to button_click if it was on a button
  32.         local event, p1 = t:handleEvents(os.pullEvent())
  33.         if event == "button_click" then
  34.             --# p1 will be "left" or "right", since those are the button labels
  35.             --# toggle the button that was clicked.
  36.             t:flash(p1)
  37.             if p1 == "EG" then setMessage(6)
  38.             elseif p1 == "U1" then setMessage(5)
  39.             elseif p1 == "U2" then setMessage(4)
  40.             elseif p1 == "U3" then setMessage(3)
  41.             elseif p1 == "U4" then setMessage(2)
  42.             elseif p1 == "U5" then setMessage(1)
  43.             end
  44.             rednet.send(17, mes)
  45.         end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement