SVty

Double Rednet Display

Aug 3rd, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.83 KB | None | 0 0
  1. --[[
  2. Program pro dvojity sedmisegmentovy display
  3. Verze 0.8 beta
  4. Vytvoril SVty
  5. http://pastebin.com/u/SVty
  6. http://www.youtube.com/user/SVtyPlay
  7. --]]
  8. --***********************
  9. num1 = { 63, 6, 91, 79, 102, 109, 125, 7, 127, 111, 0 }
  10. num2 = { 8064, 768, 11648, 10112, 13056, 13952, 16000, 896, 16256, 14208, 0 }
  11. sr = 0
  12. sl = 0
  13. s = "r"
  14. exit = false
  15. rednet.open("bottom")
  16.  
  17. --mazani
  18. rs.setBundledOutput("left",0)
  19. rs.setBundledOutput("right",0)
  20. rs.setBundledOutput("back",0)
  21. rs.setBundledOutput("top",0)
  22.  
  23. function start()
  24. id, y = rednet.receive()
  25. end
  26.  
  27. function spousteni()
  28.   if y > 99999 and s=="r" then
  29.     chyba()
  30.   elseif y>999 and s=="l" then
  31.     chyba()
  32.   else
  33.     x = y
  34.     vypocet()
  35.   end
  36. end
  37.  
  38. function vypocet()
  39.  
  40.   e = math.floor (x / 10000)
  41.   d = math.floor((x - (e * 10000)) / 1000)
  42.  
  43.   a = math.floor((x - ((e * 10000) + (d * 1000))) /100)
  44.   b = math.floor((x - ((e * 10000) + (d * 1000) + (a * 100))) /10)
  45.   c = math.floor (x - ((e * 10000) + (d * 1000) + (a * 100) + (b * 10)))
  46.  
  47. end
  48.  
  49. function printl()
  50.   if e == 0 then e = 10 end
  51.   if e == 10 and d == 0 then d = 10 end
  52.   if e == 10 and d == 10 and a == 0 then a = 10 end
  53.   if e == 10 and d == 10 and a == 10 and b == 0 then b = 10 end
  54.  
  55.   if e == 10 and not(d == 10) then
  56.     e = d
  57.     d = a
  58.     a = b
  59.     b = c
  60.     c = 10
  61.   elseif e == 10 and d == 10 and not(a == 10) then
  62.     e = a
  63.     d = b
  64.     a = c
  65.     b = 10
  66.     c = 10
  67.   elseif e == 10 and d == 10 and a == 10 and not(b == 10) then
  68.     e = b
  69.     d = c
  70.     a = 10
  71.     b = 10
  72.     c = 10
  73.   elseif e == 10 and d == 10 and a == 10 and b == 10 and not(c == 10) then
  74.     e = c
  75.     d = 10
  76.     a = 10
  77.     b = 10
  78.     c = 10
  79.   end
  80.  
  81.   print(e)
  82.   print(d)
  83.   print(a)
  84.   print(b)
  85.   print(c)
  86.   sl = (num1[e + 1])
  87.   rs.setBundledOutput("left",(num1[a + 1]) + (num2[d + 1]))
  88.   rs.setBundledOutput("top",sl + sr)
  89.   rs.setBundledOutput("back",(num1[c + 1]) + (num2[b + 1]))  
  90. end
  91.  
  92. function printr()
  93.   if a == 0 then a = 10 end
  94.   if a == 10 and b == 0 then b = 10 end
  95.  
  96.   print(a)
  97.   print(b)
  98.   print(c)
  99.   sr = (num2[c + 1])
  100.   rs.setBundledOutput("right",(num2[a + 1]) + (num1[b + 1]))
  101.   rs.setBundledOutput("top",sl + sr)
  102. end
  103.  
  104. function leftd()
  105.   rgh = rs.getBundledInput("right")
  106.   top = rs.getBundledInput("top")
  107.   lft = rs.getBundledInput("left")
  108.   bck = rs.getBundledInput("back")
  109.   for rep=1,3 do
  110.     rs.setBundledOutput("right",10240+48)
  111.     rs.setBundledOutput("top",14208+118)
  112.     rs.setBundledOutput("left",15360)
  113.     rs.setBundledOutput("back",0)
  114.     sleep(0.5)
  115.     rs.setBundledOutput("right",0)
  116.     rs.setBundledOutput("top",0)
  117.     rs.setBundledOutput("left",0)
  118.     rs.setBundledOutput("back",0)
  119.     sleep(0.5)  
  120.   end
  121.   rs.setBundledOutput("right",rgh)
  122.   rs.setBundledOutput("top",top)
  123.   rs.setBundledOutput("left",lft)
  124.   rs.setBundledOutput("back",bck)
  125. end
  126.  
  127.  
  128.  
  129.  
  130. function rightd()
  131.   rgh = rs.getBundledInput("right")
  132.   top = rs.getBundledInput("top")
  133.   lft = rs.getBundledInput("left")
  134.   bck = rs.getBundledInput("back")
  135.   for rep=1,3 do
  136.     rs.setBundledOutput("right",7168+121)
  137.     rs.setBundledOutput("top",14464+120)
  138.     rs.setBundledOutput("left",0)
  139.     rs.setBundledOutput("back",0)
  140.     sleep(0.5)
  141.     rs.setBundledOutput("right",0)
  142.     rs.setBundledOutput("top",0)
  143.     rs.setBundledOutput("left",0)
  144.     rs.setBundledOutput("back",0)
  145.     sleep(0.5)
  146.   end
  147.   rs.setBundledOutput("right",rgh)
  148.   rs.setBundledOutput("top",top)
  149.   rs.setBundledOutput("left",lft)
  150.   rs.setBundledOutput("back",bck)
  151. end
  152.  
  153. function chyba()
  154.  
  155.   rgh = rs.getBundledInput("right")
  156.   top = rs.getBundledInput("top")
  157.   lft = rs.getBundledInput("left")
  158.   bck = rs.getBundledInput("back")
  159.   for rep=1,3 do
  160.     rs.setBundledOutput("right",15488+80)
  161.     rs.setBundledOutput("top",10240+92)
  162.     rs.setBundledOutput("left",10240)
  163.     rs.setBundledOutput("back",0)
  164.     sleep(0.5)
  165.     rs.setBundledOutput("right",0)
  166.     rs.setBundledOutput("top",0)
  167.     rs.setBundledOutput("left",0)
  168.     rs.setBundledOutput("back",0)
  169.     sleep(0.5)
  170.   end
  171.   rs.setBundledOutput("right",rgh)
  172.   rs.setBundledOutput("top",top)
  173.   rs.setBundledOutput("left",lft)
  174.   rs.setBundledOutput("back",bck)
  175.  
  176. end
  177. --********************************
  178.  
  179. function help()
  180.   print("----------")
  181.   print(" Napoveda ")
  182.   print("----------")
  183.   print("")
  184.   print("/left - pro zapis na levou stranu displaye")
  185.   print("/right - pro zapis na pravou stranu displaye")
  186.   print("/day - pro zobraneni Den na pravou stranu displaye")
  187.   print("/help - zobrazeni napovedy")
  188.   print("/exit - konec programu")
  189. end
  190.  
  191. function day()
  192.   sr = (10752)
  193.   rs.setBundledOutput("right",12032+121)
  194.   rs.setBundledOutput("top",sl + sr)
  195.   print("Na prave strane displaye je zobrazeno Den:")
  196.   s = "r"
  197. end
  198.  
  199. function ep()
  200.  
  201. end
  202.  
  203.  
  204. function exit1()
  205.   for rep=1,3 do
  206.     rs.setBundledOutput("right",121)
  207.     rs.setBundledOutput("top",6912+48)
  208.     rs.setBundledOutput("left",15360)
  209.     rs.setBundledOutput("back",0)
  210.     sleep(0.5)
  211.     rs.setBundledOutput("right",0)
  212.     rs.setBundledOutput("top",0)
  213.     rs.setBundledOutput("left",0)
  214.     rs.setBundledOutput("back",0)
  215.     sleep(0.5)
  216.   end
  217.   rs.setBundledOutput("right",8064+62)
  218.   rs.setBundledOutput("top",15360+115)
  219.   rs.setBundledOutput("left",7936+120)
  220.   rs.setBundledOutput("back",0)  
  221. end
  222.  
  223. --********************************
  224. --program
  225. while exit == false do
  226.   start()
  227.   if not tonumber(y) then
  228.  
  229.     if y == "/right" then
  230.       s = "r"
  231.       leftd()
  232.     elseif y == "/left" then
  233.       s = "l"
  234.       rightd()
  235.     elseif y == "/day" then
  236.       day()
  237.     elseif y == "/help" then
  238.       help()
  239.     elseif y == "/exit" then
  240.       exit = true
  241.       exit1()
  242.     else
  243.       print(y.." je neplatny prikaz!")
  244.     end
  245.  
  246.   else
  247.     print(y)
  248.     y = tonumber(y)
  249.     spousteni()
  250.     if s == "r" then
  251.       printl()
  252.     else
  253.       printr()
  254.     end
  255.   end
  256.   sleep(1)
  257.   print(s)
  258. end
Advertisement
Add Comment
Please, Sign In to add comment