I have the Mifare 130 RFID Module with the sparkfun shield and I found some infos and sketch by
Tom Igoe. It works to read my tags but now I would like to (e.g) display an image if the reader reads a defined ID.
I tried to make a function (at the end of the code) who would show the image as soon as the reader reads the tag but it gives me a
"unexpected token" error.
I think i closed all the brackets and i registered the function in the draw method but i honestly don't know if the code would work like this. Any idea?
Thank you!
/* SonMicro RFID Reader simple example Language: Processing
This sketch uses the SonMicroReader library to demonstrate how to read from Mifare RFID tags using the SonMicro reader.
created 6 March 2009 by Tom Igoe */
// import libraries: import processing.serial.*; import sonMicroReader.*; Serial myPort; // serial port instance SonMicroReader myReader; // sonMicroReader instance
int fontHeight = 24; // font height for the text onscreen String lastTag; // last tag read String tagID = "E2AB9C87"; // ADDED TAG ID PImage user; // USER IMAGE
void setup() { // set window size: size(400, 300); img = loadImage("m-icon.png"); // 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); myPort = new Serial (this, "/dev/tty.usbserial-A6008smX", 19200); // initialize the reader instance: myReader = new SonMicroReader(this, myPort); myReader.start(); myReader.reset(); // create a font with the second font available to the system: PFont myFont = createFont(PFont.list()[2], fontHeight); textFont(myFont); }
void draw() {
// draw to the screen: background(255); fill(0); textAlign(CENTER); readTagOne();
if (lastTag != null) { text(lastTag, width/2, height/2); } else { text("Hit any key to begin reading", width/2, height/2); } }
void keyReleased() { // for manually starting a seek: myReader.seekTag(); }
/* This function is called automatically whenever there's a valid packet of data from the reader */ void sonMicroEvent(SonMicroReader myReader) { // get all the relevant data from the last data packet: if (myReader.getTagString() != null) { lastTag = myReader.getTagString(); } // get the error code and last command: int errorCode = myReader.getErrorCode(); int lastCommand = myReader.getCommand();
// a little debugging info: println("error code: " + hex(errorCode, 2)); println("last command: " + hex(lastCommand, 2)); println("last tag type: " + myReader.getTagType()); println("last tag: " + lastTag); println("-----");
// if the last command was seekTag, then you're either waiting, // or ready to seek again: if (lastCommand == 0x82) { if (errorCode == 0x4C) { // you're waiting for a tag to appear } if (errorCode == 0) { // you got a successful read; // wat, then read again delay(300); myReader.seekTag(); } }
void readTagOne() { if (myReader.getTagString() == tagID) { user = loadImage("p-image.png"); } } }
There are already some questions arround cp5 and Lists but i was not able to solve "my" problem so far. Maybe someone out there knows a solution - would be great.
In my Program there are some images and lines plus some cp5 elements which woorks fine so far. But if i want to ad a cp5 ListItem, it won't work properly until i set the background to some int value in the draw function. e.g -> background(128); As soon as i set the background to some value, the List works fine but all the other elements disapear.
I have Processing 2.0b8 installed but i'm using the Sublime Text 2 IDE.
Here is the Code. I'ts more or less taken from the cp5 example. I deleted most of the comments in order to limit the list.
Thank you for the help and sorry for my english.
import controlP5.*;
ControlP5 cp5;
DropdownList d1;
int cnt = 0;
PImage appHeader;
PImage device;
void setup() {
size(1000, 830, P3D);
cp5 = new ControlP5(this);
// create a DropdownList
d1 = cp5.addDropdownList("myList-d1")
.setPosition(100, 100)
;
customize(d1); // customize the first list
// --------------- GUI OBEN ------------------
appHeader = loadImage("header.png");
image(appHeader, 0, 0); // position des headers
// --------------- DEVICE ------------------
device = loadImage("device.png");
image(device, 70, 140); // position of device
}
void customize(DropdownList ddl) {
// a convenience function to customize a DropdownList
ddl.setBackgroundColor(color(190));
ddl.setItemHeight(20);
ddl.setBarHeight(15);
ddl.captionLabel().set("HTC One X");
ddl.captionLabel().style().marginTop = 3;
ddl.captionLabel().style().marginLeft = 3;
ddl.valueLabel().style().marginTop = 3;
ddl.addItem("Samsung Galaxy S4", 0);
ddl.addItem("Google Nexus 4 ", 1);
//ddl.scroll(0);
ddl.setColorBackground(color(60));
ddl.setColorActive(color(255, 128));
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isGroup()) {
// check if the Event was triggered from a ControlGroup
println("event from group : "+theEvent.getGroup().getValue()+" from "+theEvent.getGroup());
}
else if (theEvent.isController()) {
println("event from controller : "+theEvent.getController().getValue()+" from "+theEvent.getController());