Advertisement
Guest User

test

a guest
Feb 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. peri = fs.open("periph","r")
  2. a1 = peri.readLine()
  3. a2 = peri.readLine()
  4. peri.close()
  5. p1 = peripheral.wrap(a1)
  6. p2 = peripheral.wrap(a2)
  7. function color(e1,e2)
  8. e1.setBackgroundColor(e2)
  9. e1.clear()
  10. end
  11. function contr(r1,r2,p1,p2,astat)
  12. print(r1)
  13. print(r2)
  14. print(rs.getInput("left"))
  15. print(rs.getInput("right"))
  16. if r2 == rs.getInput("left") or r1 == rs.getInput("right") then
  17. rs.setOutput("left",not r1)
  18. rs.setOutput("right",not r2)
  19. if r1 then
  20. color(p1,colors.green)
  21. color(p2,colors.red)
  22. elseif r2 then
  23. color(p1,colors.red)
  24. color(p2,colors.green)
  25. else
  26. color(p1,colors.orange)
  27. color(p2,colors.orange)
  28. end
  29. end
  30. end
  31. mon = peripheral.wrap("back")
  32. for y = 1,12 do
  33. for x = 1,29 do
  34. if x > 20 or x < 10 then
  35. mon.setBackgroundColor(colors.green)
  36. else
  37. mon.setBackgroundColor(colors.red)
  38. end
  39. mon.setCursorPos(x,y)
  40. mon.write(" ")
  41. end
  42. end
  43. while true do
  44. e,d1,x,y = os.pullEvent()
  45. if e == "timer" and tn == d1 then
  46. astat = contr(false,false,p1,p2,astat)
  47. end
  48. if d1 == "monitor_1"  then
  49. astat = contr(true,false,p1,p2,astat)
  50. tn = os.startTimer(10)
  51. end
  52. if d1 == "monitor_0" then
  53. astat = contr(false,true,p1,p2,astat)
  54. tn = os.startTimer(10)
  55. end
  56. if d1 == "back" then
  57. if x < 10 then
  58. astat = contr(false,true,p1,p2,astat)
  59. tn = os.startTimer(10)
  60. elseif x > 19 then
  61. astat = contr(true,false,p1,p2,astat)
  62. tn = os.startTimer(10)
  63. else
  64. astat = contr(false,false,p1,p2,astat)
  65. end
  66. end
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement