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

Pressure-plate door

Question

something that can detect the redstone pulse from a pressureplate to send a pulse to a door, keeping it open until the pressureplate is ran over again.

 

run over plate -> door opens

run over plate again -> door closes

 

I managed to create something that will listen to the pressureplate and output RS but I have no idea how to make it toggle the door to stay open

my patience is running out and googlefu isn't returning anything useful

local component = require("component")
local sd = require("sides")
local rs = require("component.redstone")

if rs.getInput(sd.front) == 15 then
  print("Opening door")
  rs.setOutput(sd.right, 15)
else
  print("Closing door")
  rs.setOutput(sd.right, 0)
end
Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0
  • Solution
local component = require("component")
local sd = require("sides")
local rs = component.redstone
local event = require("event")

local oldSignal = false
local state = false
while true do
  local signal = rs.getInput(sd.front) > 0 --check if we have a redstone signal
  if signal ~= oldSignal then --make sure we don't trigger twice when the plate was stepped on once '
    oldSignal = signal
    if signal then 
      state = not state  --make it so we toggle if signal is true
      if state then
        print("Opening door")
        rs.setOutput(sd.right, 15)
      else
        print("Closing door")
        rs.setOutput(sd.right, 0)
      end
    end
  end
  event.pull("redstone_changed",rs.address,sd.front) --sleep until redstone input on our device's front changes '
end

You need to check if the redstone input is true when you toggle the output. 

 

EDIT: Added ' local event = require("event") '.

Link to post
Share on other sites
  • 0

You need a loop.

Otherwise the program will return before you step on the plate.

 

` require("component.redstone") ` is wrong.

"component" is the library with a variable called redstone.

You have to write ` require("component").redstone `

local component = require("component")
local sd = require("sides")
local rs = require("component").redstone

while true do

  if rs.getInput(sd.front) == 15 then
    print("Opening door")
    rs.setOutput(sd.right, 15)
  else
    print("Closing door")
    rs.setOutput(sd.right, 0)
  end

end

You can stop the programm with: Ctl + Alt + C (terminate)

Link to post
Share on other sites
  • 0

If I loop it will keep printing "opening door" / "closing door" and it will shut the door the moment I move from the pressureplate.

This was just something I managed to put together to test if the plate would talk to the computer

<snip>
Link to post
Share on other sites
  • 0

Other than a loop you'd also need to: keep track of the state, make sure one step equals one trigger, sleep
 

local component = require("component")
local sd = require("sides")
local rs = component.redstone

local oldSignal = false
local state = false
while true do
  local signal = rs.getInput(sd.front) > 0 --check if we have a redstone signal
  if signal ~= oldSignal then --make sure we don't trigger twice when the plate was stepped on once '
    oldSignal = signal
    state = not state --make it so we toggle
    if state then
      print("Opening door")
      rs.setOutput(sd.right, 15)
    else
      print("Closing door")
      rs.setOutput(sd.right, 0)
    end
  end
  event.pull("redstone_changed",rs.address,sd.front) --sleep until redstone input on our device's front changes '
end

Link to post
Share on other sites
  • 0

Improvements have been made, but it won't keep the door open. the moment I move away from the plate the output on sd.right is set to 0.

Also had to add a 'local event = require("event")' to make it run, but yeah

Link to post
Share on other sites
  • 0

I get double entries from the print("Open/Close door"), but it doesn't really matter. I might omit the messages when I work this into the door/lights opener. It's working as expected now!

Thanks for the help.

;)

Link to post
Share on other sites

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.