Advertisement
Pinkishu

clock

Feb 25th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. local updateRate = 0.08
  2. local updateTimer = os.startTimer(updateRate)
  3. local offsetX,offsetY=0,0
  4. local autoCenter = false
  5. local monSide = "top"
  6. local monScale = nil
  7. local writeTerm = term
  8.  
  9. if monSide then
  10.   writeTerm = peripheral.wrap(monSide)
  11.   if monScale then
  12.     writeTerm.setTextScale(monScale)
  13.   end
  14. end
  15.  
  16. if autoCenter then
  17.   local w = writeTerm.getSize()
  18.   offsetX = math.ceil(w/2) - 4 - 1
  19. end
  20.  
  21. while true do
  22.   local ev, uTimer = os.pullEvent("timer")
  23.   if updateTimer == uTimer then
  24.     writeTerm.setCursorPos(1+offsetX,1+offsetY)
  25.     writeTerm.clearLine()
  26.     local time = os.time()
  27.     local hours = math.floor(time)
  28.     local minutes = math.floor( (time - hours)*60)
  29.     local ampm = "am"
  30.  
  31.     if hours > 11 then
  32.       ampm = "pm"
  33.       if hours > 12 then
  34.         hours = hours - 12
  35.       end
  36.     elseif hours == 0 then hours = 12
  37.     end
  38.     writeTerm.write(string.format("%s:%s",(hours<10 and "0"..hours or hours),(minutes<10 and "0"..minutes or minutes)).. " " .. ampm)
  39.     updateTimer = os.startTimer(updateRate)
  40.   end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement