Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Aether

A little question related to the motion sensor.

Question

This is the program.

local component = require("component")
local sensor = component.motion_sensor
local sides = require("sides")
local io = require("io")
local term = require("term")
local event = require("event")
sensor.setSensitivity(0.2)
local range=1
------ Functions -----

function close()
    local rs1 = component.proxy("bebe4c8f-a23e-4e7a-baec-be0124a0b598")
    rs1.setOutput(sides.right,0)
    os.sleep(1)  
  for address in component.list("redstone",true) do
        local rs = component.proxy(address)
        rs.setOutput(sides.top,15)
  end
end

function open()
  for address in component.list("redstone",true) do
    local rs = component.proxy(address)   
    rs.setOutput(sides.top,0)
   end
   os.sleep(1)  
   local rs1 = component.proxy("bebe4c8f-a23e-4e7a-baec-be0124a0b598")
   rs1.setOutput(sides.right,15)
 end

function openMan()
  open()
  print("Closing it in 8 seconds")
  os.sleep(8)
  close()
end

function detect()
    print("Detecting...")
  while true do
    local _,_,x,y,z,name=event.pull("motion")  
    if math.abs(x)<=tonumber(range) and math.abs(y)<=tonumber(range) and math.abs(z)<=tonumber(range) then  
      if name == "AetherEus" then
         open()
         print("Detected:",name)
         print("Closing the staircase in 10 seconds")
         os.sleep(10)
         close()
         return false            
      end
    end
  end
end
close()
---- end ---- 
---- Menu ----
if component.isAvailable("motion_sensor") then
  repeat
    print("Aileen:Program Started. What do I do now?")
    print("1.Open the staircase.\n2.Star detection mode.\n3.Close the staircase.\n4.Close the program.")

    local inst=io.read("*n")
  
    if inst==1 then term.clear() print("Aileen: Opening.") openMan() os.sleep(1) detect() end
    if inst==2 then term.clear() print("Aileen: Starting detection mode.") detect() end
    if inst==4 then term.clear() print("Aileen: Closing the program.") term.clear() end
    if inst==3 then term.clear() print("Aileen: Closing the staircase.") close() end
    until inst == 4
  else
  print("Plug in the motion sensor!!!")
end
return 0

It's simple it activates or deactivates a redstone machanism that opens up a path to a staircase. The two things I want to fix or add is  1. A  way to manually cancel the detecting process. 2.Fix that the motion sensor takes to long to detect or I need to jump a lo to make it work. 

6oUeqbV.jpg

6y5oaNy.jpgkdz7qFc.jpg

 

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.