MMIA
Dependencies: MMA8451Q TSI USBDevice mbed
Revision 5:54110e05065c, committed 2016-10-06
- Comitter:
- OK2AMA
- Date:
- Thu Oct 06 11:49:07 2016 +0000
- Parent:
- 4:0f13346a8475
- Commit message:
- It working!
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA8451Q.lib Thu Oct 06 11:49:07 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TSI.lib Thu Oct 06 11:49:07 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/mbed/code/TSI/#1a60ef257879
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Thu Oct 06 11:49:07 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mbed_official/code/USBDevice/#01321bd6ff89
--- a/main.cpp Tue Feb 19 23:45:13 2013 +0000 +++ b/main.cpp Thu Oct 06 11:49:07 2016 +0000 @@ -1,15 +1,89 @@ #include "mbed.h" +#include "USBSerial.h" +#include "TSISensor.h" +#include "MMA8451Q.h" +#include <string> + +using namespace std; + +#define MMA8451_I2C_ADDRESS (0x1d<<1) + +USBSerial serial; +TSISensor tsi; + int main() { + MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); + + DigitalOut gpo(PTB8); - DigitalOut led(LED_RED); + DigitalOut led_r(LED_RED); + DigitalOut led_g(LED_GREEN); + DigitalOut led_b(LED_BLUE); + int x, y, z, sldr = 0; + + string str("**"); + while (true) { - gpo = 1; - led = 1; // Off - wait(2); - gpo = 0; - led = 0; // on - wait(2); + + while(1) + { + x = 1 - acc.getAccX() * 100; + y = 1 - acc.getAccY() * 100 ; + z = 1 - acc.getAccZ() * 100 ; + + sldr = ( tsi.readPercentage() ) *100; + + str = "**"; + + if( z > 50 ) + str = "+Z"; + if( z < -50 ) + str = "-Z"; + + if( x > 50 ) + str = "+X"; + if( x < -50 ) + str = "-X"; + + if( y > 50 ) + str = "+Y"; + if( y < -50 ) + str = "-Y"; + + serial.printf("X=%4d, Y=%4d, Z=%4d, osa=%s, slider=%3d%%\r\n", x, z, y, str, sldr); + wait(0.3); + + } + + + + led_r = 0; // Off + wait(1); + + led_r = 1; // Off + led_b = 1; // Off + led_g = 1; // Off + wait(1); + + led_g = 0; // Off + wait(1); + + led_r = 1; // Off + led_b = 1; // Off + led_g = 1; // Off + wait(1); + + led_b = 0; // Off + wait(1); + + led_r = 1; // Off + led_b = 1; // Off + led_g = 1; // Off + wait(1); + + + } } \ No newline at end of file