I'm fuzzy on the details, but I think C++ handles initializers in a structure differently than "regular" C. Try this (untested):
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
struct dataStruct {
byte arrayToPrint[21];
byte cursorRow;
} txDataStream = {"THIS IS LINE ONE ..!", 0}; // Initialize after struct is defined
Serial.write(txDataStream.arrayToPrint, 20);
}
void loop() {
}
econjack:
I'm fuzzy on the details, but I think C++ handles initializers in a structure differently than "regular" C. Try this (untested):
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
struct dataStruct {
byte arrayToPrint[21];
byte cursorRow;
} txDataStream = {"THIS IS LINE ONE ..!", 0}; // Initialize after struct is defined
Serial.write(txDataStream.arrayToPrint, 20);
}
void loop() {
}
OK that works. But thats fine if i have only message to print .. in reality I need to be able to change the message that I pass to that byte array from inside the loop. When I tried to do that, the compiler does not emit any error but printing also does not happen. Tried both ways ...( one at a time of course !)
txDataStream.lcdMessage[21] = {" This is line No 1. "};
txDataStream.lcdMessage[21] = " This is line No 1. ";
I guess I don't see the problem. Just use strcpy() to change it:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
struct dataStruct {
byte arrayToPrint[21];
byte cursorRow;
} txDataStream = {"THIS IS LINE ONE ..!", 0}; // Initialize after struct is defined
Serial.write(txDataStream.arrayToPrint, strlen(txDataStream.arrayToPrint));
Serial.write('\n');
strcpy(txDataStream.arrayToPrint, "New message");
Serial.write(txDataStream.arrayToPrint, strlen(txDataStream.arrayToPrint));
}
void loop() {
}
Why are you using the array size outside of the structure definition? txDataStream is a struct object with two members and my code initializes it at the time of definition. If you want to change it after it has been defined and initialized, just use strcpy() on that member. You do not need to use the array size again outside of the structure definition.