Advertisement
Guest User

startup

a guest
Nov 19th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. receivingID = 2
  2. messageOpen = "///OPENING\\\\\\ "
  3. messageClose = "///CLOSING\\\\\\ "
  4. monitor = peripheral.find("monitor")
  5. rednet.open("front")
  6. state = false
  7. if fs.exists("saveState") then
  8.   h = fs.open("saveState","r")
  9.   value = h.readLine()
  10.   if value == "true" then
  11.     state = true
  12.   elseif value == "false" then
  13.     state= false
  14.   else
  15.     state = false
  16.   end
  17.   h.close()
  18. end
  19. function updateState()
  20. while true do
  21.   id, message = rednet.receive()
  22.   if id == receivingID then
  23.     if message == "open" then
  24.       state = true
  25.       redstone.setAnalogOutput("top",15)
  26.       sleep(5)
  27.       redstone.setAnalogOutput("top",0)
  28.     elseif message == "close" then
  29.       redstone.setAnalogOutput("top",15)
  30.       sleep(5)
  31.       redstone.setAnalogOutput("top",0)
  32.       state = false
  33.     end
  34.    
  35.     h = fs.open("saveState","w")
  36.     if state then  
  37.       h.writeLine("true")
  38.     else
  39.       h.writeLine("false")
  40.     end
  41.     h.close()
  42.   end
  43. end
  44. end
  45. function useState()
  46.   while true do
  47.   monitor.clear()
  48.   monitor.setCursorPos(1,1)
  49.   monitor.setBackgroundColor(colors.blue)
  50.   monitor.setTextScale(3)
  51.   if state then
  52.     redstone.setAnalogOutput("right",15)
  53.     redstone.setAnalogOutput("left",0)
  54.     monitor.write(messageOpen)
  55.   else
  56.     redstone.setAnalogOutput("right",0)
  57.     redstone.setAnalogOutput("left",15)
  58.     monitor.write(messageClose)
  59.   end
  60.   sleep(0.1)
  61. end
  62. end
  63. parallel.waitForAll(updateState,useState)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement