Hi
Thanks for getting back to me so fast. Firstly you'll probably have to excuse the way i describe all this stuff as i've not been doing it long.
My RFID reader is reading different cards which in turn flash up images in processing, I don't think I made that clear so sorry.
Here's my arduino code controlling the RGB LED with the RFID...
char val = 0; // Value of read from Serial
int i=0;
int redPin = 11;
int greenPin = 9;
int bluePin = 10;
//Serial myPort;
char tagID[13]; //the string for the tag ID
void setup() {
Serial.begin(9600); // connect to the serial port
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
}
void loop () {
while (Serial.available() > 0) {
// tagID = Serial.read();
char tagID1[13] = "1F001A7072";
char tagID2[13] = "1F001A8A83";
char tagID3[13] = "1F001ACC0F";
char tagID4[13] = "1F001A9C40";
char tagID5[13] = "1F001A830D";
char IDstring[13]; //create a string of 13 characters
//if data is available on the serial buffer
if (Serial.available() > 0 ) {
if ( (val = Serial.read()) == 02 ) { // look for Start Of Text marker (i.e ASCII "02")
Serial.print("[SOT] ");
// read until you get End Of Text
for ( i = 0; (val = Serial.read()) != 03 ; i++) {
Serial.print(val, DEC); // Display val in Hexadecimal
Serial.print(" ");
IDstring = val;
* }*
* IDstring[10] = 0x00;*
* Serial.println("[EOT]");*
* Serial.println();*
* Serial.print(" IDString = ");*
*} *
- if(IDstring[7]==tagID1[7] && IDstring[8]== tagID1[8] && IDstring[9]==tagID1[9]) // if it's this specific rfid card*
- { Serial.print("hello");*
- color(0, 0, 255);*
delay(1000);} //turn rgb to blue*
else if(IDstring[7]==tagID2[7] && IDstring[8]== tagID2[8] && IDstring[9]==tagID2[9]) // if it's this specific rfid card*
{ Serial.print("hello");*
color(255, 0, 0);*
delay(1000);} //turn rgb to red*
else if(IDstring[7]==tagID3[7] && IDstring[8]== tagID3[8] && IDstring[9]==tagID3[9]) // if it's this specific rfid card*
{ Serial.print("hello");*
color(255,180,0);*
delay(1000);} //turn rgb to yellow*
else if(IDstring[7]==tagID4[7] && IDstring[8]== tagID4[8] && IDstring[9]==tagID4[9]) // if it's this specific rfid card*
{ Serial.print("hello");*
color(0,255, 0);*
delay(1000);} //turn rgb to green*
else if(IDstring[7]==tagID5[7] && IDstring[8]== tagID5[8] && IDstring[9]==tagID5[9]) // if it's this specific rfid card*
{ Serial.print("hello");*
color(128,0,255);*
delay(1000);} //turn rgb to purple*
}*
}//end of loop
}
void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function
*{ *
analogWrite(redPin, 255-red); *
analogWrite(bluePin, 255-blue);*
analogWrite(greenPin, 255-green);*
}
----------------------------------------------------------------------------
Here's my processing sketch, that is displaying as image when the same RFID is scanned...
import processing.serial.*;
PImage visionblue;
PImage visiongreen;
PImage visionpurple;
PImage visionyellow;
PImage visionred;
Serial myPort;
String tagID = ""; //the string for the tag ID
String txt ="";
void setup() {
size (600,600); //create a display window*
println (Serial.list()); //prints list of serial onto console*
//write here the name of your serial port*
String portname = "COM3"; //MacOS X uses a different format such as "/dev/cu.USA28X21P1.1"*
//create new instance of a serial port with specified parameters.*
myPort = new Serial (this, portname, 9600);*
//create font for writing text*
PFont myFont = createFont (PFont.list () [10], 36);*
textFont (myFont);*
}//end setup
void draw(){
//clear Screen*
background(0);*
//delay screen refresh 2 second*
delay(2000);*
// read bytes from serial and print it out as a string of text*
while (myPort.available() > 0) {*
tagID = myPort.readString(); *
String tagID1 = "1F001A7072";*
String tagID2 = "1F001A8A83";*
String tagID3 = "1F001ACC0F";*
String tagID4 = "1F001A9C40";*
String tagID5 = "1F001A830D";*
if (tagID.equals(tagID1) == true) {*
background(2);*
visionblue = loadImage("20.jpg");*
image(visionblue, 0, 0); *
}*
//text("Vision Blue", 200, 100);//draw text on a specific position in display window*
//end while*
else if (tagID.equals(tagID2) == true) {
background(2);*
visiongreen = loadImage("21.jpg");*
image(visiongreen, 0, 0); *
} *
//text("Vision Green", 200, 100);//draw text on a specific position in display window*
//end while*
else if (tagID.equals(tagID3) == true) {
background(2);*
visionpurple = loadImage("22.jpg");*
image(visionpurple, 0, 0);*
}*
//text("Vision Purple", 200, 100);//draw text on a specific position in display window*
//end while*
else if (tagID.equals(tagID4) == true) {
background(2);*
visionyellow = loadImage("23.jpg");*
image(visionyellow, 0, 0);*
}*
//text("Vision Yellow", 200, 100);//draw text on a specific position in display window*
//end while*
else if (tagID.equals(tagID5) == true) {
* background(2);*
- visionred = loadImage("24.jpg");*
- image(visionred, 0, 0);*
- }*
- //text("Vision Red", 200, 100);//draw text on a specific position in display window*
- //end while*
}
}
------------------------------------------------------------------------
Also I know the code may be messy in places but independently of each other the 2 things work but I want it to do the led and flash up the pic at the same time from just 1 swipe of a card.
Thanks again, really really appreciate the help.