tim010 tim010
/
LV9-GRUPA2-TIM10-ZADATAK1
Beganovic Benjamin Babic Mirhat
main.cpp@0:0e251e6860c0, 2014-05-12 (annotated)
- Committer:
- tim010
- Date:
- Mon May 12 08:24:39 2014 +0000
- Revision:
- 0:0e251e6860c0
LV9-GRUPA2-TIM10
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim010 | 0:0e251e6860c0 | 1 | #include "mbed.h" |
tim010 | 0:0e251e6860c0 | 2 | #include "MMA8451Q.h" |
tim010 | 0:0e251e6860c0 | 3 | |
tim010 | 0:0e251e6860c0 | 4 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
tim010 | 0:0e251e6860c0 | 5 | PinName const SDA = PTE25; |
tim010 | 0:0e251e6860c0 | 6 | PinName const SCL = PTE24; |
tim010 | 0:0e251e6860c0 | 7 | #elif defined (TARGET_KL05Z) |
tim010 | 0:0e251e6860c0 | 8 | PinName const SDA = PTB4; |
tim010 | 0:0e251e6860c0 | 9 | PinName const SCL = PTB3; |
tim010 | 0:0e251e6860c0 | 10 | #else |
tim010 | 0:0e251e6860c0 | 11 | #error TARGET NOT DEFINED |
tim010 | 0:0e251e6860c0 | 12 | #endif |
tim010 | 0:0e251e6860c0 | 13 | |
tim010 | 0:0e251e6860c0 | 14 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
tim010 | 0:0e251e6860c0 | 15 | Serial pc(USBTX, USBRX); |
tim010 | 0:0e251e6860c0 | 16 | |
tim010 | 0:0e251e6860c0 | 17 | int main(void) { |
tim010 | 0:0e251e6860c0 | 18 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
tim010 | 0:0e251e6860c0 | 19 | float x, y, z; |
tim010 | 0:0e251e6860c0 | 20 | |
tim010 | 0:0e251e6860c0 | 21 | while(1) { |
tim010 | 0:0e251e6860c0 | 22 | x = acc.getAccX(); |
tim010 | 0:0e251e6860c0 | 23 | y = acc.getAccY(); |
tim010 | 0:0e251e6860c0 | 24 | z = acc.getAccZ(); |
tim010 | 0:0e251e6860c0 | 25 | pc.printf("x: %f, y: %f, z: %f\n", x, y, z); |
tim010 | 0:0e251e6860c0 | 26 | wait(1); |
tim010 | 0:0e251e6860c0 | 27 | } |
tim010 | 0:0e251e6860c0 | 28 | } |