Could somebody help me to understand why my Serial.Print loop works nicely when I declare a FOUR element integer array by writing int16_t cmps[3] = {0}; but the same Serial.Print loop only prints a single line when I declare a three element integer array by writing int16_t cmps[2] ?
All I am trying to do is to repeatedly print three integer values - namely cmps[0], cmps[1] and cmps[2] that keep getting updated.
I find that I only get a single line output when declare the integer array with 3 elements, ie. int16_t cmps[2]. So my output would just be 1 line.
70 -88 -116
But once I declare the array with 4 integers, such as int16_t cmps[3], then the loop always works properly, such as with outputs:
62 -92 -120
68 -90 -124
66 -86 -124
69 -89 -121
68 -84 -118
66 -84 -120
68 -90 -118
(and the lines just keep building forever).
Would someone be able to let me know why my Serial.Print code only works properly when I declare my integer array to be larger than what I need? That is everything works excellently when I declare the array (cmps) with 4 elements, while declaring with 3 elements causes my code to print a single line of values (then seemingly gets jammed).
Thanks in advance!
Kenny
===============================
int16_t cmps[2] = {0};
void loop()
{
// Print all sensor values which the sensor provides
// Formated all values as x, y, and z in order for
// Compass, Gyro, Acceleration. The First value is
// the temperature.
I2Cdev::writeByte(MAG_I2C_ADDY, MAG_CNTL, 0x00);
delay(10);
I2Cdev::writeByte(MAG_I2C_ADDY, MAG_CNTL, 0x01);
delay(10);
cmps[0] = readMAG(0x03, 0x04);
cmps[1] = readMAG(0x05, 0x06);
cmps[2] = readMAG(0x07, 0x08);
Serial.print(cmps[0]);Serial.print(" ");Serial.print(cmps[1]);Serial.print(" ");Serial.print(cmps[2]);
Serial.println();
delay(100);
}
==============================