Odobasic Faris Mehanovic Adnan

Dependencies:   MMA8451Q mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MMA8451Q.h"
00003  
00004 #if   defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
00005   PinName const SDA = PTE25;
00006   PinName const SCL = PTE24;
00007 #elif defined (TARGET_KL05Z)
00008   PinName const SDA = PTB4;
00009   PinName const SCL = PTB3;
00010 #else
00011   #error TARGET NOT DEFINED
00012 #endif
00013  
00014 #define MMA8451_I2C_ADDRESS (0x1d<<1)
00015 
00016 Serial pc(USBTX, USBRX);
00017 
00018 int main(void) {
00019     MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
00020     PwmOut rled(LED1);
00021     PwmOut gled(LED2);
00022     PwmOut bled(LED3); 
00023     while (true) {
00024         float x, y, z;
00025         x = rled = 1.0 - abs(acc.getAccX());
00026         y = gled = 1.0 - abs(acc.getAccY());
00027         z = bled = 1.0 - abs(acc.getAccZ());
00028         pc.printf("Vrijednost po x-osi : %.2f \nVrijednost po y-osi : %.2f \nVrijednost po z-osi : %.2f \n", x, y, z);
00029         pc.printf("\n\n");
00030         wait(3);
00031     }
00032 }