Advertisement
DOGGYWOOF

Data Card System

Jun 16th, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. -- main.lua
  2. local cardDriveSide = "bottom" -- side where the card reader is connected
  3. local monitorSide = "right" -- side where the monitor is connected
  4. local doorSide = "left" -- side where the door is connected
  5.  
  6. -- Wrap peripherals
  7. local cardDrive = peripheral.wrap(cardDriveSide)
  8. local monitor = peripheral.wrap(monitorSide)
  9.  
  10. -- Function to display a message on the monitor
  11. local function displayMessage(line, message)
  12. monitor.setCursorPos(1, line)
  13. monitor.clearLine()
  14. monitor.write(message)
  15. end
  16.  
  17. -- Function to display a detailed message about the access card status
  18. local function displayAccessCardMessage(status)
  19. monitor.clear()
  20. if status == "insert" then
  21. displayMessage(1, "Doggy OS Enterprise Security")
  22. displayMessage(2, "============================")
  23. displayMessage(4, "Welcome to Doggy OS Enterprise Security System.")
  24. displayMessage(6, "Please insert your access card to proceed.")
  25. elseif status == "valid" then
  26. displayMessage(1, "Access Granted")
  27. displayMessage(2, "============================")
  28. displayMessage(4, "Welcome, authorized user!")
  29. displayMessage(6, "Access has been granted.")
  30. sleep(3) -- Display message for 3 seconds
  31. elseif status == "invalid" then
  32. displayMessage(1, "Access Denied")
  33. displayMessage(2, "============================")
  34. displayMessage(4, "Invalid or unauthorized card.")
  35. displayMessage(6, "Access denied. Please contact")
  36. displayMessage(7, "security for assistance.")
  37. sleep(3) -- Display message for 3 seconds
  38. end
  39. end
  40.  
  41. -- Function to check the inserted card and control the door
  42. function checkCard()
  43. displayAccessCardMessage("insert") -- Initial message to insert card
  44.  
  45. while true do
  46. if cardDrive.isDiskPresent() then
  47. local diskID = cardDrive.getDiskID()
  48.  
  49. if fs.exists("/disk/Cards/"..diskID..".ID") then
  50. displayAccessCardMessage("valid")
  51. redstone.setOutput(doorSide, true) -- Open door
  52. sleep(1) -- Ensure door is fully open before ejecting
  53.  
  54. -- Eject the card
  55. cardDrive.ejectDisk()
  56. sleep(2) -- Keep door open for 2 seconds after ejecting
  57. redstone.setOutput(doorSide, false) -- Close door
  58.  
  59. break -- Exit loop after valid card action
  60. else
  61. displayAccessCardMessage("invalid")
  62. break -- Exit loop after invalid card action
  63. end
  64. else
  65. -- No card inserted, continue checking
  66. sleep(1) -- Wait briefly before checking again
  67. end
  68. end
  69. end
  70.  
  71. -- Main loop to continuously check for the card
  72. while true do
  73. checkCard()
  74. end
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement