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@0:236e405a257c, 2016-01-27 (annotated)
- Committer:
- marcel1691
- Date:
- Wed Jan 27 16:37:46 2016 +0000
- Revision:
- 0:236e405a257c
- Child:
- 1:2f3874d539dd
Sehr, sehr einfacher Fitness Tracker unter Zuhilfename eines 3 Lagen Sensors
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 | 0:236e405a257c | 24 | SLCD slcd; |
| 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 | 0:236e405a257c | 32 | // I/O Buffer |
| marcel1691 | 0:236e405a257c | 33 | char buf[5]; |
| marcel1691 | 0:236e405a257c | 34 | |
| marcel1691 | 0:236e405a257c | 35 | int main(void) |
| marcel1691 | 0:236e405a257c | 36 | { |
| marcel1691 | 0:236e405a257c | 37 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
| marcel1691 | 0:236e405a257c | 38 | slcd.clear(); |
| marcel1691 | 0:236e405a257c | 39 | |
| marcel1691 | 0:236e405a257c | 40 | printf("MMA8451 ID: %d\n", acc.getWhoAmI()); |
| marcel1691 | 0:236e405a257c | 41 | |
| marcel1691 | 0:236e405a257c | 42 | while (true) |
| marcel1691 | 0:236e405a257c | 43 | { |
| marcel1691 | 0:236e405a257c | 44 | float x, y, z; |
| marcel1691 | 0:236e405a257c | 45 | x = acc.getAccX(); |
| marcel1691 | 0:236e405a257c | 46 | y = acc.getAccY(); |
| marcel1691 | 0:236e405a257c | 47 | z = acc.getAccZ(); |
| marcel1691 | 0:236e405a257c | 48 | wait( 0.2f ); |
| marcel1691 | 0:236e405a257c | 49 | printf( "X: %1.2f, Y: %1.2f, Z: %1.2f, step: %d\n", x, y, z, step ); |
| marcel1691 | 0:236e405a257c | 50 | |
| marcel1691 | 0:236e405a257c | 51 | if ( z > max && last < min ) |
| marcel1691 | 0:236e405a257c | 52 | step++; |
| marcel1691 | 0:236e405a257c | 53 | |
| marcel1691 | 0:236e405a257c | 54 | slcd.Home(); |
| marcel1691 | 0:236e405a257c | 55 | slcd.printf( "%4d", step ); |
| marcel1691 | 0:236e405a257c | 56 | last = z; |
| marcel1691 | 0:236e405a257c | 57 | } |
| marcel1691 | 0:236e405a257c | 58 | } |