Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hexi_OLED_SSD1351
Diff: GYROMETER.cpp
- Revision:
- 0:a84d2425acba
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/GYROMETER.cpp Fri Jul 26 13:37:55 2019 +0000
@@ -0,0 +1,45 @@
+
+#include "GYROMETER.h"
+ #include "mbed.h"
+
+GYROMETER::GYROMETER(PinName sda, PinName scl) : gyroi2c(sda,scl)
+ {
+
+ }
+
+ void GYROMETER::Config(void)
+ {
+ char d[2];
+ d[0] = GYRO_CTRL_REG1; //standby mode
+ d[1] = 0x08;
+ gyroi2c.write(GYRO_I2C_ADDRESS, d,2);
+
+
+ d[0] = GYRO_CTRL_REG0;
+ d[1] = 0x00;
+ gyroi2c.write(GYRO_I2C_ADDRESS, d, 2);
+
+
+ d[0] = GYRO_CTRL_REG1; // active mode
+ d[1] = 0x0A;
+ gyroi2c.write(GYRO_I2C_ADDRESS, d,2);
+
+ }
+
+ void GYROMETER::getData(float * g_data)
+ {
+
+ char data_bytes[7];
+ gyroi2c.write(GYRO_I2C_ADDRESS,GYRO_STATUS,1,true); // Read the 6 data bytes
+ gyroi2c.read(GYRO_I2C_ADDRESS,data_bytes,7);
+
+ g_data[0] = (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * 0.0625;
+ g_data[1] = (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * 0.0625;
+ g_data[2] = (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * 0.0625;
+
+ }
+
+
+
+
+