Skip to main content
added 350 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

You got confused here:

Serial.print(data[idx]);

You're printing array slice 5 (the sixth entry in a 5 entry array) 5 times.

You probably meant to write:

Serial.print(data[i]);

To improve clarity you may want to #define it instead:

#define DATA_SIZE 5
uint16_t data[DATA_SIZE];

... 

for (int i = 0; i < DATA_SIZE; i++) {
    ....
}

Or you can do it the other way round (get the size from the array):

uint16_t data[5];
#define DATA_SIZE (sizeof(data) / sizeof(data[0]))

You got confused here:

Serial.print(data[idx]);

You're printing array slice 5 (the sixth entry in a 5 entry array) 5 times.

You probably meant to write:

Serial.print(data[i]);

You got confused here:

Serial.print(data[idx]);

You're printing array slice 5 (the sixth entry in a 5 entry array) 5 times.

You probably meant to write:

Serial.print(data[i]);

To improve clarity you may want to #define it instead:

#define DATA_SIZE 5
uint16_t data[DATA_SIZE];

... 

for (int i = 0; i < DATA_SIZE; i++) {
    ....
}

Or you can do it the other way round (get the size from the array):

uint16_t data[5];
#define DATA_SIZE (sizeof(data) / sizeof(data[0]))
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

You got confused here:

Serial.print(data[idx]);

You're printing array slice 5 (the sixth entry in a 5 entry array) 5 times.

You probably meant to write:

Serial.print(data[i]);