Filip Maksimovic HW2 repository
Dependencies: MMA8451Q TSI TextLCD USBDevice mbed tsi_sensor
Diff: main.cpp
- Revision:
- 0:6ee2b447a1c5
- Child:
- 1:e6873017e1d2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Sep 12 22:53:06 2014 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "MMA8451Q.h" +#include "TSISensor.h" +#include "USBKeyboard.h" +#define MMA8451_I2C_ADDRESS (0x1d<<1) + +int main(void) { + MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); + TSISensor tsi; + PwmOut rled(LED_RED); + PwmOut gled(LED_GREEN); + PwmOut bled(LED_BLUE); + Serial pc(USBTX, USBRX); + USBKeyboard keyboard; + + rled = 1.0; bled = 0.0; gled = 1.0; + + // Begin the big fat fatty loop + while (1) { + gled = 1.0; bled = 0.0; rled = 1.0; + + // Instantiate the touch 'buffer' + int x[2] = {0,0}; + + // Get touch pad sensor reading + int t = tsi.readDistance(); + + // Test if the touch pad is being groped + x[0] = tsi.readDistance(); + + while(t != 0) { + gled = 0.0; + x[1] = x[0]; + x[0] = tsi.readDistance(); + // test for a left swipe + if (x[0] > x[1] + 20) { + // i swiped right + // key = spacebar + bled = 0.0; rled = 1.0; gled = 1.0; + keyboard.keyCode(' ',0); + } + // from experience, x[1] is the actual output 'value' booya :) + x[1] = x[0]; x[0] = tsi.readDistance(); + + if (tsi.readDistance() == 0) + break; // get out of the fucking loop you piece of shit + + // built-in loop delay + wait(0.1); + } + + // now i get into the nitty gritty - how do i extract the keys themselves + wait(0.1); + } +} \ No newline at end of file