Advertisement
scriding

7 segment display Clock

Jan 5th, 2021 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. --WIRING DIAGRAM (use rednet cables and color them accordingly)
  2. --         **Looking from back of display**
  3. --
  4. --         {Lime}                   {Brown}
  5. --   {White}    {Yellow}     {DkGray}     {DkBlue}
  6. --        {Salmon}                 {DkGreen}
  7. --   {Orange}   {LtBlue}     {LtGray}     {Purple}
  8. --         {Pink}                   {Cyan}
  9. --  
  10.  
  11.  
  12. os.loadAPI("json")   --load api for reading JSON
  13.  
  14.  
  15. uni = {              --array of units
  16. 63,     --0
  17. 3,      --1
  18. 109,    --2
  19. 103,    --3
  20. 83,     --4
  21. 118,    --5
  22. 126,    --6
  23. 35,     --7
  24. 127,    --8
  25. 115,    --9
  26. }
  27.  
  28. dec = {              --array of decimals
  29. 8064,   --0
  30. 384,    --1
  31. 13952,  --2
  32. 13184,  --3
  33. 10624,  --4
  34. 15104,  --5
  35. 16128,  --6
  36. 4480,   --7
  37. 16256,  --8
  38. 14720,  --9
  39. }
  40.  
  41. prs = {             --array of sums
  42.  
  43. }
  44.  
  45. k=0
  46. for j = 1, 10 do    --populate prs array
  47.  for i = 1, 10 do
  48.  
  49.   prs[k] = uni[i]+dec[j]
  50.   k=k+1
  51.  end
  52. end
  53.  
  54. --lightOn = 1        --starting value of blinking colon
  55.  
  56. while true do
  57.  
  58.  http.request("http://worldtimeapi.org/api/timezone/America/New_York")   --aquire time (JSON)
  59.                                                                          --********Change the URL to your own time zone
  60.  
  61.  while true do
  62.    evt, url, msg = os.pullEvent()    --if website returns a result then
  63.     if evt == "http_success" then
  64.    
  65.     str = msg.readAll()              --read data from website
  66.     obj = json.decode(str)           --decode JSON
  67.     value = obj.datetime             --store time value string
  68.    
  69.     local time = value              
  70.     local hdot = string.sub (time, 12, 13) --pull hours from string
  71.     local mdot = string.sub (time, 15, 16) --pull minutes from string
  72.     h = tonumber(hdot)                     --convert to integer
  73.     m = tonumber(mdot)                     --''
  74.    
  75.       if h >= 13 then           --*****If you want 24 hour format,
  76.          h = h-12               -- comment *****
  77.       end                       -- out    ******
  78.  
  79.       if h == 0 then            -- these  ******
  80.          h = 12                 -- 6      ******
  81.       end                       -- lines. ******
  82.  
  83.     break
  84.    
  85.      elseif evt == "http_failure" then     --if no signal print no connection
  86.  
  87.      print("No connection")
  88.      break
  89.    
  90.      end
  91.    end
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  if h ~= nil then                           --if hour value /= nil, output value
  99.    rs.setBundledOutput("left", prs[h])
  100.  end
  101.  
  102.  if m ~= nil then                           --if minute value /= nil, output value
  103.    rs.setBundledOutput("right", prs[m])
  104.  end
  105.  
  106. -- rs.setBundledOutput("top", lightOn)     --set colon on
  107.  
  108. -- if lightOn == 1 then
  109. --    lightOn = 0
  110. -- else
  111. --    lightOn = 1
  112. -- end
  113.  
  114.  sleep(10)
  115.  
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement