Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Elevator Button - ASCII with Door Animation
- local monitor = peripheral.find("monitor")
- monitor.setTextScale(1)
- -- Set up colors
- local callBgColor = colors.orange
- local hereBgColor = colors.lime
- local textColor = colors.black
- -- ICONS (ASCII only, fitting 7x5)
- local callIcon = {
- " ",
- " | ",
- " | ",
- " / \\ ",
- " "
- }
- local hereClosed = {
- "| |",
- "| |",
- "| |",
- "| |",
- "| |"
- }
- local hereOpen1 = {
- "| |",
- " \\ / ",
- " \\ / ",
- " / \\ ",
- " / \\ "
- }
- local hereOpen2 = {
- " ",
- " | ",
- " | ",
- " | ",
- " "
- }
- -- Helper to draw an icon
- local function drawIcon(icon, bgColor)
- monitor.setBackgroundColor(bgColor)
- monitor.clear()
- monitor.setTextColor(textColor)
- for y, line in ipairs(icon) do
- monitor.setCursorPos(1, y)
- monitor.write(line)
- end
- end
- -- Fancy door opening animation
- local function doorAnimation()
- local frames = {
- hereClosed,
- hereOpen1,
- hereOpen2
- }
- for i, frame in ipairs(frames) do
- drawIcon(frame, hereBgColor)
- sleep(0.3)
- end
- drawIcon(hereClosed, hereBgColor) -- Reclose after animation
- end
- -- Send redstone pulse to left
- local function sendPulse()
- redstone.setOutput("left", true)
- sleep(0.2)
- redstone.setOutput("left", false)
- end
- -- Main loop
- local previousState = nil
- while true do
- local elevatorHere = redstone.getInput("front")
- -- Update display if state changed
- if elevatorHere ~= previousState then
- if elevatorHere then
- drawIcon(hereClosed, hereBgColor)
- else
- drawIcon(callIcon, callBgColor)
- end
- previousState = elevatorHere
- end
- -- Listen for touch events
- local event = os.pullEventRaw()
- if event == "monitor_touch" then
- if elevatorHere then
- doorAnimation()
- else
- sendPulse()
- end
- end
- sleep(0.1) -- Tiny wait to not overwork CPU
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement