Shape-Shifter_Controller_Joseph_Elena_Anupama

Dependencies:   DebounceIn MMA8451Q USBDevice mbed

Fork of HW3 by Joseph Marquis

Committer:
JMarquis
Date:
Sat Sep 19 00:21:38 2015 +0000
Revision:
1:716678407ac4
Parent:
0:a80df48a0372
Joey's edit 9/18;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Maskax 0:a80df48a0372 1 #include "mbed.h"
Maskax 0:a80df48a0372 2 //#include "PinDetect.h"
Maskax 0:a80df48a0372 3 #include "MMA8451Q.h"
Maskax 0:a80df48a0372 4 #include "USBKeyboard.h"
Maskax 0:a80df48a0372 5
Maskax 0:a80df48a0372 6 USBKeyboard key;
Maskax 0:a80df48a0372 7
Maskax 0:a80df48a0372 8 // define I2C Pins and address for KL25Z. Taken from default sample code.
Maskax 0:a80df48a0372 9 PinName const SDA = PTE25;
Maskax 0:a80df48a0372 10 PinName const SCL = PTE24;
JMarquis 1:716678407ac4 11 AnalogIn j(A0);
JMarquis 1:716678407ac4 12 AnalogIn n(A5);
JMarquis 1:716678407ac4 13 AnalogIn k(A2);
Maskax 0:a80df48a0372 14 //PinDetect P0(D2);
Maskax 0:a80df48a0372 15
Maskax 0:a80df48a0372 16 #define MMA8451_I2C_ADDRESS (0x1d<<1)
Maskax 0:a80df48a0372 17
Maskax 0:a80df48a0372 18 //serial connection to PC via USB
Maskax 0:a80df48a0372 19 //Serial pc(USBTX, USBRX);
Maskax 0:a80df48a0372 20
Maskax 0:a80df48a0372 21 int main(void)
Maskax 0:a80df48a0372 22 {
Maskax 0:a80df48a0372 23 //configure on-board I2C accelerometer on KL25Z
Maskax 0:a80df48a0372 24 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
Maskax 0:a80df48a0372 25 //map read acceleration to PWM output on red status LED
JMarquis 1:716678407ac4 26 float p;
JMarquis 1:716678407ac4 27 float q;
JMarquis 1:716678407ac4 28 float r;
JMarquis 1:716678407ac4 29
JMarquis 1:716678407ac4 30 state = 1;
Maskax 0:a80df48a0372 31 while (true) {
Maskax 0:a80df48a0372 32 float x, y, z;
Maskax 0:a80df48a0372 33 x = acc.getAccX();
Maskax 0:a80df48a0372 34 y = acc.getAccY();
Maskax 0:a80df48a0372 35 wait(0.05f);
JMarquis 1:716678407ac4 36 p= j.read();
JMarquis 1:716678407ac4 37 q= n.read();
JMarquis 1:716678407ac4 38 r= k.read();
JMarquis 1:716678407ac4 39
JMarquis 1:716678407ac4 40 if (p>.2) {
JMarquis 1:716678407ac4 41 if (q<.2){
JMarquis 1:716678407ac4 42 if(r<.2){
JMarquis 1:716678407ac4 43 key.keyCode('1',KEY_CTRL);
JMarquis 1:716678407ac4 44 }
JMarquis 1:716678407ac4 45 }
JMarquis 1:716678407ac4 46 if (q>.2){
JMarquis 1:716678407ac4 47 if (r<.2) {
JMarquis 1:716678407ac4 48 key.keyCode('2',KEY_CTRL);
JMarquis 1:716678407ac4 49 }
JMarquis 1:716678407ac4 50 if (r>.2) {
JMarquis 1:716678407ac4 51 key.keyCode('3',KEY_CTRL);
JMarquis 1:716678407ac4 52 }
JMarquis 1:716678407ac4 53 }
JMarquis 1:716678407ac4 54 }
JMarquis 1:716678407ac4 55
JMarquis 1:716678407ac4 56
JMarquis 1:716678407ac4 57
Maskax 0:a80df48a0372 58
Maskax 0:a80df48a0372 59 while (y<-0.2){
Maskax 0:a80df48a0372 60 key.keyCode(LEFT_ARROW);
Maskax 0:a80df48a0372 61 x = acc.getAccX();
Maskax 0:a80df48a0372 62 y = acc.getAccY();
Maskax 0:a80df48a0372 63 //key.printf("left arrow\n");
Maskax 0:a80df48a0372 64 if (x<-1.9)
Maskax 0:a80df48a0372 65 {
Maskax 0:a80df48a0372 66 // key.printf("Salto\n");
Maskax 0:a80df48a0372 67 key.keyCode(UP_ARROW);
Maskax 0:a80df48a0372 68 wait(0.3f);
Maskax 0:a80df48a0372 69 }
Maskax 0:a80df48a0372 70 }
Maskax 0:a80df48a0372 71 while (y>0.2){
Maskax 0:a80df48a0372 72 key.keyCode(RIGHT_ARROW);
Maskax 0:a80df48a0372 73 x = acc.getAccX();
Maskax 0:a80df48a0372 74 y = acc.getAccY();
Maskax 0:a80df48a0372 75 //key.printf("right arrow\n");
Maskax 0:a80df48a0372 76 if (x<-1.9)
Maskax 0:a80df48a0372 77 {
Maskax 0:a80df48a0372 78 // key.printf("Salto\n");
Maskax 0:a80df48a0372 79 key.keyCode(UP_ARROW);
Maskax 0:a80df48a0372 80 wait(0.3f);
Maskax 0:a80df48a0372 81 }
Maskax 0:a80df48a0372 82 }
Maskax 0:a80df48a0372 83 if (x<-1.9)
Maskax 0:a80df48a0372 84 {
Maskax 0:a80df48a0372 85 // key.printf("Salto\n");
Maskax 0:a80df48a0372 86 key.keyCode(UP_ARROW);
Maskax 0:a80df48a0372 87 x = acc.getAccX();
Maskax 0:a80df48a0372 88 wait(0.3f);
Maskax 0:a80df48a0372 89 }
Maskax 0:a80df48a0372 90 //wait(0.5);*/
Maskax 0:a80df48a0372 91 }
Maskax 0:a80df48a0372 92 }