
code c++ carte KL25Z avec écran TFT Qr4 526S01 TP28017 oscilloscope (en développement)
Dependencies: poirier-proj-95 TFT_fonts mbed
Revision 3:24069293d35d, committed 2015-09-15
- Comitter:
- dujardin
- Date:
- Tue Sep 15 16:09:10 2015 +0000
- Parent:
- 2:1d66e2e776bc
- Child:
- 4:56b453735e89
- Commit message:
- base pour des projets de S3; IUT de cergy Neuville ; cr?ation : dujardin
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
perso/diver.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed May 13 08:01:47 2015 +0000 +++ b/main.cpp Tue Sep 15 16:09:10 2015 +0000 @@ -14,12 +14,28 @@ #include "Arial28x28.h" #include "font_big.h" #include "diver.h" - + PwmOut rled(LED_RED); // init + PwmOut gled(LED_GREEN); + PwmOut bled(LED_BLUE); SeeedStudioTFTv2 TFT(PTB3, PTB1, PTB2, PTB0, PTD2, PTD3, PTD1, PTA5, PTC8, PTC9, PTA4); int main() { + // init I2C accélero + uint8_t data[2] = {REG_CTRL_REG_1, 0x01}; + i2c.write(MMA8451_I2C_ADDRESS,(char *)data,2); + + // initially set leds off + rled=1.0f; + gled=1.0f; + bled=1.0f; + // 1ms pwm frequency + rled.period(0.001f); + gled.period(0.001f); + bled.period(0.001f); + + //Configure l'afficheur TFT TFT.background(Black); TFT.foreground(White); @@ -28,12 +44,12 @@ //Print : message de bonjour TFT.set_font((unsigned char*) Arial28x28); TFT.locate(0,0); - TFT.printf("Bonjour la France v1"); + TFT.printf("Bonjour "); - //Wait for 5 seconds - wait(5.0); + //Wait for 1 seconds + wait(1.0); - //Draw some graphics + //Draw some graphics // inutile sauf comme exemple de programmation TFT.cls(); TFT.set_font((unsigned char*) Arial24x23); TFT.locate(100,100); @@ -55,23 +71,36 @@ TFT.pixel(i, 100 + (int)s, Red); } - //Wait for 5 seconds - wait(5.0); + //Wait for 1 seconds + wait(1.0); - //Multiple fonts + //Multiple fonts // vous montre d'autres choses TFT.foreground(White); TFT.background(Blue); TFT.cls(); TFT.set_font((unsigned char*) Arial24x23); TFT.locate(0,0); TFT.printf("Different Fonts :"); - TFT.set_font((unsigned char*) Neu42x35); - TFT.locate(0,30); - TFT.printf("Hello Mbed 1"); + TFT.set_font((unsigned char*) Arial24x23); TFT.locate(20,80); TFT.printf("Hello Mbed 2"); TFT.set_font((unsigned char*) Arial12x12); TFT.locate(35,120); TFT.printf("Hello Mbed 3"); + + while (true) { + + float xaccln,yaccln; + xaccln=acclnread(REG_OUT_X_MSB); + yaccln=acclnread(REG_OUT_Y_MSB); + + TFT.locate(35,220); + TFT.printf("X: %1.4f, Y: %1.4f", xaccln, yaccln ); + + wait(0.1f); + + + } + }
--- 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); +}