Expected ';' (or ')') before numeric constant

Hello

I'm trying to average reading from MPU6050, but with floats.

Thats my Code:

#include<Wire.h>

const int MPU_addr = 0x68;
int16_t ax, ay, az;
long xSum;
long ySum;
long zSum;
long ReadingNo;
float axT, ayT, azT;
float aT[3];


void setup() {
  Wire.begin();
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(57600);
  ReadingNo = 0;
}

void loop() {
  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr, 6, true); // request a total of 14 registers
  ax = Wire.read() << 8 | Wire.read();
  ay = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  az = Wire.read() << 8 | Wire.read();
  xSum += ax;
  ySum += ay;
  zSum += az;
  ReadingNo++;
  delay(5);
  if (ReadingNo >= 100) {
    axT = (float)xSum / ReadingNo.0;
    ayT = (float)ySum / ReadingNo.0;
    azT = (float)zSum / ReadingNo.0;
    aT[] = {axT, ayT, azT};
    ReadingNo = 0;
  }
}

And there i get "expected ';' before numeric constant" in lines with axT=, ayT= and azT=.

When I change that into:

axT = (xSum / ReadingNo.0);
    ayT = (ySum / ReadingNo.0);
    azT = (zSum / ReadingNo.0);

Error is "expected ')' before numeric constant". What should I change to make it work?

I'd start by removing the '.0' from such statements:

ReadingNo.0

to see if it more acceptable to the compiler.

Putting ".0" after a value makes it a float rather than an int. For example "123" is an int but "123.0" is a float. But you cannot do that to a variable. You must "cast" the variable to change its type like this:

axT = xSum / ((float) ReadingNo);

Ok, everything is working now, thanks :slight_smile:

   aT[] = {axT, ayT, azT};

If you want to insert values into an array after it has been declared you have to put each of them into the array separately

aT[0] = axT;
aT[1] = ayT;
aT[2] = azT;