Advertisement
DOGGYWOOF

Untitled

Jan 20th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. -- PIN Lock System
  2.  
  3. local pin = "1234"
  4. local doorSide = "left"
  5. local alarmSide = "back"
  6.  
  7. -- Function to check the entered PIN
  8. local function checkPIN(enteredPIN)
  9. return enteredPIN == pin
  10. end
  11.  
  12. -- Function to activate the alarm
  13. local function activateAlarm()
  14. print("Doggy OS Home Security: Intruder Alert!")
  15. redstone.setOutput(alarmSide, true)
  16. end
  17.  
  18. -- Function to deactivate the alarm
  19. local function deactivateAlarm()
  20. redstone.setOutput(alarmSide, false)
  21. print("Doggy OS Home Security: Alarm Deactivated")
  22. end
  23.  
  24. -- Function to check if the door is opened without computer activation
  25. local function doorOpenedWithoutActivation()
  26. local previousDoorStatus = redstone.getInput(doorSide)
  27.  
  28. while true do
  29. sleep(1) -- Adjust this delay based on how frequently you want to check for the door status
  30.  
  31. local currentDoorStatus = redstone.getInput(doorSide)
  32.  
  33. if currentDoorStatus and not previousDoorStatus then
  34. print("Door opened without computer activation. Activating alarm.")
  35. activateAlarm()
  36. sleep(5) -- Adjust this delay based on how long you want the alarm to sound
  37. deactivateAlarm()
  38. end
  39.  
  40. previousDoorStatus = currentDoorStatus
  41. end
  42. end
  43.  
  44. -- Main program
  45. while true do
  46. term.clear()
  47. term.setCursorPos(1,1)
  48. print("Enter PIN to unlock:")
  49. local enteredPIN = read("*")
  50.  
  51. if checkPIN(enteredPIN) then
  52. print("PIN correct. Unlocking door.")
  53. redstone.setOutput(doorSide, true)
  54. sleep(2) -- Adjust this delay based on your door mechanism
  55. redstone.setOutput(doorSide, false)
  56. deactivateAlarm()
  57. break
  58. else
  59. print("Incorrect PIN. Resetting.")
  60. sleep(2) -- Adjust this delay based on how long you want to wait before resetting
  61. end
  62. end
  63.  
  64. -- Start monitoring the door status
  65. parallel.waitForAny(doorOpenedWithoutActivation)
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement