Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q SLCD mbed
main.cpp@1:2f3874d539dd, 2016-01-27 (annotated)
- Committer:
- marcel1691
- Date:
- Wed Jan 27 16:46:05 2016 +0000
- Revision:
- 1:2f3874d539dd
- Parent:
- 0:236e405a257c
Code gesaeubert
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcel1691 | 0:236e405a257c | 1 | /** KL64Z Fitness Tracker |
marcel1691 | 0:236e405a257c | 2 | * Sehr, sehr einfacher Fitness Tracker unter Zuhilfename eines 3 Lagen Sensors |
marcel1691 | 0:236e405a257c | 3 | */ |
marcel1691 | 0:236e405a257c | 4 | #include "mbed.h" |
marcel1691 | 0:236e405a257c | 5 | #include "MMA8451Q.h" |
marcel1691 | 0:236e405a257c | 6 | #include "SLCD.h" |
marcel1691 | 0:236e405a257c | 7 | |
marcel1691 | 0:236e405a257c | 8 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
marcel1691 | 0:236e405a257c | 9 | PinName const SDA = PTE25; |
marcel1691 | 0:236e405a257c | 10 | PinName const SCL = PTE24; |
marcel1691 | 0:236e405a257c | 11 | #elif defined (TARGET_KL05Z) |
marcel1691 | 0:236e405a257c | 12 | PinName const SDA = PTB4; |
marcel1691 | 0:236e405a257c | 13 | PinName const SCL = PTB3; |
marcel1691 | 0:236e405a257c | 14 | #elif defined (TARGET_K20D50M) |
marcel1691 | 0:236e405a257c | 15 | PinName const SDA = PTB1; |
marcel1691 | 0:236e405a257c | 16 | PinName const SCL = PTB0; |
marcel1691 | 0:236e405a257c | 17 | #else |
marcel1691 | 0:236e405a257c | 18 | #error TARGET NOT DEFINED |
marcel1691 | 0:236e405a257c | 19 | #endif |
marcel1691 | 0:236e405a257c | 20 | |
marcel1691 | 0:236e405a257c | 21 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
marcel1691 | 0:236e405a257c | 22 | |
marcel1691 | 0:236e405a257c | 23 | // Display |
marcel1691 | 1:2f3874d539dd | 24 | SLCD lcd; |
marcel1691 | 0:236e405a257c | 25 | // Anzahl Schritte |
marcel1691 | 0:236e405a257c | 26 | long step = 0; |
marcel1691 | 0:236e405a257c | 27 | // letzte Z Lage |
marcel1691 | 0:236e405a257c | 28 | float last; |
marcel1691 | 0:236e405a257c | 29 | // Schwellenwerte |
marcel1691 | 0:236e405a257c | 30 | float min = -0.2; |
marcel1691 | 0:236e405a257c | 31 | float max = 0.2; |
marcel1691 | 1:2f3874d539dd | 32 | |
marcel1691 | 0:236e405a257c | 33 | |
marcel1691 | 0:236e405a257c | 34 | int main(void) |
marcel1691 | 0:236e405a257c | 35 | { |
marcel1691 | 0:236e405a257c | 36 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
marcel1691 | 1:2f3874d539dd | 37 | lcd.clear(); |
marcel1691 | 0:236e405a257c | 38 | |
marcel1691 | 0:236e405a257c | 39 | printf("MMA8451 ID: %d\n", acc.getWhoAmI()); |
marcel1691 | 0:236e405a257c | 40 | |
marcel1691 | 0:236e405a257c | 41 | while (true) |
marcel1691 | 0:236e405a257c | 42 | { |
marcel1691 | 0:236e405a257c | 43 | float x, y, z; |
marcel1691 | 0:236e405a257c | 44 | x = acc.getAccX(); |
marcel1691 | 0:236e405a257c | 45 | y = acc.getAccY(); |
marcel1691 | 0:236e405a257c | 46 | z = acc.getAccZ(); |
marcel1691 | 0:236e405a257c | 47 | wait( 0.2f ); |
marcel1691 | 0:236e405a257c | 48 | printf( "X: %1.2f, Y: %1.2f, Z: %1.2f, step: %d\n", x, y, z, step ); |
marcel1691 | 0:236e405a257c | 49 | |
marcel1691 | 0:236e405a257c | 50 | if ( z > max && last < min ) |
marcel1691 | 0:236e405a257c | 51 | step++; |
marcel1691 | 0:236e405a257c | 52 | |
marcel1691 | 1:2f3874d539dd | 53 | lcd.Home(); |
marcel1691 | 1:2f3874d539dd | 54 | lcd.printf( "%4d", step ); |
marcel1691 | 0:236e405a257c | 55 | last = z; |
marcel1691 | 0:236e405a257c | 56 | } |
marcel1691 | 0:236e405a257c | 57 | } |