Hi all,
I am not a programmer so forgive me my mistakes and errors...
I am trying to set a text to be scrolled constantly (until new one is set) on a 32x16 RGB LED matrix. I am using an Arduino Mega and an Arduino Ethernet shield to set the new text I would like to be scrolled on the LED matrix.
I can see that I am able to get the proper string of characters in the Serial monitor, but I have the feeling that the matrix loop has the string empty and does not want to update it with the new one. I am posting my code, please take a look... i will be happy on some feedback.
#include <Ethernet.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <RGBmatrixPanel.h>
#define CLK 53
#define LAT A5
#define OE 9
#define A A2
#define B A3
#define C A4
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //if need to change the MAC address (Very Rare)
//byte ip[] = { 192, 168, 0, 149 }; //Manual setup only
//byte gateway[] = { 192, 168, 1, 1 }; //Manual setup only
//byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only
EthernetServer server = EthernetServer(80); //port 80
char StringOne[32];
char StringTwo[32];
//char StringThree[32];
int StringPos = 0;
boolean reading = false;
int textX = matrix.width();
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac);
//Ethernet.begin(mac, ip, gateway, subnet); //for manual setup
server.begin();
Serial.println(Ethernet.localIP());
matrix.begin();
matrix.setTextWrap(false); // Allow text to run off right edge
matrix.setTextSize(2);
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
StringPos = 0;
memset( &StringOne, 0, 32 );
while (client.connected())
{
if (client.available())
{
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '?') reading = true;
if(reading)
{
StringOne[StringPos] = c;
StringPos ++;
}
if (c == '\n' && currentLineIsBlank) break;
if (c == '\n')
{
currentLineIsBlank = true;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}
}
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection:
String StringTwo = StringOne;
StringTwo.replace("%20", " ");
StringTwo.replace("?", "");
Serial.println(StringTwo);
}
else
{
rgbmatrix();
}
}
void rgbmatrix()
{
int textMin = sizeof(StringTwo) * -12;
// Set speed
matrix.fillRect(0, 0, 32, 16, matrix.Color333(0, 0, 0));
delay(10);
// Draw big scrolly text on top
matrix.setTextColor(matrix.Color333(255, 0, 0));
matrix.setCursor(textX, 1);
matrix.print(StringTwo);
// Move text left (w/wrap)
if((--textX) < textMin) textX = matrix.width();
// Update display
matrix.swapBuffers(false);
}
Thank you in advance!