project1

Dependencies:   mbed TSI MMA8451Q

Committer:
bcis93
Date:
Thu Sep 19 19:36:36 2019 +0000
Revision:
1:69b15daf7a7d
Parent:
0:529f900ad93b
Child:
2:316ddc3b4384
Changes for module 1

Who changed what in which revision?

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