Alexandre Lemay
/
APP1_s5_A17
PARTYYYY
Revision 3:56cd9dff3b5f, committed 2017-09-04
- Comitter:
- evrast
- Date:
- Mon Sep 04 22:39:02 2017 +0000
- Parent:
- 1:ad54e8b7ac20
- Child:
- 4:ab14f0e33f2b
- Commit message:
- MMA library;
Changed in this revision
--- a/Accelerometre.cpp Mon Sep 04 20:00:30 2017 +0000 +++ b/Accelerometre.cpp Mon Sep 04 22:39:02 2017 +0000 @@ -2,19 +2,39 @@ +Accelerometre::Accelerometre():i2c(p9,p10),pc(USBTX, USBRX),acc(p9, p10, 40000){ + } + +int Accelerometre::readxyzAngle(double *x, double *y, double *z){ + + acc.readXYZGravity(x,y,z); + +} + + + + +//int Accelerometre::readSingleByte(int regis){ +// int c; +// pc.printf("Reading single byte\n"); +// i2c.start(); +// int a=i2c.write(WRITE_DATA); // A write to device +// i2c.write(regis); // Register to read from (acceleration in X) +// i2c.start(); // Need to send start condition here +// i2c.write(READ_DATA); // tell devide you want to read +// c=i2c.read(0); +// i2c.stop(); +// pc.printf("value is %d\n", c); +// pc.printf("end\n"); +// return c; +// } + -int Accelerometre::readSingleByte(int regis){ - char cmd[8]; - int c; +void Accelerometre::writeByte(int regis,int data){ pc.printf("Reading single byte\n"); i2c.start(); - int a=i2c.write(0x38); // A write to device + i2c.write(WRITE_DATA); // A write to device i2c.write(regis); // Register to read from (acceleration in X) - i2c.start(); // Need to send start condition here - i2c.write(0x39); // tell devide you want to read - c=i2c.read(0); + i2c.write(data); i2c.stop(); - pc.printf("value is %d\n", c); - pc.printf("end\n"); - return c; - } \ No newline at end of file +}
--- a/Accelerometre.h Mon Sep 04 20:00:30 2017 +0000 +++ b/Accelerometre.h Mon Sep 04 22:39:02 2017 +0000 @@ -1,9 +1,20 @@ #include "mbed.h" +#include "MMA8452.h" class Accelerometre{ - int readSingleByte(int regist); + int const WRITE_DATA = 0x38; + int const READ_DATA = 0x39; + MMA8452 acc; + I2C i2c; + + Serial pc; + public: + void writeByte(int Regist,int data); + int readxyzAngle(double *x, double *y, double *z); + int readMultiByte(int regist); + Accelerometre(); }; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA8452.lib Mon Sep 04 22:39:02 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/ashleymills/code/MMA8452/#a92a632a0cc7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MainEvr.cpp Mon Sep 04 22:39:02 2017 +0000 @@ -0,0 +1,20 @@ + +#include "Accelerometre.h" + + +Serial pc(USBTX, USBRX); +int main() { + + + + Accelerometre acc; + acc.writeByte(0x2A,0x01); + + double x = 0, y = 0, z = 0; + + + + acc.readxyzAngle(&x,&y,&z); + pc.printf("Gravities: %lf %lf %lf\r\n",x,y,z); + +} \ No newline at end of file
--- a/maint.cpp Mon Sep 04 20:00:30 2017 +0000 +++ b/maint.cpp Mon Sep 04 22:39:02 2017 +0000 @@ -1,45 +1,48 @@ #include "mbed.h" -class Afficheur -{ - Afficheur() - { - afficheur.format(8,0); - afficheur.frequency(50000); - p8 = 1; - } - - void write(char characters[4], bool dot ) - { - - char rx; - - pin =0; - afficheur.write - afficheur.write(characters,4,rx,4); - pin =1; - - } - - static SPI afficheur(p5,p6,p7); - static DigitalOut chipSelect(p8); -} + + -DigitalOut pin(p8); - -Serial pc(USBTX, USBRX); // tx, rx - -int main() { - - while(1) - { - char rx[50]; - if(pc.readable()) { - pin = 0; - afficheur.write("1234",4,rx,50); - pin = 1; - wait(1); - } - } -} +//class Afficheur +//{ +// Afficheur() +// { +// afficheur.format(8,0); +// afficheur.frequency(50000); +// p8 = 1; +// } +// +// void write(char characters[4], bool dot ) +// { +// +// char rx; +// +// pin =0; +// afficheur.write +// afficheur.write(characters,4,rx,4); +// pin =1; +// +// } +// +// static SPI afficheur(p5,p6,p7); +// static DigitalOut chipSelect(p8); +//} +// +//DigitalOut pin(p8); +// +//Serial pc(USBTX, USBRX); // tx, rx +// +//int main() { +// +// while(1) +// { +// char rx[50]; +// if(pc.readable()) { +// pin = 0; +// afficheur.write("1234",4,rx,50); +// pin = 1; +// wait(1); +// } +// } +//}