Advertisement
DubSlime

elevator-button

Apr 28th, 2025 (edited)
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. -- Elevator Button - ASCII with Door Animation
  2. local monitor = peripheral.find("monitor")
  3. monitor.setTextScale(1)
  4.  
  5. -- Set up colors
  6. local callBgColor = colors.orange
  7. local hereBgColor = colors.lime
  8. local textColor = colors.black
  9.  
  10. -- ICONS (ASCII only, fitting 7x5)
  11. local callIcon = {
  12. " ",
  13. " | ",
  14. " | ",
  15. " / \\ ",
  16. " "
  17. }
  18.  
  19. local hereClosed = {
  20. "| |",
  21. "| |",
  22. "| |",
  23. "| |",
  24. "| |"
  25. }
  26.  
  27. local hereOpen1 = {
  28. "| |",
  29. " \\ / ",
  30. " \\ / ",
  31. " / \\ ",
  32. " / \\ "
  33. }
  34.  
  35. local hereOpen2 = {
  36. " ",
  37. " | ",
  38. " | ",
  39. " | ",
  40. " "
  41. }
  42.  
  43. -- Helper to draw an icon
  44. local function drawIcon(icon, bgColor)
  45. monitor.setBackgroundColor(bgColor)
  46. monitor.clear()
  47. monitor.setTextColor(textColor)
  48. for y, line in ipairs(icon) do
  49. monitor.setCursorPos(1, y)
  50. monitor.write(line)
  51. end
  52. end
  53.  
  54. -- Fancy door opening animation
  55. local function doorAnimation()
  56. local frames = {
  57. hereClosed,
  58. hereOpen1,
  59. hereOpen2
  60. }
  61. for i, frame in ipairs(frames) do
  62. drawIcon(frame, hereBgColor)
  63. sleep(0.3)
  64. end
  65. drawIcon(hereClosed, hereBgColor) -- Reclose after animation
  66. end
  67.  
  68. -- Send redstone pulse to left
  69. local function sendPulse()
  70. redstone.setOutput("left", true)
  71. sleep(0.2)
  72. redstone.setOutput("left", false)
  73. end
  74.  
  75. -- Main loop
  76. local previousState = nil
  77.  
  78. while true do
  79. local elevatorHere = redstone.getInput("front")
  80.  
  81. -- Update display if state changed
  82. if elevatorHere ~= previousState then
  83. if elevatorHere then
  84. drawIcon(hereClosed, hereBgColor)
  85. else
  86. drawIcon(callIcon, callBgColor)
  87. end
  88. previousState = elevatorHere
  89. end
  90.  
  91. -- Listen for touch events
  92. local event = os.pullEventRaw()
  93. if event == "monitor_touch" then
  94. if elevatorHere then
  95. doorAnimation()
  96. else
  97. sendPulse()
  98. end
  99. end
  100.  
  101. sleep(0.1) -- Tiny wait to not overwork CPU
  102. end
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement