Help with Loop

Joined
Mar 30, 2023
Messages
1
Reaction score
0
Ok so I am trying to get some code to run an rfid reader, display some information on an led matrix and then loop back to do it all again. I can't get it to loop though once it gets a rfid code it just repeats it infinitely. Any help would be appreciated. Here's my code:
#include <RGBmatrixPanel.h>
#include <gamma.h>
#include <SoftwareSerial.h>
#include <string>
#include <iostream>
#include <sstream>


#define RFIDEnablePin 5 // Pin that enables reading. Set as OUTPUT and LOW to read an RFID tag
#define RFIDSerialRate 2400 // Parallax RFID Reader Serial Port Speed
#define RxPin 16 // Pin to read data from RFID Reader
#define TxPin 25 // THIS PIN ISN'T USED!!!! this pin writes data and the Parallax is only a reader
#define CLK 14 // Sends clock signal from ESP32 to the RGB Matrix
#define OE 23 // Enables the transmitting of data to the Matrix
#define LAT 13 // "Latches" onto data transmission and clock speed
#define A 27 // Red data signal
#define B 32 // Green data signal
#define C 33 // Blue data signal
#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr

SoftwareSerial RFIDReader (RxPin, TxPin);
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);

String RFIDTAG = "";
String DisplayTAG = "";
const char def[] PROGMEM = "Slide A Fish";
const char def1[] PROGMEM = " To The Scale";
const char bass[] PROGMEM = "Fish: Largemouth Bass Caught: 1/24/92 At Lake Fork";
const char bass1[] PROGMEM = " Weight: 18.18 Pounds Angler: Barry St. Clair";
const char crap[] PROGMEM = "Fish: White Crappie Weight: 4.56 Pounds Caught: February 14th 1968 At Navarro Mills Lake Angler: G G Wooderson";
const char blue[] PROGMEM = "Fish: Bluegill Weight: 2.02 Pounds Caught: November 21st 1999 At Lampasas River Angler: Gibbs Milliken";
const char strp[] PROGMEM = "Fish: Striped Bass Weight: 53 Pounds Caught: May 27th 1999 At Brazos River Angler: Ron Venerable";
const char cat[] PROGMEM = "Fish: Blue Catfish Weight: 121.5 Pounds Caught: June 16th 2004 At Texoma Angler: Cody Mullenix";
const char str[] PROGMEM = "Adafruit 16x32 RGB LED Matrix";
int16_t textX = matrix.width(),
textMin = (int16_t)sizeof(def1) * -12,
hue = 0;



void setup() {
RFIDReader.begin(RFIDSerialRate);// SOUT Pin connected to Serial RX pin at 2400bps
pinMode(RFIDEnablePin, OUTPUT);
digitalWrite(RFIDEnablePin, LOW);
Serial.begin(115200);// Sets up Serial Library at 115200 bps
matrix.begin();
matrix.setTextWrap(false); // Allow text to run off right edge
matrix.setTextSize(1);

}

void loop() {
byte i;
{
// if ((RFIDTAG) = "0")
// {
ReadSerial(RFIDTAG);
// matrix.fillScreen(0); // Clears background of screen
// matrix.setTextColor(matrix.ColorHSV(hue, 0, 200, true)); // Sets color of text
// matrix.setCursor(textX, 0); // Sets cursor on the top row of matrix
// matrix.print(F2(def)); // prints message on the top row
// matrix.setCursor(textX, 8); // sets cursor on the bottom row of matrix
// matrix.print(F2(def1)); // prints message on the bottom row
// if((--textX) < textMin) textX = matrix.width(); // Scrolls text to the left and wraps
// delay(60);
// }
// if ((RFIDTAG) = "0101649C47")
// {
// digitalWrite(RFIDEnablePin, HIGH);
// Serial.println(RFIDTAG);
// matrix.fillScreen(0); // Clears background of screen
// matrix.setTextColor(matrix.ColorHSV(hue, 0, 200, true)); // Sets color of text
// matrix.setCursor(textX, 0); // Sets cursor on the top row of matrix
// matrix.print(F2(bass)); // prints message on the top row
// matrix.setCursor(textX, 8); // sets cursor on the bottom row of matrix
// matrix.print(F2(bass1)); // prints message on the bottom row
// if((--textX) < textMin) textX = matrix.width(); // Scrolls text to the left and wraps
// delay(60);
// Serial.end();
// Serial.flush();

// }
int RfidTag = RFIDTAG.toInt();
char a = "0101649C47";


switch (RfidTag)
{
case 0:
digitalWrite(RFIDEnablePin, LOW);
Serial.println(RFIDTAG);
matrix.fillScreen(0); // Clears background of screen
matrix.setTextColor(matrix.ColorHSV(hue, 0, 200, true)); // Sets color of text
matrix.setCursor(textX, 0); // Sets cursor on the top row of matrix
matrix.print(F2(def)); // prints message on the top row
matrix.setCursor(textX, 8); // sets cursor on the bottom row of matrix
matrix.print(F2(def1)); // prints message on the bottom row
if((--textX) < textMin) textX = matrix.width(); // Scrolls text to the left and wraps
delay(60);
RFIDTAG = "";
break;

case '0101649C47':
digitalWrite(RFIDEnablePin, LOW);
Serial.println(RFIDTAG);
matrix.fillScreen(0); // Clears background of screen
matrix.setTextColor(matrix.ColorHSV(hue, 0, 200, true)); // Sets color of text
matrix.setCursor(textX, 0); // Sets cursor on the top row of matrix
matrix.print(F2(bass)); // prints message on the top row
matrix.setCursor(textX, 8); // sets cursor on the bottom row of matrix
matrix.print(F2(bass1)); // prints message on the bottom row
if((--textX) < textMin) textX = matrix.width(); // Scrolls text to the left and wraps
delay(60);
RFIDTAG = "";
break;

default:
digitalWrite(RFIDEnablePin, LOW);
Serial.println(RFIDTAG);
matrix.fillScreen(0); // Clears background of screen
matrix.setTextColor(matrix.ColorHSV(hue, 0, 200, true)); // Sets color of text
matrix.setCursor(textX, 0); // Sets cursor on the top row of matrix
matrix.print(F2(def)); // prints message on the top row
matrix.setCursor(textX, 8); // sets cursor on the bottom row of matrix
matrix.print(F2(def1)); // prints message on the bottom row
if((--textX) < textMin) textX = matrix.width(); // Scrolls text to the left and wraps
delay(60);
RFIDTAG = "";
break;



}

}









matrix.swapBuffers(false); // Updates display
}
void ReadSerial(String& ReadTagString)
{
int bytesread = 0;
int val = 0;
char code[10];
String TagCode = "";

if (RFIDReader.available() > 0) { // If data available from reader
if ((val = RFIDReader.read()) == 10) { // Check for header
bytesread = 0;
while (bytesread < 10) { // Read 10 digit code
if (RFIDReader.available() > 0) {
val = RFIDReader.read();
if ((val == 10) || (val == 13)) { // If header or stop bytes before the 10 digit reading
break; // Stop reading
}
code[bytesread] = val; // Add the digit
bytesread++; // Ready to read next digit
}
}
if (bytesread == 10) { // If 10 digit read is complete

for (int x = 0; x < 10; x++) //Copy the Chars to a String
{
TagCode += code[x];
}
ReadTagString = TagCode; //Update the caller
while (RFIDReader.available() > 0) //Burn off any characters still in the buffer
{
RFIDReader.read();
}

}
bytesread = 0;
TagCode = "";
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top