Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:620019419136, committed 2015-01-20
- Comitter:
- giogal
- Date:
- Tue Jan 20 17:10:46 2015 +0000
- Parent:
- 1:adb624063b97
- Commit message:
- x
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jan 20 08:17:10 2015 +0000
+++ b/main.cpp Tue Jan 20 17:10:46 2015 +0000
@@ -10,6 +10,9 @@
#define MMA8451_I2C_ADDRESS (0x1d<<1)
#define CNTRL_REG_1 0x2A
+#define CNTRL_REG_2 0x2B
+#define CNTRL_REG_3 0x2C
+#define CNTRL_REG_4 0x2D
#define X_acc 0x01
#define Y_acc 0x03
#define Z_acc 0x05
@@ -19,6 +22,11 @@
//viene richiamata per le accelerazioni su ognuno dei tre assi
float conversion(char buf);
+int Inter=0;
+void isr(){
+ Inter=1;
+ }
+
int main(void)
{
//Classe I2C presente nella libreria mbed
@@ -40,19 +48,30 @@
char z_buffer;
char y_buffer;
char x_buffer;
+ InterruptIn trig(PTA15);
+
+ PwmOut rled(LED1);
+ PwmOut gled(LED2);
+ PwmOut bled(LED3);
//inizializziamo il registro di controllo a 0 per poterlo settare
char data[2] = {CNTRL_REG_1, 0x00};
i2c.write(address, data, 2);
- //settiamo il registro di controllo
- char data_wr_2[2]={CNTRL_REG_1, 0x3B};
- i2c.write(address,data_wr_2, 2);
+ char wr_2[2] = {CNTRL_REG_2, 0x04};
+ i2c.write(address, wr_2, 2);
+
+ char wr_4[2] = {CNTRL_REG_4, 0x01};
+ i2c.write(address, wr_4, 2);
+ char wr_3[2] = {CNTRL_REG_3, 0x02};
+ i2c.write(address, wr_3, 2);
+
+ //settiamo il registro di controllo
+ char wr_1[2]={CNTRL_REG_1, 0xFB};
+ i2c.write(address,wr_1, 2);
- PwmOut rled(LED1);
- PwmOut gled(LED2);
- PwmOut bled(LED3);
+
while (true) {
@@ -61,9 +80,10 @@
i2c.write(address,&stato,1,true);
i2c.read(address,&data_stato,1,false);
- //Se sono presenti nuovi valori
- if(data_stato & 8 == 8)
+ trig.rise(&isr);
+ if(Inter)
{
+ Inter = 0;
z = 0;
x = 0;
y = 0;
@@ -143,6 +163,6 @@
{
val+= 1;
}
- val = (float) val/64;
+ val = (float) val*9.8/64;
return val;
}