Skip to content

Instantly share code, notes, and snippets.

@Seich
Created May 28, 2012 20:54
Show Gist options
  • Save Seich/2821185 to your computer and use it in GitHub Desktop.
Save Seich/2821185 to your computer and use it in GitHub Desktop.
require "serialport"
@rfid_reader = SerialPort.new 4 # Open COM 5
@arduino = SerialPort.new 2 # Open COM 3
@valid_ids = ['4500B8D690BB']
def readRFID
rfid = @rfid_reader.gets
rfid.strip!
rfid.slice(0) if rfid.size == 13
rfid.slice(0..1) if rfid.size == 14
return rfid
end
puts "Waiting for input..."
loop do
rfid = readRFID # Get the RFID of the current card
if !rfid.empty?
if @valid_ids.include? rfid # is the ID valid?
puts "RFID: " + rfid
# Send the arduino a signal so it opens the lock.
@arduino.write "1"
else
puts "Invalid RFID: " + rfid
@arduino.write ""
end
end
@arduino.write ""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment