加速度・ジャイロセンサ―
Fork of MPU-6050 by
Diff: MPU6050.h
- Revision:
- 7:ea53dc62603d
- Parent:
- 6:01dbbf760e1a
- Child:
- 8:15523fc1427d
--- a/MPU6050.h Sun May 15 06:48:16 2016 +0000 +++ b/MPU6050.h Sun May 15 09:33:34 2016 +0000 @@ -41,10 +41,10 @@ // Using the GY-521 breakout board, I set ADO to 0 by grounding through a 4k7 resistor // Seven-bit device address is 110100 for ADO = 0 and 110101 for ADO = 1 - if(ad0) { + if(ad0 == 0) { + adr = 0x68; + } else { adr = 0x69; - } else { - adr = 0x68; } // Specify sensor full scale @@ -119,35 +119,35 @@ } - void readAccelData(int16_t * destination) { + void readAccelData(int * destination) { /** 加速度の読み出し * @param destination int[3]の配列を渡してください、加速度をxyz順に返します */ uint8_t rawData[6]; // x/y/z accel register data stored here readBytes(ACCEL_XOUT_H, 6, &rawData[0]); // Read the six raw data registers into data array - destination[0] = (int16_t)(((int16_t)rawData[0] << 8) | rawData[1]) ; // Turn the MSB and LSB into a signed 16-bit value - destination[1] = (int16_t)(((int16_t)rawData[2] << 8) | rawData[3]) ; - destination[2] = (int16_t)(((int16_t)rawData[4] << 8) | rawData[5]) ; + destination[0] = (int)(((int8_t)rawData[0] << 8) | rawData[1]) ; // Turn the MSB and LSB into a signed 16-bit value + destination[1] = (int)(((int8_t)rawData[2] << 8) | rawData[3]) ; + destination[2] = (int)(((int8_t)rawData[4] << 8) | rawData[5]) ; } - void readGyroData(int16_t * destination) { + void readGyroData(int * destination) { /** 角速度の読み出し * @param destination int[3]の配列を渡してください、角速度をxyz順に返します */ uint8_t rawData[6]; // x/y/z gyro register data stored here readBytes(GYRO_XOUT_H, 6, &rawData[0]); // Read the six raw data registers sequentially into data array - destination[0] = (int16_t)(((int16_t)rawData[0] << 8) | rawData[1]) ; // Turn the MSB and LSB into a signed 16-bit value - destination[1] = (int16_t)(((int16_t)rawData[2] << 8) | rawData[3]) ; - destination[2] = (int16_t)(((int16_t)rawData[4] << 8) | rawData[5]) ; + destination[0] = (int)(((int8_t)rawData[0] << 8) | rawData[1]) ; // Turn the MSB and LSB into a signed 16-bit value + destination[1] = (int)(((int8_t)rawData[2] << 8) | rawData[3]) ; + destination[2] = (int)(((int8_t)rawData[4] << 8) | rawData[5]) ; } - int16_t readTempData() { + int readTempData() { /** 温度の読み出し * @return int型の変数に代入してください、温度を返します */ uint8_t rawData[2]; // x/y/z gyro register data stored here readBytes(TEMP_OUT_H, 2, &rawData[0]); // Read the two raw data registers sequentially into data array - return (int16_t)(((int16_t)rawData[0]) << 8 | rawData[1]) ; // Turn the MSB and LSB into a 16-bit value + return (int)(((int8_t)rawData[0]) << 8 | rawData[1]) ; // Turn the MSB and LSB into a 16-bit value }