Continued Thanks go out to Mike who is slowly beating into my head what the ESP is doing while it is 'waiting' but this program works and it will help those who want to fire an interrupt via a serial input.
Mike really is busting his butt to help others.....
Those of us who work at a lower level will appreciate how to get hex bytes from the reader <grin>.
The reader is a Seeedstudio mini which outputs only 5 bytes - no header. I chose it for this learning task because it is 3.3v compliant. Picture below.
Code below:
memclear
print "Select operation mode" 'Prints option for selection; Read (normal) or Add which adds new tags
mode = "read" 'Default
dropdown mode, "add,read"
maxtags = 10 'Max user ID tags used
dim idtags(10) 'Tag ID array
dim h$(5) 'Hex array
dim d(5) 'Decimal array
'Read in added tags from flash
for x = 1 to maxtags
idtags(x) = read("idtag" & str(x))
print idtags(x) 'Prints on screen for verification
next x
'activate serial branch to catch rfid tag data
serialbranch [check.rfid] 'Works well, Thanks Mike!
wait
[check.rfid] 'Magic happens here
ID = ""
do 'Reads the data from the tag, this reader spits out 5 hex bytes
d(1) = str(serial.read.int())
d(2) = str(serial.read.int())
d(3) = str(serial.read.int())
d(4) = str(serial.read.int())
d(5) = str(serial.read.int())
Loop while Serial.available() 'loop through and put each byte in its own var
for x=1 to 5 'Converts dec to hex in bytes
h$(x)=hex(d(x))
next x
'for x=1 to 5 'This confirms by printing that it is working
' print "x=" & x & " " & "decimal=" & d(x) & " " & "Hex=" & (h$(x))
'next x
ID = hextoint(h$(1)&h$(2)&h$(3)&h$(4)) 'Equates ID in decimal
if mode == "add" then
for x = 1 to maxtags
'check if id is already in system
if idtags(x) == ID then
print "tag already in system"
return
end if
'Add tag to next empty slot
if idtags(x) == 0 then
idtags(x) = ID
'add tag to flash storage
write("idtag" & str(x), ID)
print "Tag Added"
return
end if
next x
else
'Look up tag and exicute branch for if tag is in system
for x = 1 to maxtags
'check if id is already in system
if idtags(x) == ID then
x = 10
Print "Valid tag detected"
'Activate pin to open door
io(po,d0,0)
'Give 10 seconds for user to enter
timer 10000, [lock.the.door]
return
end if
next x
print "Invalid tag detected"
end if
return
[lock.the.door]
timer 0
io(po,d0,1)
wait
- Albert Einstein