MMIA

Dependencies:   MMA8451Q TSI USBDevice mbed

Committer:
OK2AMA
Date:
Thu Oct 06 11:49:07 2016 +0000
Revision:
5:54110e05065c
Parent:
2:f37d74a0e3e2
It working!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:0024ab6b9624 1 #include "mbed.h"
OK2AMA 5:54110e05065c 2 #include "USBSerial.h"
OK2AMA 5:54110e05065c 3 #include "TSISensor.h"
OK2AMA 5:54110e05065c 4 #include "MMA8451Q.h"
OK2AMA 5:54110e05065c 5 #include <string>
OK2AMA 5:54110e05065c 6
OK2AMA 5:54110e05065c 7 using namespace std;
OK2AMA 5:54110e05065c 8
OK2AMA 5:54110e05065c 9 #define MMA8451_I2C_ADDRESS (0x1d<<1)
OK2AMA 5:54110e05065c 10
OK2AMA 5:54110e05065c 11 USBSerial serial;
OK2AMA 5:54110e05065c 12 TSISensor tsi;
OK2AMA 5:54110e05065c 13
chris 0:0024ab6b9624 14
emilmont 1:4f62fc36c30d 15 int main() {
OK2AMA 5:54110e05065c 16 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
OK2AMA 5:54110e05065c 17
OK2AMA 5:54110e05065c 18
chris 0:0024ab6b9624 19 DigitalOut gpo(PTB8);
OK2AMA 5:54110e05065c 20 DigitalOut led_r(LED_RED);
OK2AMA 5:54110e05065c 21 DigitalOut led_g(LED_GREEN);
OK2AMA 5:54110e05065c 22 DigitalOut led_b(LED_BLUE);
OK2AMA 5:54110e05065c 23 int x, y, z, sldr = 0;
OK2AMA 5:54110e05065c 24
OK2AMA 5:54110e05065c 25 string str("**");
chris 0:0024ab6b9624 26
OK2AMA 5:54110e05065c 27
emilmont 2:f37d74a0e3e2 28 while (true) {
OK2AMA 5:54110e05065c 29
OK2AMA 5:54110e05065c 30 while(1)
OK2AMA 5:54110e05065c 31 {
OK2AMA 5:54110e05065c 32 x = 1 - acc.getAccX() * 100;
OK2AMA 5:54110e05065c 33 y = 1 - acc.getAccY() * 100 ;
OK2AMA 5:54110e05065c 34 z = 1 - acc.getAccZ() * 100 ;
OK2AMA 5:54110e05065c 35
OK2AMA 5:54110e05065c 36 sldr = ( tsi.readPercentage() ) *100;
OK2AMA 5:54110e05065c 37
OK2AMA 5:54110e05065c 38 str = "**";
OK2AMA 5:54110e05065c 39
OK2AMA 5:54110e05065c 40 if( z > 50 )
OK2AMA 5:54110e05065c 41 str = "+Z";
OK2AMA 5:54110e05065c 42 if( z < -50 )
OK2AMA 5:54110e05065c 43 str = "-Z";
OK2AMA 5:54110e05065c 44
OK2AMA 5:54110e05065c 45 if( x > 50 )
OK2AMA 5:54110e05065c 46 str = "+X";
OK2AMA 5:54110e05065c 47 if( x < -50 )
OK2AMA 5:54110e05065c 48 str = "-X";
OK2AMA 5:54110e05065c 49
OK2AMA 5:54110e05065c 50 if( y > 50 )
OK2AMA 5:54110e05065c 51 str = "+Y";
OK2AMA 5:54110e05065c 52 if( y < -50 )
OK2AMA 5:54110e05065c 53 str = "-Y";
OK2AMA 5:54110e05065c 54
OK2AMA 5:54110e05065c 55 serial.printf("X=%4d, Y=%4d, Z=%4d, osa=%s, slider=%3d%%\r\n", x, z, y, str, sldr);
OK2AMA 5:54110e05065c 56 wait(0.3);
OK2AMA 5:54110e05065c 57
OK2AMA 5:54110e05065c 58 }
OK2AMA 5:54110e05065c 59
OK2AMA 5:54110e05065c 60
OK2AMA 5:54110e05065c 61
OK2AMA 5:54110e05065c 62 led_r = 0; // Off
OK2AMA 5:54110e05065c 63 wait(1);
OK2AMA 5:54110e05065c 64
OK2AMA 5:54110e05065c 65 led_r = 1; // Off
OK2AMA 5:54110e05065c 66 led_b = 1; // Off
OK2AMA 5:54110e05065c 67 led_g = 1; // Off
OK2AMA 5:54110e05065c 68 wait(1);
OK2AMA 5:54110e05065c 69
OK2AMA 5:54110e05065c 70 led_g = 0; // Off
OK2AMA 5:54110e05065c 71 wait(1);
OK2AMA 5:54110e05065c 72
OK2AMA 5:54110e05065c 73 led_r = 1; // Off
OK2AMA 5:54110e05065c 74 led_b = 1; // Off
OK2AMA 5:54110e05065c 75 led_g = 1; // Off
OK2AMA 5:54110e05065c 76 wait(1);
OK2AMA 5:54110e05065c 77
OK2AMA 5:54110e05065c 78 led_b = 0; // Off
OK2AMA 5:54110e05065c 79 wait(1);
OK2AMA 5:54110e05065c 80
OK2AMA 5:54110e05065c 81 led_r = 1; // Off
OK2AMA 5:54110e05065c 82 led_b = 1; // Off
OK2AMA 5:54110e05065c 83 led_g = 1; // Off
OK2AMA 5:54110e05065c 84 wait(1);
OK2AMA 5:54110e05065c 85
OK2AMA 5:54110e05065c 86
OK2AMA 5:54110e05065c 87
chris 0:0024ab6b9624 88 }
chris 0:0024ab6b9624 89 }