Hello World

Dependencies:   MMA8451Q mbed

Committer:
Daniel90
Date:
Tue May 27 09:20:28 2014 +0000
Revision:
0:fa7bb836444d
Hello World

Who changed what in which revision?

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