Hi, thanks.
This sounds like a possible explanation. I'm using arrays to detect the Rfid's, and like I said there seems to be a much faster overload when reading many different (only 6-7 id's) than when reading the same over and over again. But I'm not sure if the problem is in the detection iof the actual Rfid's or in the stringcompare I use later to give the accurate feedback. Anyway, here's my code..
// SETUP ============================================
// Set up speaker on a PWM pin (digital 9, 10 or 11)
int speakerOutPin = 9;
int smallVibePin = 3;
int bigVibePin = 10;
int soundBoxPin = 11;
// RFID READER ======================================
int inByte;
char tagArray[12]; // the array for the tags
int byteCount = 0; // counter for filling the tag array
//sun = 0103F8B0B7F
//flower = 0103F895523
//star = 0103F8AACF9
char sun[12] = {
'0', '1', '0', '3', 'F', '8', 'B', '0', 'B', '7', 'F', '\0'};
char flower[12] = {
'0', '1', '0', '3', 'F', '8', '9', '5', '5', '2', '3', '\0'};
char star[12] = {
'0', '1', '0', '3', 'F', '8', 'A', 'A', 'C', 'F', '9', '\0'};
char speaker[12] = {
'0', '1', '0', '4', 'C', '3', '8', '3', '7', '3', '3', '\0'};
char smallvibe[12] = {
'0', '1', '0', '4', 'C', '3', '9', 'F', 'F', 'A', 'A', '\0'};
char bigvibe[12] = {
'0', '1', '0', '4', 'C', '2', 'D', '3', 'E', '8', 'F', '\0'};
char soundbox[12] = {
'0', '1', '0', '4', 'C', '2', 'E', '2', '5', '8', '7', '\0'};
void setup() {
beginSerial(9600);
pinMode(speakerOutPin, OUTPUT);
pinMode(smallVibePin, OUTPUT);
pinMode(bigVibePin, OUTPUT);
pinMode(soundBoxPin, OUTPUT);
}
void loop() {
// PRINTING OUT ARPHID'S ======================================
if (serialAvailable()) {
inByte = serialRead();
//Serial.println(inByte);
switch (inByte) {
case 0x02: // the start byte
// reset the byte array counter:
byteCount = 0;
break;
case 0x03: // the end byte
// print out the tag array:
printTagArray();
break;
case '\r': // carriage return
case '\n': // linefeed
// we don't care about these, so ignore them
break;
default:
// increment the byte counter:
// there are eleven bytes in the tag ID, so
// if the count is less than 11, add the byte
// to the array:
if (byteCount < 11) {
tagArray[byteCount] = inByte;
byteCount++;
}
// add a final over-and-out byte:
else {
tagArray[byteCount] = '\0';
}
break;
}
}
}
// DETECT THE ARPHIDS ================================================================
void printTagArray() {
// print out the tag array byte by byte:
Serial.print("tagArray :");
Serial.print(tagArray);
// print a new line to separate the tags:
Serial.println();
if(strcmp(tagArray, sun) == 0) {
Serial.print(" Sun :");
Serial.print( sun);
slide_up();
}
if(strcmp(tagArray, flower) == 0) {
Serial.print(" Flower :");
Serial.print( flower);
}
if(strcmp(tagArray, star) == 0) {
Serial.print(" Star :");
Serial.print( star);
}
if(strcmp(tagArray, speaker) == 0) {
Serial.print(" Speaker :");
Serial.print( speaker);
speak1();
}
if(strcmp(tagArray, smallvibe) == 0) {
Serial.print(" Smallvibe :");
Serial.print( smallvibe);
vibe1();
}
if(strcmp(tagArray, bigvibe) == 0) {
Serial.print(" Bigvibe :");
Serial.print( bigvibe);
vibe2();
}
if(strcmp(tagArray, soundbox) == 0) {
Serial.print(" Soundbox :");
Serial.print( soundbox);
box1();
}
// print a new line to separate the tags:
Serial.println();
}
// PLAY A SLIDING TONE =======================================
void slide_up() {
int i = 3000;
while(i > 0) {
digitalWrite(speakerOutPin,HIGH);
delayMicroseconds(i%3000);
digitalWrite(speakerOutPin, LOW);
delayMicroseconds(i%3000);
i-=32;
}
int j = 4000;
while(j > 1000) {
digitalWrite(speakerOutPin,HIGH);
delayMicroseconds(j%3000);
digitalWrite(speakerOutPin, LOW);
delayMicroseconds(j%3000);
j-=32;
}
}
void slide_down() {
int i = 0;
while(i < 8000) {
digitalWrite(speakerOutPin,HIGH);
delayMicroseconds(i%8000);
digitalWrite(speakerOutPin, LOW);
delayMicroseconds(i%8000);
i+=16;
}
}
void speak1() {
int i = 3000;
while(i > 0) {
digitalWrite(speakerOutPin,HIGH);
delayMicroseconds(i%3000);
digitalWrite(speakerOutPin, LOW);
delayMicroseconds(i%3000);
i-=64;
}
delay (200);
int j = 5000;
while(j > 1000) {
digitalWrite(speakerOutPin,HIGH);
delayMicroseconds(j%4000);
digitalWrite(speakerOutPin, LOW);
delayMicroseconds(j%4000);
j-=64;
}
}
void vibe1() {
int i = 3000;
while(i > 0) {
digitalWrite(smallVibePin, HIGH);
delayMicroseconds(i%3000);
digitalWrite(smallVibePin, LOW);
delayMicroseconds(i%3000);
i-=64;
}
delay (200);
int j = 5000;
while(j > 1000) {
digitalWrite(smallVibePin, HIGH);
delayMicroseconds(j%4000);
digitalWrite(smallVibePin, LOW);
delayMicroseconds(j%4000);
j-=64;
}
digitalWrite(smallVibePin, LOW);
}
void vibe2() {
int i;
for(i = 0; i < 50000; i++) {
digitalWrite(bigVibePin, HIGH);
}
digitalWrite(bigVibePin, LOW);
}
void box1() {
int i;
for(i = 0; i < 30000; i++) {
digitalWrite(soundBoxPin, HIGH);
}
digitalWrite(soundBoxPin, LOW);
}
Do you know if there's a way to clear arrays?
S