Submitted by Angela Hsueh, Maya Mardini, Yi Tong Slingshot controller using a force sensor and accelerometer for an Angry Birds clone game.

Dependencies:   LSM303DLHC MMA8451Q PinDetect USBDevice mbed

Fork of hw3_controller by HW3 Controller Team!

Committer:
ahsueh
Date:
Fri Sep 18 21:02:14 2015 +0000
Revision:
1:01b4684bc210
Parent:
0:c9bb3c9d5ce8
Child:
2:31cf09b1ad9c
Initial Revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ahsueh 1:01b4684bc210 1
bjo3rn 0:c9bb3c9d5ce8 2 #include "mbed.h"
ahsueh 1:01b4684bc210 3 //#include "MMA8451Q.h"
ahsueh 1:01b4684bc210 4 //#include "USBMouse.h"
ahsueh 1:01b4684bc210 5 #include "LSM303DLHC.h"
bjo3rn 0:c9bb3c9d5ce8 6
bjo3rn 0:c9bb3c9d5ce8 7 // define I2C Pins and address for KL25Z. Taken from default sample code.
ahsueh 1:01b4684bc210 8 PinName const SDA = D14;
ahsueh 1:01b4684bc210 9 PinName const SCL = D15;
bjo3rn 0:c9bb3c9d5ce8 10 #define MMA8451_I2C_ADDRESS (0x1d<<1)
bjo3rn 0:c9bb3c9d5ce8 11
bjo3rn 0:c9bb3c9d5ce8 12 //serial connection to PC via USB
bjo3rn 0:c9bb3c9d5ce8 13 Serial pc(USBTX, USBRX);
ahsueh 1:01b4684bc210 14 LSM303DLHC lsm(SDA, SCL);
ahsueh 1:01b4684bc210 15 //USBMouse mouse;
ahsueh 1:01b4684bc210 16
ahsueh 1:01b4684bc210 17 // acc and mag values
ahsueh 1:01b4684bc210 18 float ax, ay, az;
ahsueh 1:01b4684bc210 19 float mx, my, mz;
ahsueh 1:01b4684bc210 20
bjo3rn 0:c9bb3c9d5ce8 21
bjo3rn 0:c9bb3c9d5ce8 22 int main(void)
bjo3rn 0:c9bb3c9d5ce8 23 {
ahsueh 1:01b4684bc210 24 pc.printf("Hello\n");
bjo3rn 0:c9bb3c9d5ce8 25
ahsueh 1:01b4684bc210 26 //configure on-board I2C accelerometer on KL25Z
ahsueh 1:01b4684bc210 27 //MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
bjo3rn 0:c9bb3c9d5ce8 28
ahsueh 1:01b4684bc210 29 while (true) {
ahsueh 1:01b4684bc210 30 lsm.read(&ax, &ay, &az, &mx, &my, &mz); //get acceleration
ahsueh 1:01b4684bc210 31 pc.printf("acc %1.2f %1.2f %1.2f\n", ax, ay, az); //print ascii-encoded float to serial port
ahsueh 1:01b4684bc210 32 pc.printf("mag %1.2f %1.2f %1.2f\n", mx, my, mz); //print ascii-encoded float to serial port
ahsueh 1:01b4684bc210 33 wait(0.05f); // wait 50ms (20Hz update rate)
ahsueh 1:01b4684bc210 34 }
bjo3rn 0:c9bb3c9d5ce8 35 }