satoshi shimada
/
mbed_mpu6050_i2c_raw_register
MPU-6050 sample code
main.cpp@0:abd3a0fd55a9, 2018-12-12 (annotated)
- Committer:
- satoshi1204
- Date:
- Wed Dec 12 12:42:30 2018 +0000
- Revision:
- 0:abd3a0fd55a9
- Child:
- 1:6f743fe9a027
implement MPU library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
satoshi1204 | 0:abd3a0fd55a9 | 1 | #include "mbed.h" |
satoshi1204 | 0:abd3a0fd55a9 | 2 | #include "mpu6050.h" |
satoshi1204 | 0:abd3a0fd55a9 | 3 | |
satoshi1204 | 0:abd3a0fd55a9 | 4 | DigitalOut myled(LED1); |
satoshi1204 | 0:abd3a0fd55a9 | 5 | Serial pc(USBTX, USBRX); |
satoshi1204 | 0:abd3a0fd55a9 | 6 | MPU6050 mpu(p9, p10); |
satoshi1204 | 0:abd3a0fd55a9 | 7 | |
satoshi1204 | 0:abd3a0fd55a9 | 8 | void readData() |
satoshi1204 | 0:abd3a0fd55a9 | 9 | { |
satoshi1204 | 0:abd3a0fd55a9 | 10 | double ax, ay, az; |
satoshi1204 | 0:abd3a0fd55a9 | 11 | mpu.readAccelemeter(ax, ay, az); |
satoshi1204 | 0:abd3a0fd55a9 | 12 | double gx, gy, gz; |
satoshi1204 | 0:abd3a0fd55a9 | 13 | mpu.readGyroscope(gx, gy, gz); |
satoshi1204 | 0:abd3a0fd55a9 | 14 | pc.printf("%.4lf %.4lf %.4lf %.4lf %.4lf %.4lf\r\n", ax, ay, az, gx, gy, gz); |
satoshi1204 | 0:abd3a0fd55a9 | 15 | } |
satoshi1204 | 0:abd3a0fd55a9 | 16 | |
satoshi1204 | 0:abd3a0fd55a9 | 17 | int main() { |
satoshi1204 | 0:abd3a0fd55a9 | 18 | int acc, gyro; |
satoshi1204 | 0:abd3a0fd55a9 | 19 | mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec); |
satoshi1204 | 0:abd3a0fd55a9 | 20 | mpu.getMaxScale(acc, gyro); |
satoshi1204 | 0:abd3a0fd55a9 | 21 | pc.printf("%x %x\r\n", acc, gyro); |
satoshi1204 | 0:abd3a0fd55a9 | 22 | while(1) { |
satoshi1204 | 0:abd3a0fd55a9 | 23 | myled = 1; |
satoshi1204 | 0:abd3a0fd55a9 | 24 | readData(); |
satoshi1204 | 0:abd3a0fd55a9 | 25 | wait(0.2); |
satoshi1204 | 0:abd3a0fd55a9 | 26 | myled = 0; |
satoshi1204 | 0:abd3a0fd55a9 | 27 | wait(0.2); |
satoshi1204 | 0:abd3a0fd55a9 | 28 | } |
satoshi1204 | 0:abd3a0fd55a9 | 29 | } |