Hey guys, I'm working on a fairly simple sketch that reads some data addresses (#3-33) on an RFID card, printing the results to the monitor. I had another variant of this sketch working before, but I am trying to make it a little more elegant and have run into a problem. Whenever i try to compile the sketch, I receive the error message:
FINAL_read_whole_card_with_checking:3: error: 'whichSpace' was not declared in this scope
FINAL_read_whole_card_with_checking:31: error: redefinition of 'int readCard'
FINAL_read_whole_card_with_checking:3: error: 'int readCard' previously defined here
I have read and re-read my code, but I can't figure out what the IDE isn't liking. My code is below (sorry that it isn't formatted nicely, but that's another problem I'm having: clicking "copy for forum" returns "Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 40")
Here's my code:
#include <NewSoftSerial.h>
#define RFID_READ 0x01
#define txPin 6
#define rxPin 8
int firstByte;
int secondByte;
int thirdByte;
int fourthByte;
int whichSpace;
NewSoftSerial mySerial(rxPin, txPin);
void setup()
{
Serial.begin(9600);
Serial.println("Read RFID addresses #3-33:");
mySerial.begin(9600);
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);
}
void suppressAll()
{
if(mySerial.available() > 0)
{
mySerial.read();
suppressAll();
}
}
int readCard(whichSpace)
{
mySerial.print("!RW");
mySerial.print(RFID_READ, BYTE);
mySerial.print(whichSpace, BYTE);
if(mySerial.available() > 0)
{
val = mySerial.read();
if (val != 1)
{
suppressAll();
read(whichSpace);
}
first = mySerial.read();
second = mySerial.read();
third = mySerial.read();
fourth = mySerial.read();
}
}
void loop()
{
for (whichSpace = 3; whichSpace <= 33; whichSpace++)
{
readCard(whichSpace)
if(mySerial.available() > 0) {
val = mySerial.read();
Serial.print(whichSpace);
Serial.print(":");
Serial.print(firstByte, DEC);
Serial.print(" , ");
}
if(mySerial.available() > 0) {
val = mySerial.read();
Serial.print(secondByte, DEC);
Serial.print(" , ");
}
if(mySerial.available() > 0) {
val = mySerial.read();
Serial.print(thirdByte, DEC);
Serial.print(" , ");
}
if(mySerial.available() > 0) {
val = mySerial.read();
Serial.println(fourthByte, DEC);
}
delay(100);
}
}
}
Thanks for any/all help you can give!