Hardware Reference
In-Depth Information
Continued from previous page.
ArrayList buttons = new ArrayList(); // list of buttons
// the buttons themselves:
String[] buttonNames = {
"antenna power", "select tag", "authenticate", "read block", "seek Tag",
"write block", "firmware version"
};
setup() initializes the serial con-
nection and makes an instance of the
SonMicroReader library. Then it makes
fonts for drawing text on the screen,
and calls the makeButtons() function
to make the onscreen buttons. The
button creation and control functions
come later, at the end of the sketch.
8
void setup() {
// set window size:
size(600, 400);
// list all the serial ports:
println(Serial.list());
// based on the list of serial ports printed from the
// previous command, change the 0 to your port's number:
String portnum = Serial.list()[0];
// initialize the serial port. default data rate for
// the SM130 reader is 19200:
myPort = new Serial(this, portnum, 19200);
// initialize the reader instance:
myReader = new SonMicroReader(this, myPort);
myReader.start();
// create a font with the second font available to the system:
PFont myFont = createFont(PFont.list()[2], fontHeight);
textFont(myFont);
// create the command buttons:
makeButtons();
}
draw() draws text and buttons to
the screen.
8
void draw() {
background(currentcolor);
// draw the command buttons:
drawButtons();
// draw the output fields:
textAlign(LEFT);
text("Command: " + hex(lastCommand, 2), 10, 30);
text("Packet length: " +lastPacketLength, 10, 50);
text("Antenna power: " + lastAntennaPower, 10, 70);
text("Tag type: " + lastTagType, 10, 90);
text("Tag string: " + lastTag, 10, 110);
text("Error code: " + hex(lastErrorCode, 2), 10, 130);
// print the hex values for all the bytes in the response:
ยป
 
Search WWH ::




Custom Search