Advertisement
Sparkybearbomb

Clock

Nov 27th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. --Clock
  2. --By SparkyBearBomb
  3.  
  4. function monitorSearch()
  5.    local names = peripheral.getNames()
  6.    local i, name
  7.    for i, name in pairs(names) do
  8.       if peripheral.getType(name) == "monitor" then
  9.         test = name
  10.          return peripheral.wrap(name)
  11.       else
  12.          --return null
  13.       end
  14.    end
  15. end
  16.  
  17. function roundNumber(num, n)
  18.   local mult = 10^(n or 0)
  19.   return math.floor(num * mult + 0.5) / mult
  20. end
  21.  
  22. function heading(text)
  23.    w, h = mon.getSize()
  24.    mon.setCursorPos((w-string.len(text))/2+1, 1)
  25.    mon.write(text)
  26. end
  27. mon = monitorSearch()
  28.  
  29. while true do
  30.     time = os.time()
  31.     if (time>06.00) and (time<18.00) then
  32.         mon.setBackgroundColor(colors.white)
  33.         mon.setTextColor(colors.green)
  34.     else
  35.         mon.setBackgroundColor(colors.black)
  36.         mon.setTextColor(colors.red)
  37.     end
  38.     mon.setTextScale(5)
  39.     mon.setCursorPos(3,1)
  40.     mon.clear()
  41.     mon.write("00:00")
  42.     mon.setCursorPos(3,1)
  43.     if (time<10.00) then
  44.         mon.write("0")
  45.     end
  46.     time = roundNumber(time, 2)
  47.     mon.write(time)
  48.     sleep(0.5)
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement