svennp

live clock

Feb 28th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. line = true
  2. power = true
  3. location = "Europe/Oslo"
  4.  
  5. for k,v in pairs(rs.getSides()) do
  6.   if peripheral.getType(v) == "monitor" then
  7.     mon = peripheral.wrap(v)
  8.     break
  9.   end
  10. end
  11. mon.setTextScale(4)
  12.  
  13. function printTime()
  14.   time = http.get("http://ts.svennp.com/time.php?location="..location).readAll()
  15.   os.startTimer(0.95)
  16.   mon.clear()
  17.   mon.setCursorPos(1,1)
  18.   if mon.isColor() then
  19.     mon.setBackgroundColor(colors.green)
  20.   end
  21.   if #time == 4 then
  22.     mon.write("0")
  23.   end
  24.   mon.write(time)
  25.   mon.setCursorPos(3,1)
  26.   if line then
  27.     mon.write(":")
  28.   else
  29.     mon.write(" ")
  30.   end
  31.   line = not line
  32. end
  33.  
  34. printTime()
  35.  
  36. repeat
  37.   e,p1 = os.pullEvent()
  38.   if e == "timer" and power then
  39.     printTime()
  40.   elseif e == "redstone" or e == "monitor_touch" then
  41.     if power then
  42.       if mon.isColor() then
  43.         mon.setBackgroundColor(colors.red)
  44.         mon.setCursorPos(1,1)
  45.         if #time == 4 then
  46.           mon.write("0")
  47.         end
  48.         mon.write(time)
  49.       end
  50.       if e == "redstone" then
  51.         os.pullEvent("redstone")
  52.       end
  53.     else
  54.       printTime()
  55.     end
  56.     power = not power
  57.   end
  58. until e == "char" and p1 == "q"
Add Comment
Please, Sign In to add comment