Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- main.lua
- local cardDriveSide = "bottom" -- side where the card reader is connected
- local monitorSide = "right" -- side where the monitor is connected
- local doorSide = "left" -- side where the door is connected
- -- Wrap peripherals
- local cardDrive = peripheral.wrap(cardDriveSide)
- local monitor = peripheral.wrap(monitorSide)
- -- Function to display a message on the monitor
- local function displayMessage(line, message)
- monitor.setCursorPos(1, line)
- monitor.clearLine()
- monitor.write(message)
- end
- -- Function to display a detailed message about the access card status
- local function displayAccessCardMessage(status)
- monitor.clear()
- if status == "insert" then
- displayMessage(1, "Doggy OS Enterprise Security")
- displayMessage(2, "============================")
- displayMessage(4, "Welcome to Doggy OS Enterprise Security System.")
- displayMessage(6, "Please insert your access card to proceed.")
- elseif status == "valid" then
- displayMessage(1, "Access Granted")
- displayMessage(2, "============================")
- displayMessage(4, "Welcome, authorized user!")
- displayMessage(6, "Access has been granted.")
- sleep(3) -- Display message for 3 seconds
- elseif status == "invalid" then
- displayMessage(1, "Access Denied")
- displayMessage(2, "============================")
- displayMessage(4, "Invalid or unauthorized card.")
- displayMessage(6, "Access denied. Please contact")
- displayMessage(7, "security for assistance.")
- sleep(3) -- Display message for 3 seconds
- end
- end
- -- Function to check the inserted card and control the door
- function checkCard()
- displayAccessCardMessage("insert") -- Initial message to insert card
- while true do
- if cardDrive.isDiskPresent() then
- local diskID = cardDrive.getDiskID()
- if fs.exists("/disk/Cards/"..diskID..".ID") then
- displayAccessCardMessage("valid")
- redstone.setOutput(doorSide, true) -- Open door
- sleep(1) -- Ensure door is fully open before ejecting
- -- Eject the card
- cardDrive.ejectDisk()
- sleep(2) -- Keep door open for 2 seconds after ejecting
- redstone.setOutput(doorSide, false) -- Close door
- break -- Exit loop after valid card action
- else
- displayAccessCardMessage("invalid")
- break -- Exit loop after invalid card action
- end
- else
- -- No card inserted, continue checking
- sleep(1) -- Wait briefly before checking again
- end
- end
- end
- -- Main loop to continuously check for the card
- while true do
- checkCard()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement