Guest User

Untitled

a guest
Oct 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. -- BroTech 7 segment display clock
  2.  
  3. function writeBundle(sSide, seg1, seg2)
  4.  rs.setBundledOutput(sSide, 0)
  5.  fOut = 0
  6.  
  7.  if seg1[1] == 1 then fOut = fOut + colors.brown end
  8.  if seg1[2] == 1 then fOut = fOut + colors.purple end
  9.  if seg1[3] == 1 then fOut = fOut + colors.yellow end
  10.  if seg1[4] == 1 then fOut = fOut + colors.magenta end
  11.  if seg1[5] == 1 then fOut = fOut + colors.orange end
  12.  if seg1[6] == 1 then fOut = fOut + colors.cyan end
  13.  if seg1[7] == 1 then fOut = fOut + colors.white end
  14.  if seg1[8] == 1 then fOut = fOut + colors.lime end
  15.  
  16.  if seg2[1] == 1 then fOut = fOut + colors.red end
  17.  if seg2[2] == 1 then fOut = fOut + colors.green end
  18.  if seg2[3] == 1 then fOut = fOut + colors.pink end
  19.  if seg2[4] == 1 then fOut = fOut + colors.gray end
  20.  if seg2[5] == 1 then fOut = fOut + colors.lightBlue end
  21.  if seg2[6] == 1 then fOut = fOut + colors.blue end
  22.  if seg2[7] == 1 then fOut = fOut + colors.black end
  23.  if seg2[8] == 1 then fOut = fOut + colors.lightGray end
  24.  
  25.  rs.setBundledOutput(sSide, fOut)
  26. end
  27.  
  28. function writeInt(sSide, val)
  29.  bytes = {0x30, 0x6D, 0x79, 0x72, 0x5B, 0x5F, 0x31, 0x7F, 0x73, 0x3F} -- Each element's index number corresponds to the number it writes.
  30.  local digitTens = 0
  31.  local digitOnes = 0
  32.  if val > 99 then return 1 end
  33.  if val < 0 then return 1 end
  34.  digitTens = math.floor(val / 10)
  35.  digitOnes = val - (digitTens * 10)
  36.  if digitTens == 0 then digitTens = 10 end
  37.  if digitOnes == 0 then digitOnes = 10 end
  38.  -- print(bit.tobits(bytes[digitTens]))
  39.  -- print(bit.tobits(bytes[digitOnes]))
  40.  
  41.  writeBundle(sSide, bit.tobits(bytes[digitTens]), bit.tobits(bytes[digitOnes]))
  42. end
  43.  
  44. hours = "right"
  45. minutes = "left"
  46.  
  47. while true do
  48.  os.startTimer(1)
  49.  local cTime = os.time()
  50.  cTime = textutils.formatTime(cTime, true)
  51.  _, _, cHours, cMinutes = string.find(cTime, "(%d+):(%d+)")
  52.  writeInt(hours, tonumber(cHours))
  53.  writeInt(minutes, tonumber(cMinutes))
  54.  os.pullEvent()
  55. end
Add Comment
Please, Sign In to add comment