Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ======================================
- -- Digital Clock Script for ComputerCraft
- -- brendan-at-slayweb.com 2013-02-15
- -- ======================================
- -- Expects first digit to be connected via bundled cable on the left side.
- -- Expects second digit to be connected via bundled cable on right side.
- -- Expects minute counter to be connected via bundled cable on the top.
- -- Bottom output sends a single on/off redstone signal indicating night/day.
- -- One digit is twenty lights which will form a full eight shape.
- -- ++++++++
- -- ++0000++
- -- ++0++0++
- -- ++0++0++
- -- ++0000++
- -- ++0++0++
- -- ++0++0++
- -- ++0000++
- -- ++++++++
- -- This is split in to 13 sections to be wired to the following colours.
- -- ++++++++
- -- ++1223++
- -- ++4++5++
- -- ++4++5++
- -- ++6778++
- -- ++9++A++
- -- ++9++A++
- -- ++BCCD++
- -- ++++++++
- -- 1: White
- -- 2: Orange
- -- 3: Magenta
- -- 4: Light Blue
- -- 5: Yellow
- -- 6: Lime
- -- 7: Pink
- -- 8: Cyan
- -- 9: Purple
- -- 10: (A) Blue
- -- 11: (B) Brown
- -- 12: (C) Green
- -- 13: (D) Red
- -- The minute counter is a cross of lights which light up two at a time every 15 world minutes.
- -- +++++++
- -- +++O+++
- -- ++OOO++
- -- +++O+++
- -- +++++++
- -- Wired as follows
- -- +++++++
- -- +++2+++
- -- ++513++
- -- +++4+++
- -- +++++++
- -- Patterns for numbers
- -- 0: 1,2,3,4,5,6,8,9,10,11,12,13
- -- 1: 3,5,8,10,13
- -- 2: 1,2,3,5,8,7,6,9,11,12,13
- -- 3: 1,2,3,5,6,7,8,10,11,12,13
- -- 4: 1,4,6,7,3,5,8,10,13
- -- 5: 1,2,3,4,6,7,8,10,13,12,11
- -- 6: 1,2,3,4,6,7,8,10,9,11,12,13
- -- 7: 1,2,3,5,8,10,13
- -- 8: 1,2,3,4,5,6,7,8,9,10,11,12,13
- -- 9: 1,2,3,4,5,6,7,8,10,11,12,13
- -- ======================
- -- Variables
- -- ======================
- server_time = 0
- old_hour = 0
- old_minute = 0
- old_q = 0
- current_hour = 0
- current_minute = 0
- current_q = 0
- -- ======================
- -- Colour Groups for numbers
- -- Colours for bundled outputs are just combinations of ints. These have been pre-calculated.
- -- These could be changed to use colors.combine()
- -- ======================
- n0 = 32319
- n1 = 18964
- n2 = 30327
- n3 = 31351
- n4 = 19069
- n5 = 31343
- n6 = 32367
- n7 = 18967
- n8 = 32383
- n9 = 31359
- q1 = 3
- q2 = 5
- q3 = 9
- q4 = 17
- -- ======================
- -- Functions
- -- ======================
- function update_time()
- server_time = os.time()
- print("Server Timestamp: "..server_time)
- old_hour = current_hour
- old_minute = current_minute
- local worldtime = server_time
- worldtime = textutils.formatTime(worldtime, true)
- if string.len(worldtime)<5 then
- current_hour = string.sub(worldtime, 1, 1)
- current_minute = string.sub(worldtime, 3, 4)
- else
- current_hour = string.sub(worldtime, 1, 2)
- current_minute = string.sub(worldtime, 4, 5)
- end
- old_q = current_q
- if current_minute>"0" then
- current_q = 1
- end
- if current_minute>"15" then
- current_q = 2
- end
- if current_minute>"30" then
- current_q = 3
- end
- if current_minute>"45" then
- current_q = 4
- end
- print("World Time: "..worldtime)
- print("Hour: "..current_hour)
- print("Minute: "..current_minute)
- print("Quarter: "..current_q)
- end
- function update_required()
- if current_hour~=old_hour then
- return true
- end
- if current_q~=old_q then
- return true
- end
- return false
- end
- function get_number_colors(num)
- if num=="" then
- return 0
- end
- if num=="0" then
- return n0
- end
- if num=="1" then
- return n1
- end
- if num=="2" then
- return n2
- end
- if num=="3" then
- return n3
- end
- if num=="4" then
- return n4
- end
- if num=="5" then
- return n5
- end
- if num=="6" then
- return n6
- end
- if num=="7" then
- return n7
- end
- if num=="8" then
- return n8
- end
- if num=="9" then
- return n9
- end
- return 0
- end
- function get_quarter_colors(num)
- if num=="" then
- return 0
- end
- if num==1 then
- return q1
- end
- if num==2 then
- return q2
- end
- if num==3 then
- return q3
- end
- if num==4 then
- return q4
- end
- return 0
- end
- function reload_display()
- local digit1 = ""
- local digit2 = ""
- if string.len(current_hour)>1 then
- -- Double digit hour
- digit1 = string.sub(current_hour,1,1)
- digit2 = string.sub(current_hour,2,2)
- else
- -- Single digit hour
- digit1 = ""
- digit2 = string.sub(current_hour,1,1)
- end
- -- Left output: Digit 1
- print("Digit 1: "..digit1)
- rs.setBundledOutput("left",get_number_colors(digit1))
- -- Right output: Digit 2
- print("Digit 2: "..digit2)
- rs.setBundledOutput("right",get_number_colors(digit2))
- -- Top output: Quarter
- rs.setBundledOutput("top",get_quarter_colors(current_q))
- -- Bottom output: Day/Night
- -- Send redstone signal if night time
- if (server_time>8) and (server_time<"20") then
- print("Day")
- rs.setOutput("bottom",false)
- else
- print("Night")
- rs.setOutput("bottom",true)
- end
- end
- -- ======================
- -- Main Program
- -- ======================
- function display_loop()
- term.clear()
- term.setCursorPos(1,1)
- update_time()
- if update_required() then
- reload_display()
- end
- end
- while true do
- display_loop()
- sleep(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement