Hey,
I have adapted two working codes into one, to use with interrupts. The thing trigger the interrupt is a button and that is working... It just seems to not be long enough? or doesn't read the RFID card? If you have any input or advise it would be great.
The RFID module is from seeeduino http://www.seeedstudio.com/wiki/125Khz_RFID_module_-_UART
#include <SoftwareSerial.h>
SoftwareSerial RFID = SoftwareSerial(4, 12);
int state = LOW;
unsigned long ID;
void setup()
{
Serial.begin(9600);
RFID.begin(9600);
attachInterrupt(0, readID, RISING);
//attachInterrupt(0, stateChange, CHANGE);
//pinMode(13,OUTPUT);
Serial.println("Hello");
}
void loop()
{
Serial.println("I am here");
delay(1000);
}
/*
void stateChange()
{
state = !state;
digitalWrite(13, state);
}
*/
void readID()
{
Serial.println("are we here?\n\n");
static byte data[4];
static byte temp[14];
byte len;
static int i = 0;
unsigned long currentId;
if(RFID.available()){
temp[i++] = RFID.read();
Serial.println("HERE?");
if(14 == i){
if( 0x02 == temp[0] && 0x03 == temp[13]){
data[0] = Transform(temp[3])*16 + Transform(temp[4]);
data[1] = Transform(temp[5])*16 + Transform(temp[6]);
data[2] = Transform(temp[7])*16 + Transform(temp[8]);
data[3] = Transform(temp[9])*16 + Transform(temp[10]);
currentId = (unsigned long)data[0]*16777216 + (unsigned long)data[1]*65536 + (unsigned long)data[2]*256 + (unsigned long)data[3];
Serial.print("CurrentID:");
Serial.println(currentId,DEC);
i = 0;
}
}
}
}
byte Transform(byte dat)
{
if(dat >= 0x30 && dat <= 0x39)
{
return (dat - 0x30);
}else if(dat >= 0x41 && dat <= 0x46)
{
return (dat - 55);
}
}