Guest User

Untitled

a guest
Apr 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. -- Clock for display on a monitor
  2. -- Author: CecilKilmer
  3. -- Version: 1.0
  4. -- Date: 2013/09/15
  5.  
  6. -- Min width required (IE: 10:00 PM)
  7. minWidthReq = 8
  8. minHeightReq = 2
  9.  
  10. -- Figure out where our monitor is
  11. monitorSide = nil
  12. monitor = nil
  13.  
  14. if peripheral.getType("left") == "monitor" then
  15. monitorSide = "left"
  16. elseif peripheral.getType("right") == "monitor" then
  17. monitorSide = "right"
  18. elseif peripheral.getType("top") == "monitor" then
  19. monitorSide = "top"
  20. elseif peripheral.getType("bottom") == "monitor" then
  21. monitorSide = "bottom"
  22. elseif peripheral.getType("front") == "monitor" then
  23. monitorSide = "front"
  24. elseif peripheral.getType("back") == "monitor" then
  25. monitorSide = "back"
  26. end
  27.  
  28. screenWidth = 0
  29. screenHeight = 0
  30.  
  31. -- If we have one, redirect term to it
  32. if monitorSide ~= nil then
  33. monitor = peripheral.wrap(monitorSide)
  34. term.redirect(monitor)
  35.  
  36. local scale = 5.5
  37.  
  38. repeat
  39. scale = scale - 0.5
  40. monitor.setTextScale(scale)
  41. screenWidth, screenHeight = term.getSize()
  42. until screenWidth > minWidthReq and screenHeight > minHeightReq
  43. end
  44.  
  45. -- Determine our screen size
  46. screenWidth, screenHeight = term.getSize()
  47. yPos = screenHeight - minHeightReq
  48. yPos = math.floor(yPos / 2)
  49.  
  50. -- Main loop
  51. while true do
  52. term.clear()
  53.  
  54. local time = os.time()
  55. time = textutils.formatTime(time, false)
  56.  
  57. local xPos = screenWidth - string.len(time)
  58. xPos = math.ceil(xPos / 2)
  59. term.setCursorPos(xPos + 1, yPos + 2)
  60. print(time)
  61.  
  62. sleep(.1)
  63. end
Add Comment
Please, Sign In to add comment