Éric Bisson
/
Code_APP3_R
app3
Fork of Code_APP1 by
Diff: main.cpp
- Revision:
- 1:3430643e8ed4
- Parent:
- 0:52fba6f1554b
- Child:
- 2:9aacd567c70b
--- a/main.cpp Sat Jan 14 21:12:38 2017 +0000 +++ b/main.cpp Sun Jan 15 19:36:05 2017 +0000 @@ -6,41 +6,37 @@ I2C i2c(p28, p27); PwmOut led1(LED1); int addrChip = 0x3A; -char buffer[6]; -int resultat[3]; +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 - char addrIdle[2] = {0x2A, 0x01}; - i2c.write(addrChip, addrIdle, 2, true); + //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, 6); - pc.printf("%03x\t", buffer[2]); - pc.printf("%03x\t", buffer[3]); - char temp[1]; - temp[0] = ("%02x"+"%02x", buffer[2], buffer[3]); - pc.printf("%02x\n", temp[0]); - //resultat[0] = buffer[0]+buffer[1] + 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"); - /*pc.printf("%02x\n", buffer[0]); - pc.printf("%02x\n", buffer[1]); - pc.printf("%02x\n", buffer[2]); - pc.printf("%02x\n", buffer[3]); - pc.printf("%02x\n", buffer[4]); - pc.printf("%02x\n", buffer[5]);*/ - //----Base SPI---- cs = 0; spi.format(8,0); spi.frequency(250000); - spi.write(buffer[0]); - spi.write(buffer[1]); - spi.write(buffer[2]); - spi.write(buffer[3]); - + wait(0.1); + cs = 1; }