with Starboard Orange
Freescale MMA7660FC accelometer with Startboard Orange.
Please visit http://bird.dip.jp/mt/archives/2012/05/31/2240.html
Diff: main.cpp
- Revision:
- 0:8ab239852e4b
- Child:
- 1:dc5d150d4fa6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri May 25 01:28:05 2012 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" + +I2C i2c(p9, p10); // sda, scl +DigitalIn orientationInt(p5); +Serial pc(USBTX, USBRX); // tx, rx + +// define the I2C register address +const int XOUT = 0x00; +const int YOUT = 0x01; +const int ZOUT = 0x02; +const int TILS = 0x03; +const int SRST = 0x04; +const int SPCNT = 0x05; +const int INTSU = 0x06; +const int MODE = 0x07; +const int SR = 0x08; +const int PDET = 0x09; +const int PD = 0x0A; + +void configMMA7760() { + char cmd[2]; + + cmd[0] = 0x00; i2c.write(MODE, cmd, 1); // Standby Mode + cmd[0] = 0x00; i2c.write(SPCNT, cmd, 1); // No sleep count + cmd[0] = 0x03; i2c.write(INTSU, cmd, 1); // Configure GINT Interrupt + cmd[0] = 0xE0; i2c.write(PDET, cmd, 1); // No tap detection enabled + cmd[0] = 0x34; i2c.write(SR, cmd, 1); // 8 samples/s, TILT debounce filter = 2 + cmd[0] = 0x00; i2c.write(PD, cmd, 1); // No tap detection debounce count enabled + cmd[0] = 0x41; i2c.write(MODE, cmd, 1); // Active Mode, INT = push-pull and active low +} + +int main() { + char cmd[2]; + + configureMMA7760(); + while (1) { + if (!orientationInt) { + continue; + wait(0.1); + } + + i2c.read(TILT, cmd, 1); + int PoLa = (cmd[0] >> 2) & 0x07; + int BaFro = cmd[0] & 0x03; + + switch (PoLa) { + case 1: pc.printf("Left\n"); + case 2: pc.printf("Right\n"); + case 5: pc.printf("Down\n"); + case 6: pc.printf("Up\n"); + } + + switch (BaFro) { + case 1: pc.printf("Front\n"); + case 2: pc.printf("Back\n"); + } + wait(0.1); + } +} \ No newline at end of file