Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Konfiguration
- local TICKER_MESSAGE = "Sehr geehrte Fahrgäste, auf Grund einer Baustelle fahren aktuell keine Züge. Wir bitten um Ihr Verständnis +++ Aktuell kann es zu Verzögerungen bei Bus und Stadtbahn kommen, Grund dafür ist eine Brücke die saniert wird. Wir bitten um Verständnis"
- local TICKER_SPEED = 0.3 -- Geschwindigkeit des Lauftextes (in Sekunden)
- local COL_WIDTHS = {4, 15, 5, 8, 8} -- Spaltenbreiten: Linie, Ziel, Gleis, Ankunft, Abfahrt
- -- Beispieldaten für die Tabelle
- local schedule = {
- {"S1", "Stuttgart Hbf", "3", "12:30", "12:32"},
- {"S2", "Schorndorf", "5", "12:35", "12:37"},
- {"U5", "Herrenberg", "1", "12:40", "12:42"},
- {"RE", "Tübingen Hbf", "9", "12:45", "12:47"},
- {"ICE", "München Hbf", "12", "12:50", "12:53"}
- }
- -- Monitor initialisieren
- local mon = peripheral.find("monitor")
- if mon then
- mon.setTextScale(0.5)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- else
- print("Kein Monitor gefunden! Verbinde einen Monitor.")
- return
- end
- local w, h = mon.getSize()
- local tickerOffset = 0
- -- Hauptfunktion
- while true do
- mon.clear()
- -- Uhrzeit und Datum oben rechts
- local time = textutils.formatTime(os.time(), false)
- local date = os.date("%d.%m.%Y")
- local datetime = time .. " " .. date
- mon.setCursorPos(w - #datetime + 1, 1)
- mon.write(datetime)
- -- Tabellen-Überschriften
- local headers = {"Linie", "Ziel", "Gleis", "Ankunft", "Abfahrt"}
- local yPos = 3
- local x = 2
- for i, header in ipairs(headers) do
- mon.setCursorPos(x, yPos - 1)
- mon.write(header)
- x = x + COL_WIDTHS[i] + 2
- end
- -- Trennlinie unter Überschriften
- mon.setCursorPos(1, yPos)
- mon.write(string.rep("-", w))
- -- Fahrplandaten
- for i, entry in ipairs(schedule) do
- if yPos + i <= h - 2 then
- x = 2
- for j, item in ipairs(entry) do
- mon.setCursorPos(x, yPos + i)
- mon.write(item)
- x = x + COL_WIDTHS[j] + 2
- end
- end
- end
- -- Lauftext (Ticker)
- local tickerY = h
- local displayText = TICKER_MESSAGE .. " +++ " .. TICKER_MESSAGE
- local tickerText = ""
- for i = 1, w do
- local idx = (tickerOffset + i - 1) % #displayText + 1
- tickerText = tickerText .. displayText:sub(idx, idx)
- end
- mon.setCursorPos(1, tickerY)
- mon.write(tickerText)
- tickerOffset = (tickerOffset + 1) % #displayText
- sleep(TICKER_SPEED)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement