0% found this document useful (0 votes)
36 views3 pages

TP 2

This document contains code for an embedded system that reads acceleration data from an accelerometer sensor over I2C. It displays the real-time x, y, and z acceleration values on an LCD screen in floating point format. The y-axis acceleration multiplied by 90 is also sent over serial. The code continuously loops, reading the sensor values, calculating the accelerations, displaying to LCD and serial, and sleeping for 1 second before repeating.

Uploaded by

anto.aumeunier
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

TP 2

This document contains code for an embedded system that reads acceleration data from an accelerometer sensor over I2C. It displays the real-time x, y, and z acceleration values on an LCD screen in floating point format. The y-axis acceleration multiplied by 90 is also sent over serial. The code continuously loops, reading the sensor values, calculating the accelerations, displaying to LCD and serial, and sleeping for 1 second before repeating.

Uploaded by

anto.aumeunier
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// Copyright (c) 2020 Antoine TRAN TAN

// Copyright (c) 2017 Sarah MARSH

#include "mbed.h"
#include "rtos.h"
#include "C12832.h"

// Using Arduino pin notation


C12832 lcd(D11, D13, D12, D7, D10);

I2C myI2C(I2C_SDA,I2C_SCL);

//event_callback_t calcul (int event);

short V1,V2,V3;
float accx,accy,accz;

char BufTx[2] = {0x07,0x00};


char BufTx2[2] = {0x08,0x21};
char BufTx3[2] = {0x07,0x01};
char BufRx[3];
char Registre[1] = {0x00};

signed char x,y,z;

//void touche_c();

char caractere;

char tab[100];

bool test = true;

UnbufferedSerial serial(USBTX,USBRX,115200);

int main()
{

myI2C.frequency(100000);

myI2C.write(0x98,BufTx,2);
myI2C.write(0x98,BufTx2,2);
myI2C.write(0x98,BufTx3,2);
//serial.attach(&touche_c);

while (true)
{
lcd.cls();

myI2C.write(0x98,Registre,1,true);
myI2C.read(0x99,BufRx,3);

x = BufRx[0];
y = BufRx[1];
z = BufRx[2];

if((x & 0x20) == 0x20)


{
x = x | 0xC0;
}
else
{
x = x & 0x3F;
}

if((y & 0x20) == 0x20)


{
y = y | 0xC0;
}
else
{
y= y & 0x3F;
}

if((z & 0x20) == 0x20)


{
z = z | 0xC0;
}
else
{
z = z & 0x3F;
}

V1 = ((short)x);
V2 = ((short)y);
V3 = ((short)z);

accx = (float)V1 * 1.5f / 32.0f;


accy = (float)V2 * 1.5f / 32.0f;
accz = (float)V3 * 1.5f / 32.0f;

lcd.locate(0,0);
lcd.printf("x : %4.2f\ny : %4.2f\nz : %4.2f",accx,accy,accz);
sprintf(tab,"%4.2f\n",accy * 90.0f );

serial.write(tab,strlen(tab));
//serial.write("\033[1A",5);

ThisThread::sleep_for(1000ms);
}
}

You might also like