qewsrfghjnk

Dependencies:   MMA8451Q mbed

Committer:
pratit911
Date:
Wed May 30 07:24:16 2018 +0000
Revision:
0:ee88287d4817
edfghjk

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pratit911 0:ee88287d4817 1 #include "mbed.h"
pratit911 0:ee88287d4817 2 #include "MMA8451Q.h"
pratit911 0:ee88287d4817 3
pratit911 0:ee88287d4817 4 #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
pratit911 0:ee88287d4817 5 PinName const SDA = PTE25;
pratit911 0:ee88287d4817 6 PinName const SCL = PTE24;
pratit911 0:ee88287d4817 7 #elif defined (TARGET_KL05Z)
pratit911 0:ee88287d4817 8 PinName const SDA = PTB4;
pratit911 0:ee88287d4817 9 PinName const SCL = PTB3;
pratit911 0:ee88287d4817 10 #elif defined (TARGET_K20D50M)
pratit911 0:ee88287d4817 11 PinName const SDA = PTB1;
pratit911 0:ee88287d4817 12 PinName const SCL = PTB0;
pratit911 0:ee88287d4817 13 #else
pratit911 0:ee88287d4817 14 #error TARGET NOT DEFINED
pratit911 0:ee88287d4817 15 #endif
pratit911 0:ee88287d4817 16
pratit911 0:ee88287d4817 17 #define MMA8451_I2C_ADDRESS (0x1d<<1)
pratit911 0:ee88287d4817 18
pratit911 0:ee88287d4817 19 int main(void)
pratit911 0:ee88287d4817 20 {
pratit911 0:ee88287d4817 21 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
pratit911 0:ee88287d4817 22 PwmOut rled(LED1);
pratit911 0:ee88287d4817 23 PwmOut gled(LED2);
pratit911 0:ee88287d4817 24 PwmOut bled(LED3);
pratit911 0:ee88287d4817 25
pratit911 0:ee88287d4817 26 printf("MMA8451 ID: %d\n", acc.getWhoAmI());
pratit911 0:ee88287d4817 27
pratit911 0:ee88287d4817 28 while (true) {
pratit911 0:ee88287d4817 29 float x, y, z;
pratit911 0:ee88287d4817 30 x = abs(acc.getAccX());
pratit911 0:ee88287d4817 31 y = abs(acc.getAccY());
pratit911 0:ee88287d4817 32 z = abs(acc.getAccZ());
pratit911 0:ee88287d4817 33 rled = 1.0f - x;
pratit911 0:ee88287d4817 34 gled = 1.0f - y;
pratit911 0:ee88287d4817 35 bled = 1.0f - z;
pratit911 0:ee88287d4817 36 wait(0.1f);
pratit911 0:ee88287d4817 37 printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z);
pratit911 0:ee88287d4817 38 }
pratit911 0:ee88287d4817 39 }