Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------
- -- Программа --
- -- Бинарные часы для мода OpenComputers --
- -- проект http://computercraft.ru --
- -- 2017, © Asior --
- ------------------------------------------------
- cor = 3 --коррекция времени
- side = 2 --сторона куда подключен многожильный провод
- sms = '(+ 3:00)'
- ---------------------------------
- local com = require("component")
- local gpu = com.gpu
- local fs = require("filesystem")
- local rs = com.redstone
- ---------------------------------
- local function getTime(correction)
- local file = io.open('../tmp/clock.temp', 'w')
- file:write('')
- file:close()
- local lastmod = tonumber(string.sub(fs.lastModified('../tmp/clock.temp'), 1, -4))
- local hour = os.date('%H', lastmod) + correction
- local minute = os.date('%M', lastmod)
- return hour, minute
- end
- local function binarySystem(t)
- local a, s = {}, ''
- while t~=0 do
- a[#a+1]=math.fmod(t,2)
- t=math.floor(t/2)
- end
- for i=8, 1, -1 do
- if not a[i] then a[i]=0 end
- s=s..a[i]
- end
- return s
- end
- local function redSet(time)
- for i = 0, 15 do
- if string.sub(time, i+1, i+1) == '0' then
- rs.setBundledOutput(side, i, 0)
- else
- rs.setBundledOutput(side, i, 255)
- end
- end
- end
- local function stopRed()
- for i1 = 0, 5 do
- for i=0, 15 do
- if rs.getBundledInput(i1, i) > 0 then
- rs.setBundledOutput(i1, i, 0)
- end
- end
- end
- end
- ---------------------------------
- gpu.setResolution(33, 3)
- gpu.fill(1, 1, 33, 3, ' ')
- gpu.set(1, 1, 'Load..')
- stopRed()
- gpu.fill(1, 1, 33, 3, ' ')
- gpu.setForeground(0xffffff)
- while true do
- gpu.set(10, 1, 'Бинарные часы')
- local h, m = getTime(cor)
- local s = binarySystem(h)..binarySystem(m)
- gpu.set(2, 2, 'Реальное время: '..h..':'..m..' '..sms)
- gpu.set(1, 3, 'Бинарное время: '..string.sub(s, 1, 8)..':'..string.sub(s, 9))
- redSet(s)
- os.sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement