with Starboard Orange

Dependencies:   TextLCD mbed

Freescale MMA7660FC accelometer with Startboard Orange.
Please visit http://bird.dip.jp/mt/archives/2012/05/31/2240.html

/media/uploads/masato/mma7660fc.jpg

Committer:
masato
Date:
Fri May 25 01:28:05 2012 +0000
Revision:
0:8ab239852e4b
Child:
1:dc5d150d4fa6
initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
masato 0:8ab239852e4b 1 #include "mbed.h"
masato 0:8ab239852e4b 2
masato 0:8ab239852e4b 3 I2C i2c(p9, p10); // sda, scl
masato 0:8ab239852e4b 4 DigitalIn orientationInt(p5);
masato 0:8ab239852e4b 5 Serial pc(USBTX, USBRX); // tx, rx
masato 0:8ab239852e4b 6
masato 0:8ab239852e4b 7 // define the I2C register address
masato 0:8ab239852e4b 8 const int XOUT = 0x00;
masato 0:8ab239852e4b 9 const int YOUT = 0x01;
masato 0:8ab239852e4b 10 const int ZOUT = 0x02;
masato 0:8ab239852e4b 11 const int TILS = 0x03;
masato 0:8ab239852e4b 12 const int SRST = 0x04;
masato 0:8ab239852e4b 13 const int SPCNT = 0x05;
masato 0:8ab239852e4b 14 const int INTSU = 0x06;
masato 0:8ab239852e4b 15 const int MODE = 0x07;
masato 0:8ab239852e4b 16 const int SR = 0x08;
masato 0:8ab239852e4b 17 const int PDET = 0x09;
masato 0:8ab239852e4b 18 const int PD = 0x0A;
masato 0:8ab239852e4b 19
masato 0:8ab239852e4b 20 void configMMA7760() {
masato 0:8ab239852e4b 21 char cmd[2];
masato 0:8ab239852e4b 22
masato 0:8ab239852e4b 23 cmd[0] = 0x00; i2c.write(MODE, cmd, 1); // Standby Mode
masato 0:8ab239852e4b 24 cmd[0] = 0x00; i2c.write(SPCNT, cmd, 1); // No sleep count
masato 0:8ab239852e4b 25 cmd[0] = 0x03; i2c.write(INTSU, cmd, 1); // Configure GINT Interrupt
masato 0:8ab239852e4b 26 cmd[0] = 0xE0; i2c.write(PDET, cmd, 1); // No tap detection enabled
masato 0:8ab239852e4b 27 cmd[0] = 0x34; i2c.write(SR, cmd, 1); // 8 samples/s, TILT debounce filter = 2
masato 0:8ab239852e4b 28 cmd[0] = 0x00; i2c.write(PD, cmd, 1); // No tap detection debounce count enabled
masato 0:8ab239852e4b 29 cmd[0] = 0x41; i2c.write(MODE, cmd, 1); // Active Mode, INT = push-pull and active low
masato 0:8ab239852e4b 30 }
masato 0:8ab239852e4b 31
masato 0:8ab239852e4b 32 int main() {
masato 0:8ab239852e4b 33 char cmd[2];
masato 0:8ab239852e4b 34
masato 0:8ab239852e4b 35 configureMMA7760();
masato 0:8ab239852e4b 36 while (1) {
masato 0:8ab239852e4b 37 if (!orientationInt) {
masato 0:8ab239852e4b 38 continue;
masato 0:8ab239852e4b 39 wait(0.1);
masato 0:8ab239852e4b 40 }
masato 0:8ab239852e4b 41
masato 0:8ab239852e4b 42 i2c.read(TILT, cmd, 1);
masato 0:8ab239852e4b 43 int PoLa = (cmd[0] >> 2) & 0x07;
masato 0:8ab239852e4b 44 int BaFro = cmd[0] & 0x03;
masato 0:8ab239852e4b 45
masato 0:8ab239852e4b 46 switch (PoLa) {
masato 0:8ab239852e4b 47 case 1: pc.printf("Left\n");
masato 0:8ab239852e4b 48 case 2: pc.printf("Right\n");
masato 0:8ab239852e4b 49 case 5: pc.printf("Down\n");
masato 0:8ab239852e4b 50 case 6: pc.printf("Up\n");
masato 0:8ab239852e4b 51 }
masato 0:8ab239852e4b 52
masato 0:8ab239852e4b 53 switch (BaFro) {
masato 0:8ab239852e4b 54 case 1: pc.printf("Front\n");
masato 0:8ab239852e4b 55 case 2: pc.printf("Back\n");
masato 0:8ab239852e4b 56 }
masato 0:8ab239852e4b 57 wait(0.1);
masato 0:8ab239852e4b 58 }
masato 0:8ab239852e4b 59 }