Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Step 1: Wrap the monitor peripheral
- local side = "left" -- Replace with the side the monitor is attached to
- local monitor = peripheral.wrap(side)
- -- Check if the monitor is wrapped successfully
- if not monitor then
- print("Error: No monitor found on the specified side: " .. side)
- return
- end
- -- Set text scale and redirection
- local clockTextScale = 2 -- Adjusted text scale for clock screen
- local titleTextScale = 2 -- Text scale for "Real Time" title
- local songSelectorTextScale = 2 -- Adjust text scale for song selector
- monitor.setTextScale(clockTextScale)
- term.redirect(monitor)
- -- Function to get the current time as a table
- local function getRealTime()
- local time = os.date("*t")
- return {hour = time.hour, min = time.min}
- end
- -- Function to display the time centered on the monitor
- local function displayTime()
- local currentTime = getRealTime()
- local monitorWidth, monitorHeight = monitor.getSize()
- -- Calculate text position for centering
- local text = string.format("%02d:%02d", currentTime.hour, currentTime.min)
- local textWidth = #text * clockTextScale
- local xPos = math.floor((monitorWidth - textWidth) / 2) + 4
- local yPos = math.floor((monitorHeight - 1) / 2) -- Center vertically
- -- Clear screen and display time
- monitor.clear()
- monitor.setCursorPos(xPos, yPos)
- monitor.setTextColor(colors.orange)
- monitor.write(text)
- -- Display "Real Time" title
- local title = "Real Time"
- local titleWidth = #title * titleTextScale
- local titleXPos = math.floor((monitorWidth - titleWidth) / 2) + 6
- monitor.setCursorPos(titleXPos, 1)
- monitor.setTextColor(colors.red)
- monitor.setTextScale(titleTextScale)
- monitor.write(title)
- end
- -- Function to display the song selector on the monitor
- local function displaySongSelector()
- monitor.setTextScale(songSelectorTextScale)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.setTextColor(colors.white)
- monitor.write("Select a song:")
- -- Display touch indicator to switch back to clock
- monitor.setCursorPos(monitor.getWidth() - 2, monitor.getHeight() - 1)
- monitor.setTextColor(colors.yellow)
- monitor.write(">>") -- Double angle bracket pointing right
- local yOffset = 2
- for i, song in ipairs(songs) do
- monitor.setCursorPos(1, i + yOffset)
- monitor.write(i .. ". " .. song)
- end
- end
- -- List of songs
- local songs = {
- "Anarchy",
- "Daisuki",
- "FriendlyCreatures",
- "PsychoHead",
- "Psychosocial",
- "seila",
- "SunnyDay",
- "WhiteNight"
- }
- -- Function to get user input
- local function getUserSelection()
- print("Enter the number of the song to play:")
- local choice = tonumber(read())
- if choice and choice >= 1 and choice <= #songs then
- return songs[choice]
- else
- print("Invalid selection. Please try again.")
- return getUserSelection()
- end
- end
- -- Main loop to continuously update and display the time, unless screen is touched
- while true do
- displayTime()
- local event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if xPos >= monitor.getWidth() - 2 and yPos == monitor.getHeight() - 1 then
- -- Switch to song selector screen
- displaySongSelector()
- local selectedSong = getUserSelection()
- print("You selected: " .. selectedSong)
- -- Send the selection to the network
- rednet.open("back") -- Adjust the side as necessary
- rednet.broadcast(selectedSong)
- print("Song selection sent to network.")
- sleep(2) -- Delay to see the selection before returning to clock display
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement