Advertisement
Mojokojo69

count

Sep 9th, 2023 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. -- Initialize variables
  2. local channel = 11
  3. local countdownTime = 10
  4. local delayBeforeCountdown = 4 -- Delay in seconds before starting the countdown
  5.  
  6. local modem = peripheral.find("modem")
  7. local monitor = peripheral.find("monitor")
  8.  
  9. -- Get monitor dimensions
  10. local width, height = monitor.getSize()
  11.  
  12. -- Open the channel
  13. modem.open(channel)
  14.  
  15. -- Function to display text on a monitor
  16. local function displayOnMonitor(text, y, scale)
  17. monitor.setTextScale(scale)
  18. local x = math.ceil((width - #text) / 2) -- Calculate center based on text length
  19. monitor.setCursorPos(x, y)
  20. monitor.write(text)
  21. end
  22.  
  23. -- Function to run the countdown
  24. local function runCountdown()
  25. sleep(delayBeforeCountdown) -- Wait for 4 seconds before starting the countdown
  26.  
  27. -- Display "T-MINUS TO LAUNCH:" on the first line
  28. displayOnMonitor("T-MINUS TO LAUNCH:", 1, 1)
  29.  
  30. for i = countdownTime, 0, -1 do
  31. monitor.setCursorPos(1, 2)
  32. monitor.clearLine() -- Clear the line before displaying the new countdown number
  33. displayOnMonitor(tostring(i), 3, 3) -- Big number at the center
  34. sleep(1)
  35. end
  36.  
  37. monitor.clear()
  38. displayOnMonitor("LAUNCH!", 3, 3) -- Display "LAUNCH!" at the end
  39. end
  40.  
  41. -- Main loop to listen for messages
  42. while true do
  43. print("Listening for 'start' on channel " .. channel .. ".")
  44. local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  45.  
  46. if message == "start" then
  47. print("Received 'start', initiating countdown.")
  48. runCountdown()
  49. end
  50. end
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement