daily pastebin goal
21%
SHARE
TWEET

Binary_clock

Asioron Jan 25th, 2017 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------------------------------------------
  2. --                 Программа                  --
  3. --    Бинарные часы для мода OpenComputers    --
  4. --       проект http://computercraft.ru       --
  5. --                2017, © Asior               --
  6. ------------------------------------------------
  7.  
  8. cor  = 3 --коррекция времени
  9. side = 2 --сторона куда подключен многожильный провод
  10. sms  = '(+ 3:00)'
  11. ---------------------------------
  12. local com = require("component")
  13. local gpu = com.gpu
  14. local fs  = require("filesystem")
  15. local rs  = com.redstone
  16. ---------------------------------
  17. local function getTime(correction)
  18.   local file = io.open('../tmp/clock.temp', 'w')
  19.   file:write('')
  20.   file:close()
  21.   local lastmod = tonumber(string.sub(fs.lastModified('../tmp/clock.temp'), 1, -4))
  22.   local hour = os.date('%H', lastmod) + correction
  23.   local minute  = os.date('%M', lastmod)  
  24.   return hour, minute
  25. end
  26.  
  27. local function binarySystem(t)
  28.   local a, s = {}, ''
  29.   while t~=0 do
  30.     a[#a+1]=math.fmod(t,2)
  31.     t=math.floor(t/2)
  32.   end
  33.   for i=8, 1, -1 do
  34.     if not a[i] then a[i]=0 end
  35.     s=s..a[i]
  36.   end
  37.   return s
  38. end
  39.  
  40. local function redSet(time)
  41.   for i = 0, 15 do
  42.     if string.sub(time, i+1, i+1) == '0' then
  43.       rs.setBundledOutput(side, i, 0)
  44.     else
  45.       rs.setBundledOutput(side, i, 255)
  46.     end
  47.   end
  48. end
  49.  
  50. local function stopRed()
  51.   for i1 = 0, 5 do
  52.     for i=0, 15 do
  53.       if rs.getBundledInput(i1, i) > 0 then
  54.         rs.setBundledOutput(i1, i, 0)
  55.       end
  56.     end
  57.   end
  58. end
  59. ---------------------------------
  60. gpu.setResolution(33, 3)
  61. gpu.fill(1, 1, 33, 3, ' ')
  62. gpu.set(1, 1, 'Load..')
  63. stopRed()
  64. gpu.fill(1, 1, 33, 3, ' ')
  65. gpu.setForeground(0xffffff)
  66. while true do
  67.   gpu.set(10, 1, 'Бинарные часы')
  68.   local h, m = getTime(cor)
  69.   local s = binarySystem(h)..binarySystem(m)
  70.   gpu.set(2, 2, 'Реальное время: '..h..':'..m..' '..sms)
  71.   gpu.set(1, 3, 'Бинарное время: '..string.sub(s, 1, 8)..':'..string.sub(s, 9))
  72.   redSet(s)
  73.   os.sleep(10)
  74. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top