Hello fellow Arduino forum members.
Here is my problem. I have 4 variables and I would like to serial print the information they contain. The 4 variables are:
int encoder_1 = 0; // Encoder 1
int encoder_2 = 0; // Encoder 2
int encoder_3 = 0; // Encoder 3
int encoder_4 = 0; // Encoder 4
I tried to use a for loop to streamline the code a little, but when I verify the code I receive an error:
Encoder_Test:202: error: 'encoder_j' was not declared in this scope
Here is the code I would like to use:
for(int j = 1; j <= 4; j++)
{
Serial.print("Encoder ");
Serial.print(j);
Serial.print(" [");
Serial.print(encoder_j);
Serial.print("] ");
}// End for j
Serial.print("\n"); // Carriage return to separate lines of serial data.
This is what I am currently using to make it work:
Serial.print("Encoder 1 [");
Serial.print(encoder_1);
Serial.print("] ");
Serial.print("Encoder 2 [");
Serial.print(encoder_2);
Serial.print("] ");
Serial.print("Encoder 3 [");
Serial.print(encoder_3);
Serial.print("] ");
Serial.print("Encoder 4 [");
Serial.print(encoder_4);
Serial.print("]\n");
Any help would be greatly appreciated.
Thanks!