#define PIN_X A5
#define PIN_Y A6
#define PIN_Z A7

#define BUFLEN 100

void setup() {
  Serial.begin(115200);
  // A-Dコンバーターの解像度を設定
  analogReadResolution(14);
}

// A-Dコンバーターの読み取り値を加速の変換する関数
float AtoG(int a) {
  return a * 5.0 / 16384 - 2.5;
}

void loop() {
  float X = AtoG(analogRead(PIN_X));
  float Y = AtoG(analogRead(PIN_Y));
  float Z = AtoG(analogRead(PIN_Z));
  // シリアル・プロッタ出力
  char buffer[BUFLEN];
  snprintf(buffer, sizeof(buffer), "X:%.2f, Y:%.2f, Z:%.2f", X, Y, Z);
  Serial.println(buffer);
  delay(100);
}
