freefall-sleep

Dependencies:   MMA8451Q mbed

main.cpp

Committer:
zdenka
Date:
2017-11-11
Revision:
0:97ddc2168412
Child:
1:1b10921f4922

File content as of revision 0:97ddc2168412:

#include "mbed.h"
#include "MMA8451Q.h"

#if   defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
  PinName const SDA = PTE25;
  PinName const SCL = PTE24;
#elif defined (TARGET_KL05Z)
  PinName const SDA = PTB4;
  PinName const SCL = PTB3;
#elif defined (TARGET_K20D50M)
  PinName const SDA = PTB1;
  PinName const SCL = PTB0;
#else
  #error TARGET NOT DEFINED
#endif

#define MMA8451_I2C_ADDRESS (0x1d<<1)
Serial pc(USBTX, USBRX);

    MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
InterruptIn in(PTA15);
void svojafunkcia(){
    uint8_t data[1];
    acc.readRegs(0x0C,data,1);
    if((data[0]&0x04)==0x04){
        uint8_t cokolvek[1];
        acc.readRegs(0x16,cokolvek,1);
                pc.printf("prerusenie\r \n"); // print the value of variable i

        }
    }
    
int main(void)
{
    in.fall(&svojafunkcia);
    
    //krok1
    uint8_t data1[2] = {0x2A, 0x20};
    acc.writeRegs(data1, 2);
    
     //krok2
    uint8_t data2[2] = {0x15, 0xB8};
    acc.writeRegs(data2, 2);
    
     //krok3
    uint8_t data3[2] = {0x17, 0x03};
    acc.writeRegs(data3, 2);
    
     //krok4
    uint8_t data4[2] = {0x18, 0x06};
    acc.writeRegs(data4, 2);
    
     //krok5
    uint8_t data5[2] = {0x2D, 0x04};
    acc.writeRegs(data5, 2);
    
     //krok6
    uint8_t data6[2] = {0x2E, 0x00};
    acc.writeRegs(data6, 2);
    
    //krok7
    uint8_t data[1];
    acc.readRegs(0x2A,data,1);
    data[0]=data[0]| 0x01;
    uint8_t data7[2]={0x2A,data[0]};
    data7[1]=data[0];
    acc.writeRegs(data7,2);
    /*
    PwmOut rled(LED1);
    PwmOut gled(LED2);
    PwmOut bled(LED3);
*/
  //  printf("MMA8451 ID: %d\n", acc.getWhoAmI());

    while (true) {
/*        float x, y, z;
        x = abs(acc.getAccX());
        y = abs(acc.getAccY());
        z = abs(acc.getAccZ());
        rled = 1.0f - x;
        gled = 1.0f - y;
        bled = 1.0f - z;
        wait(0.1f);
        printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z);
   */ }
}