Guest User

Untitled

a guest
Nov 18th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.60 KB | None | 0 0
  1. --giant clock--
  2. local sSide = {
  3. "left",
  4. "right",
  5. "top",
  6. "bottom",
  7. "back",
  8. "front"
  9. }
  10. --peripheral check
  11. for i=1,#sSide do
  12. if peripheral.isPresent(sSide[i]) then
  13.     if peripheral.getType(sSide[i]) == "monitor" then mon = peripheral.wrap(sSide[i])
  14.     elseif peripheral.getType(sSide[i])==nil then
  15.         error("No peripheral attached")
  16.     end
  17. end
  18. end
  19. --variables
  20. local digits = {}
  21. digits[0]={"   ___  ",
  22.  "  / _ \\ ",
  23.  " | | | |",
  24.  " | | | |",
  25.  " | |_| |",
  26.  "  \\___/ "}
  27. digits[1]={"   __   ",
  28.  "  /_ |  ",
  29.  "   | |  ",
  30.  "   | |  ",
  31.  "   | |  ",
  32.  "   |_|  "}
  33. digits[2]={"  ___   ",
  34.  " |__ \\  ",
  35.  "    ) | ",
  36.  "   / /  ",
  37.  "  / /_  ",
  38.  " |____| "}
  39. digits[3]={"  ____  ",
  40.  " |___ \\ ",
  41.  "   __) |",
  42.  "  |__ < ",
  43.  "  ___) |",
  44.  " |____/ "}
  45. digits[4]={" _  _   ",
  46.  "| || |  ",
  47.  "| || |_ ",
  48.  "|__   _|",
  49.  "   | |  ",
  50.  "   |_|  "}
  51. digits[5]={"  _____ ",
  52.  " | ____|",
  53.  " | |__  ",
  54.  " |___ \\ ",
  55.  "  ___) |",
  56.  " |____/ "}
  57. digits[6]={"    __  ",
  58.  "   / /  ",
  59.  "  / /_  ",
  60.  " | '_ \\ ",
  61.  " | (_) |",
  62.  "  \\___/ "}
  63. digits[7]={" ______ ",
  64.  "|____  |",
  65.  "    / / ",
  66.  "   / /  ",
  67.  "  / /   ",
  68.  " /_/    "}
  69. digits[8]={"   ___  ",
  70.  "  / _ \\ ",
  71.  " | (_) |",
  72.  "  > _ < ",
  73.  " | (_) |",
  74.  "  \\___/ "}
  75. digits[9]={"   ___  ",
  76.  "  / _ \\ ",
  77.  " | (_) |",
  78.  "  \\__, |",
  79.  "    / / ",
  80.  "   /_/  "}
  81. digits[10]={"   ___  ",
  82.  "  / _ \\ ",
  83.  " | | | |",
  84.  " | | | |",
  85.  " | |_| |",
  86.  "  \\___/ "}
  87. digits[11]={"   __   ",
  88.  "  /_ |  ",
  89.  "   | |  ",
  90.  "   | |  ",
  91.  "   | |  ",
  92.  "   |_|  "}
  93. digits[12]={"  ___   ",
  94.  " |__ \\  ",
  95.  "    ) | ",
  96.  "   / /  ",
  97.  "  / /_  ",
  98.  " |____| "}
  99. local colon = {
  100.  "   ",
  101.  " _ ",
  102.  "(_)",
  103.  "   ",
  104.  " _ ",
  105.  "(_)"
  106. }
  107. local am = {
  108. "     ___       ___  ___  ",
  109. "    /   \\     |   \\/   | ",
  110. "   /  ^  \\    |  \\  /  | ",
  111. "  /  /_\\  \\   |  |\\/|  | ",
  112. " /  _____  \\  |  |  |  | ",
  113. "/__/     \\__\\ |__|  |__| "
  114. }
  115. local pm = {
  116. " ______    ___  ___  ",
  117. "|   _  \\  |   \\/   | ",
  118. "|  |_)  | |  \\  /  | ",
  119. "|   ___/  |  |\\/|  | ",
  120. "|  |      |  |  |  | ",
  121. "|__|      |__|  |__| "
  122. }
  123. --functions
  124. function digits12(h,m)
  125. mon.clear()
  126. --hours
  127. if h == 0 then
  128.     for i = 1,6 do
  129.         mon.setCursorPos(1,i+2)
  130.         mon.write(digits[1][i])
  131.         mon.setCursorPos(11,i+2)
  132.         mon.write(digits[2][i])
  133.     end
  134. elseif h < 12 then
  135.     if h < 10 and h >= 1 then
  136.         for i = 1,6 do
  137.             mon.setCursorPos(1,i+2)
  138.             mon.write(digits[0][i])
  139.             mon.setCursorPos(11,i+2)
  140.             mon.write(digits[h][i])
  141.         end
  142.     elseif h >= 10 and h < 20 then
  143.         for i = 1,6 do
  144.             mon.setCursorPos(1,i+2)
  145.             mon.write(digits[1][i])
  146.             mon.setCursorPos(11,i+2)
  147.             mon.write(digits[h][i])
  148.         end
  149.     end
  150. elseif h == 12 then
  151.     for i = 1,6 do
  152.         mon.setCursorPos(1,i+2)
  153.         mon.write(digits[1][i])
  154.         mon.setCursorPos(11,i+2)
  155.         mon.write(digits[2][i])
  156.     end
  157. elseif h > 12 and h < 24 then
  158.     local h = h - 12
  159.     if h < 10 then
  160.         mon.setCursorPos(1,3)
  161.         for i = 1,6 do
  162.             mon.setCursorPos(1,i+2)
  163.             mon.write(digits[0][i])
  164.             mon.setCursorPos(11,i+2)
  165.             mon.write(digits[h][i])
  166.         end
  167.     elseif h >= 10 and h < 20 then
  168.         for i = 1,6 do
  169.             mon.setCursorPos(1,i+2)
  170.             mon.write(digits[1][i])
  171.             mon.setCursorPos(11,i+2)
  172.             mon.write(digits[h][i])
  173.         end
  174.     end
  175. end
  176. --colon
  177. for i = 1,6 do
  178.     mon.setCursorPos(20,i+2)
  179.     mon.write(colon[i])
  180. end
  181. --minutes
  182. if m < 10 then
  183.     for i = 1,6 do
  184.         mon.setCursorPos(24,i+2)
  185.         mon.write(digits[0][i])
  186.         mon.setCursorPos(34,i+2)
  187.         mon.write(digits[m][i])
  188.     end
  189. elseif m >=10 and m < 20 then
  190.     local m = m-10
  191.     for i = 1,6 do
  192.         mon.setCursorPos(24,i+2)
  193.         mon.write(digits[1][i])
  194.         mon.setCursorPos(34,i+2)
  195.         mon.write(digits[m][i])
  196.     end
  197. elseif m >=20 and m < 30 then
  198.     local m = m-20
  199.     for i = 1,6 do
  200.         mon.setCursorPos(24,i+2)
  201.         mon.write(digits[2][i])
  202.         mon.setCursorPos(34,i+2)
  203.         mon.write(digits[m][i])
  204.     end
  205. elseif m >=30 and m < 40 then
  206.     local m = m-30
  207.     for i = 1,6 do
  208.         mon.setCursorPos(24,i+2)
  209.         mon.write(digits[3][i])
  210.         mon.setCursorPos(34,i+2)
  211.         mon.write(digits[m][i])
  212.     end
  213. elseif m >=40 and m < 50 then
  214.     local m = m-40
  215.     for i = 1,6 do
  216.         mon.setCursorPos(24,i+2)
  217.         mon.write(digits[4][i])
  218.         mon.setCursorPos(34,i+2)
  219.         mon.write(digits[m][i])
  220.     end
  221. elseif m >=50 then
  222.     local m = m-50
  223.     for i = 1,6 do
  224.         mon.setCursorPos(24,i+2)
  225.         mon.write(digits[5][i])
  226.         mon.setCursorPos(34,i+2)
  227.         mon.write(digits[m][i])
  228.     end
  229. end
  230. if h < 12 then
  231.     for i = 1,6 do
  232.     mon.setCursorPos(44,i+2)
  233.     mon.write(am[i])
  234.     end
  235. elseif h >= 12 then
  236.     for i = 1,6 do
  237.     mon.setCursorPos(44,i+2)
  238.     mon.write(pm[i])
  239.     end
  240. end
  241. end
  242.  
  243.  
  244. while true do
  245. local MChours = math.floor(os.time())
  246. local MCminutes = math.floor((os.time()-math.floor(os.time()))*60)
  247. digits12(MChours,MCminutes)
  248. sleep(0)
  249. end
Add Comment
Please, Sign In to add comment