View difference between Paste ID: 3N6sRY5a and Jnw5B9h1
SHOW: | | - or go back to the newest paste.
1
--If you want this to start at every boot of a computer run the following line of code in the startup
2
-- shell.run("RFID","door")
3
4
5
--The door stays open as long as you stay in the area of the reader 
6
--              !!! Make sure there is no creeper behind you !!!
7
8
-- Set up your own door system
9-
doorPass = "wsxedcrfvbgtnhzmjuzvrnzcif" --Max Length 82 chars
9+
doorPass = "qwermtqlvmjhtwerbvrthnwmrtlkjhwlrtbnthwhnwtrh"
10-
cardLabel = "Ident: Front Door"		--Max Length 20 chars
10+
cardLabel = "Bunker pass"
11-
--Make sure the following sides are equal to your build
11+
12-
readerSide = "left"
12+
readerSide = "back"
13
writerSide = "right"
14
redstoneSide = "bottom"
15
16-
--Variables (Don´t change)
16+
17
lastTimer = {}
18
19
if #tArgs < 1 then
20-
-- Check the arguments given
20+
21
	print("RFID write")
22
	print("RFID door")
23
	return
24
end
25
26
mode = tArgs[1]
27
shell.run("clear")
28
29
if mode == "write" then
30
	writer = peripheral.wrap(writerSide)
31
	print("Enter writing mode")
32
	print("Insert card in the writer")
33
	while not writer.isPresent() do --Waits until a card is in the writer
34
		sleep(0)
35
	end
36
	
37
	if writer.encode(doorPass, cardLabel) then --Start write to card
38
		print("Start writing Pass to card")
39
	else --Error handling
40
		if writer.isCoded() then
41
			print("Card is already coded\nInsert a blank card")
42
		elseif #cardLabel > 20 then
43
			print("Card Label is too long max. 20 char")
44
		elseif #doorPass > 82 then
45
			print("Data is too long max. 82 char")
46
		else
47
			print("Leave the card in the writer")
48
		end
49
		return
50
	end
51
	os.pullEvent("rfid_written") --Wait until the card is written
52
	print("RFID card is coded")
53
	print("Take the card out of the writer")
54
	
55
	while writer.isCoded() do --Ends the program when the card is taken out of the writer
56
		sleep(0)
57
	end
58
	shell.run("clear")
59
	
60
------------------------------------------------------
61
------------------------------------------------------
62
elseif mode == "door" then
63
	reader = peripheral.wrap(readerSide)
64
	print("Door Contol is running")
65
	while true do
66
		if not reader.isScanning() then
67
		  reader.scan() --Creats an "rfid_detected" when a card is in range
68-
		reader.scan() --Creats an "rfid_detected" when a card is in range
68+
69
		event, p1 = os.pullEvent()
70
		if event == "rfid_detected" then
71
			if p1 == doorPass then 
72
				print("Door opened")
73
				rs.setOutput(redstoneSide, true)
74
				lastTimer = os.startTimer(1)
75
			else
76
				print("Wrong card")
77
			end
78
		elseif event == "timer" and lastTimer == p1 then
79
			rs.setOutput(redstoneSide, false)
80
		end
81
	end
82
end