Filip Maksimovic HW2 repository

Dependencies:   MMA8451Q TSI TextLCD USBDevice mbed tsi_sensor

Committer:
fil
Date:
Fri Sep 12 22:53:06 2014 +0000
Revision:
0:6ee2b447a1c5
Child:
1:e6873017e1d2
this little piece of shit works;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fil 0:6ee2b447a1c5 1 #include "mbed.h"
fil 0:6ee2b447a1c5 2 #include "MMA8451Q.h"
fil 0:6ee2b447a1c5 3 #include "TSISensor.h"
fil 0:6ee2b447a1c5 4 #include "USBKeyboard.h"
fil 0:6ee2b447a1c5 5 #define MMA8451_I2C_ADDRESS (0x1d<<1)
fil 0:6ee2b447a1c5 6
fil 0:6ee2b447a1c5 7 int main(void) {
fil 0:6ee2b447a1c5 8 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
fil 0:6ee2b447a1c5 9 TSISensor tsi;
fil 0:6ee2b447a1c5 10 PwmOut rled(LED_RED);
fil 0:6ee2b447a1c5 11 PwmOut gled(LED_GREEN);
fil 0:6ee2b447a1c5 12 PwmOut bled(LED_BLUE);
fil 0:6ee2b447a1c5 13 Serial pc(USBTX, USBRX);
fil 0:6ee2b447a1c5 14 USBKeyboard keyboard;
fil 0:6ee2b447a1c5 15
fil 0:6ee2b447a1c5 16 rled = 1.0; bled = 0.0; gled = 1.0;
fil 0:6ee2b447a1c5 17
fil 0:6ee2b447a1c5 18 // Begin the big fat fatty loop
fil 0:6ee2b447a1c5 19 while (1) {
fil 0:6ee2b447a1c5 20 gled = 1.0; bled = 0.0; rled = 1.0;
fil 0:6ee2b447a1c5 21
fil 0:6ee2b447a1c5 22 // Instantiate the touch 'buffer'
fil 0:6ee2b447a1c5 23 int x[2] = {0,0};
fil 0:6ee2b447a1c5 24
fil 0:6ee2b447a1c5 25 // Get touch pad sensor reading
fil 0:6ee2b447a1c5 26 int t = tsi.readDistance();
fil 0:6ee2b447a1c5 27
fil 0:6ee2b447a1c5 28 // Test if the touch pad is being groped
fil 0:6ee2b447a1c5 29 x[0] = tsi.readDistance();
fil 0:6ee2b447a1c5 30
fil 0:6ee2b447a1c5 31 while(t != 0) {
fil 0:6ee2b447a1c5 32 gled = 0.0;
fil 0:6ee2b447a1c5 33 x[1] = x[0];
fil 0:6ee2b447a1c5 34 x[0] = tsi.readDistance();
fil 0:6ee2b447a1c5 35 // test for a left swipe
fil 0:6ee2b447a1c5 36 if (x[0] > x[1] + 20) {
fil 0:6ee2b447a1c5 37 // i swiped right
fil 0:6ee2b447a1c5 38 // key = spacebar
fil 0:6ee2b447a1c5 39 bled = 0.0; rled = 1.0; gled = 1.0;
fil 0:6ee2b447a1c5 40 keyboard.keyCode(' ',0);
fil 0:6ee2b447a1c5 41 }
fil 0:6ee2b447a1c5 42 // from experience, x[1] is the actual output 'value' booya :)
fil 0:6ee2b447a1c5 43 x[1] = x[0]; x[0] = tsi.readDistance();
fil 0:6ee2b447a1c5 44
fil 0:6ee2b447a1c5 45 if (tsi.readDistance() == 0)
fil 0:6ee2b447a1c5 46 break; // get out of the fucking loop you piece of shit
fil 0:6ee2b447a1c5 47
fil 0:6ee2b447a1c5 48 // built-in loop delay
fil 0:6ee2b447a1c5 49 wait(0.1);
fil 0:6ee2b447a1c5 50 }
fil 0:6ee2b447a1c5 51
fil 0:6ee2b447a1c5 52 // now i get into the nitty gritty - how do i extract the keys themselves
fil 0:6ee2b447a1c5 53 wait(0.1);
fil 0:6ee2b447a1c5 54 }
fil 0:6ee2b447a1c5 55 }