Im making a code for my metrosystem.
When you buy a ticket with a destination the cart should bring you there while carrying the RFID chip with you.
When you arrive near a station then the RFID reader should throw the switch so you arrive at the correct station.
I wrote down some code and it reacts on all rfid cards
this piece of code should only throw the switch if he sees a RFID card named with "central" and it should ignore all the other ones.
But it doesnt
reader = peripheral.wrap("left")
detected = false
central = false
while true do
if detected then
if central then
rs.setOutput("bottom",true)
end
sleep(3)
rs.setOutput("bottom",false)
end
term.clear()
term.setCursorPos(1,1)
reader.scan() -- scans for 1 second
detected = false
while true do
event, message = os.pullEvent()
if event == "rfid_detected"then
detected = true
print("An RFID Card was detected")
print("Card Data: "..message)
if message == "central" then
central = true
end
elseif event == "rfid_scan_done" then
break
end
end
end