Advertisement
JMZ10

RedHouse SmartHouse

May 24th, 2014
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. --Initalization
  2. term.setTextColor(colors.lime)
  3. term.setBackgroundColor(colors.gray)
  4. shell.run('clear')
  5. term.clear()
  6. print("RedHouse V0.1 by JMZ10")
  7. print(" ")
  8. sleep(1)
  9. repeat
  10.     io.write("Desktop or PDA [D/P]?  ")
  11.     io.flush()
  12.     answer=io.read()
  13. until answer == "d" or answer == "p"
  14. if answer == "p" then
  15.     rednet.open("back")
  16. else
  17.     rednet.open("top")
  18. end
  19.  
  20. --Server Mode Display Text
  21. function serverText()
  22.     term.setTextColor(colors.blue)
  23.     term.setBackgroundColor(colors.white)
  24.     shell.run('clear')
  25.     term.clear()
  26.     print("RedHouse V0.1 by JMZ10")
  27. end
  28.  
  29. --Rednet Reciever Code
  30. function DoorServer()
  31.     serverText()
  32.     print("Running as a Door Server")
  33.     print("To Turn off Server Press & Hold Ctrl + R ")
  34.     print("- - -")
  35.     while true do
  36.         message = rednet.recieve()
  37.         if message == "DR1" then
  38.             redstone.setOutput("back", true)
  39.             sleep(2)
  40.             redstone.setOutput("back", false)
  41.         end
  42.     end
  43. end
  44. redIO = 0
  45. function LightServer()
  46.     serverText()
  47.     print("Running as a Light Server")
  48.     print("To Turn off Server Press & Hold Ctrl + R ")
  49.     print("- - -")
  50.     while true do
  51.         local senderId, message, distance = rednet.receive()
  52.         if message == "LCR1" then
  53.             if redIO == 0 then
  54.                 redIO = 1
  55.                 redstone.setOutput("back", true)
  56.                 rednet.broadcast("MSGRS")
  57.             else
  58.                 redIO = 0
  59.                 redstone.setOutput("back", false)
  60.                 rednet.broadcast("MSGRS")
  61.             end
  62.         end
  63.     end
  64. end
  65.  
  66. --Rednet Transmitter Code
  67. function DoorAccess()
  68.     print("DT1")
  69. end
  70.  
  71. function LightControl()
  72.     rednet.broadcast("LCR1")
  73.     sleep(1)
  74.     local senderId, message, distance = rednet.receive(2)
  75.     if message == "MGSRS" then
  76.         print("Lights Toggled Successfully")
  77.     else
  78.         print("Lights Failed to Toggle!")
  79.     end
  80. end
  81.  
  82.  
  83. --Determine Mode
  84. local answer
  85. repeat
  86.     io.write("Server or Client [S/C]?  ")
  87.     io.flush()
  88.     answer=io.read()
  89. until answer == "s" or answer == "c"
  90.  
  91. shell.run('clear')
  92. print("RedHouse V0.1 by JMZ10")
  93. print(" ")
  94.  
  95. --When Server Mode
  96. if answer == "s" then
  97.     LightServer()
  98.  --   repeat
  99.  --       io.write("Lighting or Door[L/D]?")
  100.   --      io.flush()
  101.  --      answer=io.read()
  102.  --   until answer == "l" or answer == "d"
  103.  --       if answer == "l" then
  104.  --           LightServer()
  105.  --       elseif answer == "d" then
  106. --            DoorServer()
  107. --        end
  108.  
  109. -- When Client Mode
  110. else
  111.     LightControl()
  112.     --repeat
  113.         --io.write("Lighting or Door[L/D]:  |")
  114.      --   io.flush()
  115.  --       answer=io.read()
  116.  --  until answer == "l" or answer == "d"
  117.  --       if answer == "l" then
  118.  --           LightControl()
  119.  --       elseif answer == "d" then
  120.  --           DoorAccess()
  121.  --       end
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement