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: poirier-proj-95 TFT_fonts mbed
Diff: perso/diver.h
- Revision:
- 3:24069293d35d
- Parent:
- 2:1d66e2e776bc
diff -r 1d66e2e776bc -r 24069293d35d perso/diver.h
--- a/perso/diver.h Wed May 13 08:01:47 2015 +0000
+++ b/perso/diver.h Tue Sep 15 16:09:10 2015 +0000
@@ -1,40 +1,44 @@
-// pour le moment ce sont des choses inutiles
+
+// pour lecture I2C accelerometre
+ PinName const SDA = PTE25;
+ PinName const SCL = PTE24;
+ I2C i2c(SDA,SCL);
+
+#define REG_WHO_AM_I 0x0D
+#define REG_CTRL_REG_1 0x2A
+#define REG_OUT_X_MSB 0x01
+#define REG_OUT_Y_MSB 0x03
+#define REG_OUT_Z_MSB 0x05
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+// #define UINT14_MAX 16383
+#define UINT14_MAX 16384
-/*#if defined(TARGET_LPC11U24) //SEEEDUINO_ARCH
-#define PIN_XP P0_14
-#define PIN_XM P0_12
-#define PIN_YP P0_13
-#define PIN_YM P0_11
-#define PIN_MOSI P1_22
-#define PIN_MISO P1_21
-#define PIN_SCLK P1_20
-#define PIN_CS_TFT P1_24
-#define PIN_DC_TFT P1_25
-#define PIN_BL_TFT P1_5
-#define PIN_CS_SD P1_18
-#elif defined(TARGET_LPC1768) //SEEEDUINO_ARCH_PRO
-#define PIN_XP P0_26
-#define PIN_XM P0_24
-#define PIN_YP P0_25
-#define PIN_YM P0_23
-#define PIN_MOSI P0_18
-#define PIN_MISO P0_17
-#define PIN_SCLK P0_15
-#define PIN_CS_TFT P2_3
-#define PIN_DC_TFT P2_4
-#define PIN_BL_TFT P2_5
-#define PIN_CS_SD P2_2
-#else //please redefine the following pins
-#define PIN_XP
-#define PIN_XM
-#define PIN_YP
-#define PIN_YM
-#define PIN_MOSI
-#define PIN_MISO
-#define PIN_SCLK
-#define PIN_CS_TFT
-#define PIN_DC_TFT
-#define PIN_BL_TFT
-#define PIN_CS_SD
-#endif*/
+static const float redx=0.0f;
+static const float redy=1.0f;
+static const float greenx=sqrt(3.0f)/2.0f;
+static const float greeny=-0.5f;
+static const float bluex=-sqrt(3.0f)/2.0f;
+static const float bluey=-0.5f;
+
+static const float twothirds=2.0f/3.0f;
+
+
+float acclnread(uint8_t reg)
+{
+ // Normalisation here seems wrong
+ char t[1]= {reg};
+ i2c.write(MMA8451_I2C_ADDRESS,t,1,true);
+ uint8_t xbits[2] = {0,0};
+ i2c.read(MMA8451_I2C_ADDRESS,(char *)xbits,2);
+ int16_t xint = 0;
+ xint=(xbits[0]<<6)|(xbits[1]>>2);
+ // this sign flip code looks wrong, UINT14_MAX maps to 0
+ // UINT14_MAX=16383, should it be UINT14_MAX=16384
+ if (xint > UINT14_MAX>>1)
+ xint -= UINT14_MAX;
+ return float(xint)/4096.0f;
+ // return float(xint);
+}