Mynput: Game controller for Color Quest.
Dependencies: Adafruit_NeoPixel MMA8451Q PinDetect_KL25Z USBDevice mbed
Fork of idd_hw3 by
Diff: main.cpp
- Revision:
- 0:d307eb0be182
- Child:
- 1:1f45953fccf9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 15 01:15:13 2015 +0000 @@ -0,0 +1,53 @@ +#include "mbed.h" +#include "MMA8451Q.h" +#include "Timer.h" + +// define I2C Pins and address for KL25Z. Taken from default sample code. +PinName const SDA = PTE25; +PinName const SCL = PTE24; +Timer timer; +int timer_begin; +#define MMA8451_I2C_ADDRESS (0x1d<<1) + +#define leanLeftThresh -0.4 +#define leanRightThresh 0.4 +#define jumpThresh 0.4 + +//serial connection to PC via USB +Serial pc(USBTX, USBRX); +bool timerStart = false; + +int main(void) +{ + //configure on-board I2C accelerometer on KL25Z + MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); + //map read acceleration to PWM output on red status LED + PwmOut rled(LED_RED); + float x,y,z, x_new, y_new, z_new; + timer.start(); + timer_begin = timer.read_ms(); + while (true) { + x = acc.getAccX(); + y = acc.getAccY(); + z = acc.getAccZ(); + + wait(.2); //wait 0.2 ms + + x_new = acc.getAccX(); + y_new = acc.getAccY(); + z_new = acc.getAccZ(); + + if ( (y > leanRightThresh) && (y_new > leanRightThresh)) { + pc.printf("Lean right\n"); + } else if ((y < leanLeftThresh) && (y_new < leanLeftThresh)) { + pc.printf("Lean left\n"); + } + if( x < jumpThresh && timer.read_ms() - timer_begin > 300 ) { + timerStart = true; + pc.printf("Jump\n"); + timer_begin = timer.read_ms(); + } + + + } +} \ No newline at end of file