Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PIN Lock System
- local pin = "1234"
- local doorSide = "left"
- local alarmSide = "back"
- -- Function to check the entered PIN
- local function checkPIN(enteredPIN)
- return enteredPIN == pin
- end
- -- Function to activate the alarm
- local function activateAlarm()
- print("Doggy OS Home Security: Intruder Alert!")
- redstone.setOutput(alarmSide, true)
- end
- -- Function to deactivate the alarm
- local function deactivateAlarm()
- redstone.setOutput(alarmSide, false)
- print("Doggy OS Home Security: Alarm Deactivated")
- end
- -- Function to check if the door is opened without computer activation
- local function doorOpenedWithoutActivation()
- local previousDoorStatus = redstone.getInput(doorSide)
- while true do
- sleep(1) -- Adjust this delay based on how frequently you want to check for the door status
- local currentDoorStatus = redstone.getInput(doorSide)
- if currentDoorStatus and not previousDoorStatus then
- print("Door opened without computer activation. Activating alarm.")
- activateAlarm()
- sleep(5) -- Adjust this delay based on how long you want the alarm to sound
- deactivateAlarm()
- end
- previousDoorStatus = currentDoorStatus
- end
- end
- -- Main program
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("Enter PIN to unlock:")
- local enteredPIN = read("*")
- if checkPIN(enteredPIN) then
- print("PIN correct. Unlocking door.")
- redstone.setOutput(doorSide, true)
- sleep(2) -- Adjust this delay based on your door mechanism
- redstone.setOutput(doorSide, false)
- deactivateAlarm()
- break
- else
- print("Incorrect PIN. Resetting.")
- sleep(2) -- Adjust this delay based on how long you want to wait before resetting
- end
- end
- -- Start monitoring the door status
- parallel.waitForAny(doorOpenedWithoutActivation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement