Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --rom/programs/http/pastebin get xdqCUyim keycard
- local SIDES = {"left", "right", "top", "bottom", "front", "back"}
- local OUTPUT_SIDE = "bottom"
- local COMBO_SUCCESS = {11,13}
- local COMBO_FAIL = {4,3}
- local passDoorOpen = false
- local PASS_DOOR = {}
- PASS_DOOR.CLOSE = colours.green
- PASS_DOOR.OPEN = colours.red
- PASS_DOOR.PULSES = 4
- local note
- local diskIDs = {}
- diskIDs[1] = true
- diskIDs[2] = true
- local function getNoteBlock()
- for i, v in ipairs(SIDES) do
- if peripheral.getType(v) == "note" then
- return peripheral.wrap(v)
- end
- end
- end
- --[[
- local function getDisks()
- local disks = {}
- for i, v in ipairs(SIDES) do
- if peripheral.getType(v) == "disk" then
- table.insert(disks, peripheral.wrap(v))
- end
- end
- return disks
- end
- ]]
- local function clearEvents()
- os.queueEvent("clear")
- while true do
- e = os.pullEvent()
- if e == "clear" then
- break
- end
- end
- end
- local function pulseRS(side, n, colour)
- if colour then
- for i = 1, n do
- rs.setBundledOutput(side, colours.combine(rs.getBundledOutput(side), colour))
- sleep(0.45)
- rs.setBundledOutput(side, colours.subtract(rs.getBundledOutput(side), colour))
- sleep(0.45)
- end
- else
- for i = 1, n do
- rs.setOutput(side, true)
- sleep(0.45)
- rs.setOutput(side, false)
- sleep(0.45)
- end
- end
- end
- local function playNote(notes)
- for i = 1, table.getn(notes) do
- note.playNote(0,notes[i])
- sleep(0.2)
- end
- end
- local function moveDoor(door, open)
- if open then
- pulseRS(OUTPUT_SIDE, door.PULSES, door.OPEN)
- else
- pulseRS(OUTPUT_SIDE, door.PULSES, door.CLOSE)
- end
- end
- local function checkDisk(side)
- if diskIDs[disk.getID(side)] then
- return true
- end
- return false
- end
- local function main()
- local eventTimer
- note = getNoteBlock()
- print("closing door")
- moveDoor(PASS_DOOR)
- sleep(1)
- clearEvents()
- while true do
- eventTimer = os.startTimer(6)
- e, side = os.pullEvent()
- if e == "disk" then
- print("disk in")
- if(checkDisk(side)) then
- print("openening door")
- sleep(0.2)
- playNote(COMBO_SUCCESS)
- disk.eject(side)
- moveDoor(PASS_DOOR, true)
- sleep(5)
- os.reboot()
- else
- playNote(COMBO_FAIL)
- disk.eject(side)
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement