How do I print [to an LCD] a substring of seven characters from this character string? I could use a crowbar and concatenate seven bytes from this string into a new string, then print that, but I'm sure there is a more elegant way. Thanks.
void setup() {
int i;
// put your setup code here, to run once:
Serial.begin(9600);
char* room_text[] = {
"Office.",
"Den....",
"MBath...",
"Evap...",
"Roof...",
"FirePl.",
"HVAC...",
"Utility",
"Gym....",
"W Bed..",
"E Bed..",
"Lab...",
"Air Fan" } ;
for (i = 0; i < sizeof(room_text) / sizeof(room_text[0]); i++) {
Serial.println(room_text[i]);
}
}
void loop() {
// put your main code here, to run repeatedly:
}
PaulS, you hit it pretty close to the head. It is an array, but in this case it won't change. Can it be declared as a constant so that it doesn't take up RAM?
I didn't understand the array, so I was treating it as a long string and trying to cut a substring out of it.
The following code prints the 7 characters with no other manipulation required:
lcd.print(room_text[ (Unit_ID - 1) ]) ;
My other "discovery" is that I don't have to have constant length text phrases--the commas establish the array index.