Hello, I am a new user and made a bit of a mess of my first thread, so I’ll try not to be an idiot here.
Right, I’ve been using the code from the contact free jukebox, but adapting it to a LCD screen.
I’m just trying to get messages to appear when the correct RFID tag is presented to the reader. (it’s a innovation-20 if that is of any relevance, pretty sure it isn’t though)
I’ve run into the limitation of the file names not being able to be more than 8 characters, and was wondering if there is an easy way around it in this context, of if I’m limited by the approach I’ve taken to the task.
the code as it is is fully working, just wondering about the 8 char limit.
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// rfid settings
SoftwareSerial RFIDSerial(8, 6);
int RFIDResetPin = 7;
char RFIDtag[14];
int RFIDindex = 0;
boolean RFIDreading = false;
// define tag id and tracks
#define NUMTAGS 5
char audiotags[NUMTAGS][14] = {"30008C4234CA",
"310022F6D93C",
"310023030F1E",
"31002304392F",
"310023030B1A"};
// make sure soundfile names are not longer then 8 chars
char audiofiles[NUMTAGS][14] = {"hello ",
"this ",
"is ",
"a ",
"test "};
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("System Ready");
// pin13
pinMode(13, OUTPUT);
// rfid setup
pinMode(RFIDResetPin, OUTPUT);
digitalWrite(RFIDResetPin, HIGH);
RFIDSerial.begin(9600);
}
void loop() {
RFIDindex = 0;
// rfid data?
while(RFIDSerial.available()) {
int readByte = RFIDSerial.read();
if(readByte == 2) RFIDreading = true;
if(readByte == 3) RFIDreading = false;
if(RFIDreading && readByte != 2 && readByte != 10 && readByte != 13){
RFIDtag[RFIDindex] = readByte;
RFIDindex++;
}
}
// check tag and play track if tag id found
checkTag(RFIDtag);
// prepare for next read
clearTag(RFIDtag);
resetReader();
}
void resetReader() {
digitalWrite(RFIDResetPin, LOW);
digitalWrite(RFIDResetPin, HIGH);
delay(150);
}
void clearTag(char one[]) {
for(int i = 0; i < strlen(one); i++){
one[i] = 0;
}
}
void checkTag(char tag[]) {
if(strlen(tag) == 0) return;
boolean matching = true;
// compare tag id
for(int a = 0; a < NUMTAGS; a++) {
matching = true;
for(int c = 0; c < 12; c++) {
if(tag[c] != audiotags[a][c]) {
matching = false;
break;
}
}
// in case of a match
if(matching) {
lcd.setCursor(0, 1);
lcd.print(audiofiles[a]);
break;
}
}
}
Moderator edit: Code tags