![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pre commentaire
Fork of Code_APP3_R by
main.cpp
- Committer:
- LouBe4
- Date:
- 2017-01-15
- Revision:
- 2:9aacd567c70b
- Parent:
- 1:3430643e8ed4
- Child:
- 3:5dcf9b78f3ad
File content as of revision 2:9aacd567c70b:
#include "mbed.h" Serial pc(USBTX, USBRX); SPI spi(p11, p12, p13); DigitalOut cs(p14); I2C i2c(p28, p27); PwmOut led1(LED1); int addrChip = 0x3A; char buffer[3]; int calculer_angle(char accX, char accY, char accZ) { pc.printf(&accX); pc.printf(&accY); pc.printf(&accZ); return 0; } int main() { //Activer l'accéléromètre pour lecture 8 bits char activation[2] = {0x2A, 0x03}; i2c.write(addrChip, activation, 2, true); //Aller lire les valeurs d'accélération buffer[0] = 0x01; i2c.write(addrChip, buffer, 1, true); i2c.read(addrChip, buffer, 3); int angle = calculer_angle(buffer[0], buffer[1], buffer[2]); //pc.printf("%02x\t", buffer[0]); //pc.printf("%02x\t", buffer[1]); //pc.printf("%02x\t", buffer[2]); //pc.printf("\n"); //----Base SPI---- cs = 0; spi.format(8,0); spi.frequency(250000); wait(0.1); cs = 1; }