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: mbed tsi_sensor MMA8451Q
Revision 10:8ef196baf733, committed 2019-01-08
- Comitter:
- diaady
- Date:
- Tue Jan 08 14:01:52 2019 +0000
- Parent:
- 9:d4bffe27a7bf
- Commit message:
- filter acc , print on separate lines; add slider
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
tsi_sensor.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Jul 16 10:30:54 2014 +0000 +++ b/main.cpp Tue Jan 08 14:01:52 2019 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "MMA8451Q.h" +#include "tsi_sensor.h" #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) PinName const SDA = PTE25; @@ -14,11 +15,27 @@ #error TARGET NOT DEFINED #endif + + #define MMA8451_I2C_ADDRESS (0x1d<<1) + + +/* This defines will be replaced by PinNames soon */ +#if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) + #define ELEC0 9 + #define ELEC1 10 +#elif defined (TARGET_KL05Z) + #define ELEC0 9 + #define ELEC1 8 +#else + #error TARGET NOT DEFINED +#endif + int main(void) { MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); + TSIAnalogSlider tsi(ELEC0, ELEC1, 40); PwmOut rled(LED1); PwmOut gled(LED2); PwmOut bled(LED3); @@ -26,14 +43,20 @@ printf("MMA8451 ID: %d\n", acc.getWhoAmI()); while (true) { - float x, y, z; + float x, y, z, slide; x = abs(acc.getAccX()); y = abs(acc.getAccY()); z = abs(acc.getAccZ()); + slide = tsi.readPercentage(); rled = 1.0f - x; gled = 1.0f - y; bled = 1.0f - z; wait(0.1f); - printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z); + if(x > 0.1f) {printf("X: %1.2f\n",x);} + if(y > 0.1f) {printf("Y: %1.2f\n ",y);} + if(z > 0.1f) {printf("Z: %1.2f\n",z);} + if(slide > 0) {printf("Slide: %1.2f\n",slide);} + + //printf("X: %1.2f, Y: %1.2f, Z: %1.2f Slider: %1.2f\n", x, y, z,tsi.readPercentage()); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tsi_sensor.lib Tue Jan 08 14:01:52 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Kojto/code/tsi_sensor/#20ffa9b18488