Hardware Reference
In-Depth Information
The draw() method draws the tag
ID to the screen.
8
void draw() {
// clear the screen and choose
// pleasant colors inspired by a seascape:
background(#022E61);
fill(#D9EADD);
// print the string to the screen:
text(tagID, width/4, height/2);
}
The real work happens in the
serialEvent() method. It's called
whenever a byte of value 03 comes in
the serial port. It checks to see whether
the string starts with a byte of value 02
and ends with 03 . If so, it takes the first
10 bytes after the 02 as the tag ID.
8
void serialEvent(Serial myPort) {
// get the serial input buffer in a string:
String inputString = myPort.readString();
// filter out the tag ID from the string:
// first character of the input:
char firstChar = inputString.charAt(0);
// last character of the input:
char lastChar = inputString.charAt(inputString.length() -1);
// if the first char is STX (0x02) and the last char
// is ETX (0x03), then put the next 10 bytes
// into the tagID string:
if ((firstChar == 0x02) && (lastChar == 0x03)) {
tagID = inputString.substring(1, 11);
}
}
Run this sketch with the ID Innova-
tions reader attached, and wave some
tags in front of it. With each tag, you
should get a result like the screenshot
in Figure 9-9.
Figure 9-9
Output of the ID Innovations Reader sketch.
When you have this sketch working, use it to test the range
of your reader to see from how far away you can read a
tag. You'll notice that the tag has to leave the reader's
range before it can be read a second time. You may not be
able to tell that from the screen output, but you'll notice
that the LED goes off when the tag goes out of range,
and it turns on again when it comes back in range. Many
readers have a similar behavior. You should also see that
the reader can't read more than one tag at a time—this is
common among all the readers mentioned here.
X
 
Search WWH ::




Custom Search