Hardware Reference
In-Depth Information
Finally, the Button class defines
the properties and behaviors of the
buttons themselves.
8
}
class Button {
int x, y, w, h; // positions of the buttons
color basecolor, highlightcolor; // color and highlight color
color currentcolor; // current color of the button
String name;
This sketch doesn't include all the
functionality of the SM130. For
example, it only writes to block 4 of a
Mifare tag's memory, and it only uses
the default authentication scheme.
However, it does give you the ability to
read and write from tags, as well as the
structure to understand how to use the
SM130's functions.
// Constructor: sets all the initial values for
// each instance of the Button class
Button(int thisX, int thisY, int thisW, int thisH,
color thisColor, color thisHighlight, String thisName) {
x = thisX;
y = thisY;
h = thisH;
w = thisW;
basecolor = thisColor;
highlightcolor = thisHighlight;
currentcolor = basecolor;
name = thisName;
}
// if the mouse is over the button, change the button's color:
void update() {
if (containsMouse()) {
currentcolor = highlightcolor;
}
else {
currentcolor = basecolor;
}
}
// draw the button and its text:
void display() {
fill(currentcolor);
rect(x, y, w, h);
//put the name in the middle of the button:
fill(0);
textAlign(CENTER, CENTER);
text(name, x+w/2, y+h/2);
}
// check to see if the mouse position is inside
// the bounds of the rectangle:
boolean containsMouse() {
if (mouseX >= x && mouseX <= x+w &&
mouseY >= y && mouseY <= y+h) {
return true;
}
else {
return false;
}
}
}
 
Search WWH ::




Custom Search