Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initialize variables
- local channel = 11
- local countdownTime = 10
- local delayBeforeCountdown = 4 -- Delay in seconds before starting the countdown
- local modem = peripheral.find("modem")
- local monitor = peripheral.find("monitor")
- -- Get monitor dimensions
- local width, height = monitor.getSize()
- -- Open the channel
- modem.open(channel)
- -- Function to display text on a monitor
- local function displayOnMonitor(text, y, scale)
- monitor.setTextScale(scale)
- local x = math.ceil((width - #text) / 2) -- Calculate center based on text length
- monitor.setCursorPos(x, y)
- monitor.write(text)
- end
- -- Function to run the countdown
- local function runCountdown()
- sleep(delayBeforeCountdown) -- Wait for 4 seconds before starting the countdown
- -- Display "T-MINUS TO LAUNCH:" on the first line
- displayOnMonitor("T-MINUS TO LAUNCH:", 1, 1)
- for i = countdownTime, 0, -1 do
- monitor.setCursorPos(1, 2)
- monitor.clearLine() -- Clear the line before displaying the new countdown number
- displayOnMonitor(tostring(i), 3, 3) -- Big number at the center
- sleep(1)
- end
- monitor.clear()
- displayOnMonitor("LAUNCH!", 3, 3) -- Display "LAUNCH!" at the end
- end
- -- Main loop to listen for messages
- while true do
- print("Listening for 'start' on channel " .. channel .. ".")
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if message == "start" then
- print("Received 'start', initiating countdown.")
- runCountdown()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement