Boundary mods

Dependencies:   USBDevice mbed

Fork of FinalProjectKeyboard by PecMan

Committer:
pedromtz1000
Date:
Wed Apr 27 01:38:09 2016 +0000
Revision:
0:f23fd07d1d96
Child:
1:8546d208bd4f
Hey

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pedromtz1000 0:f23fd07d1d96 1 #include "mbed.h"
pedromtz1000 0:f23fd07d1d96 2 #include "USBKeyboard.h"
pedromtz1000 0:f23fd07d1d96 3
pedromtz1000 0:f23fd07d1d96 4 Serial pc(USBTX, USBRX);
pedromtz1000 0:f23fd07d1d96 5
pedromtz1000 0:f23fd07d1d96 6 //AnalogIn inputx(PTB0); // AnalogIn inputx(PTB0);
pedromtz1000 0:f23fd07d1d96 7 //AnalogIn inputy(PTB1); //AnalogIn inputy(PTB1);
pedromtz1000 0:f23fd07d1d96 8 AnalogIn inputz(PTB2); //AnalogIn inputz(PTB2);
pedromtz1000 0:f23fd07d1d96 9
pedromtz1000 0:f23fd07d1d96 10 //DigitalIn calibrate(PTD7);
pedromtz1000 0:f23fd07d1d96 11 DigitalOut LED(LED1);
pedromtz1000 0:f23fd07d1d96 12
pedromtz1000 0:f23fd07d1d96 13 int main() {
pedromtz1000 0:f23fd07d1d96 14 LED=0;
pedromtz1000 0:f23fd07d1d96 15 pc.baud(9600); // baud rate: 9600 bps interaction with computer
pedromtz1000 0:f23fd07d1d96 16
pedromtz1000 0:f23fd07d1d96 17 wait(5);
pedromtz1000 0:f23fd07d1d96 18
pedromtz1000 0:f23fd07d1d96 19 int z1=0; // variable for initialization
pedromtz1000 0:f23fd07d1d96 20 z1 = inputz.read_u16();
pedromtz1000 0:f23fd07d1d96 21
pedromtz1000 0:f23fd07d1d96 22 int z=0; // variable for z axes
pedromtz1000 0:f23fd07d1d96 23
pedromtz1000 0:f23fd07d1d96 24 //************Eric Algorithm******************
pedromtz1000 0:f23fd07d1d96 25 int status[]={0,0}; //0 means break,1 is up, 2 is down. status(0) is last, status(1) is current
pedromtz1000 0:f23fd07d1d96 26 int L=1; // 0 = not outputting, =1 is ouputting
pedromtz1000 0:f23fd07d1d96 27 //********************************************
pedromtz1000 0:f23fd07d1d96 28 USBKeyboard keyboard;
pedromtz1000 0:f23fd07d1d96 29 while (true) {
pedromtz1000 0:f23fd07d1d96 30
pedromtz1000 0:f23fd07d1d96 31 z = inputz.read_u16()-z1; //Calibration
pedromtz1000 0:f23fd07d1d96 32
pedromtz1000 0:f23fd07d1d96 33 //if(calibrate){
pedromtz1000 0:f23fd07d1d96 34 // pc.printf("Hey There\n\r");
pedromtz1000 0:f23fd07d1d96 35 // }
pedromtz1000 0:f23fd07d1d96 36
pedromtz1000 0:f23fd07d1d96 37 //Establish Down
pedromtz1000 0:f23fd07d1d96 38 if (z<-1100) {
pedromtz1000 0:f23fd07d1d96 39 status[0] = status[1];
pedromtz1000 0:f23fd07d1d96 40 status[1] = 1;
pedromtz1000 0:f23fd07d1d96 41
pedromtz1000 0:f23fd07d1d96 42 if (L==1) {
pedromtz1000 0:f23fd07d1d96 43 //pc.printf("Up\n\r"); //Output Up
pedromtz1000 0:f23fd07d1d96 44 keyboard.keyCode(UP_ARROW);
pedromtz1000 0:f23fd07d1d96 45 L=0;}}
pedromtz1000 0:f23fd07d1d96 46
pedromtz1000 0:f23fd07d1d96 47 //Establish Up
pedromtz1000 0:f23fd07d1d96 48 if(z>2500) {
pedromtz1000 0:f23fd07d1d96 49 status[0] = status[1];
pedromtz1000 0:f23fd07d1d96 50 status[1] = 2;
pedromtz1000 0:f23fd07d1d96 51
pedromtz1000 0:f23fd07d1d96 52 if (L==1) {
pedromtz1000 0:f23fd07d1d96 53 //pc.printf("Down\n\r"); //Output Down
pedromtz1000 0:f23fd07d1d96 54 keyboard.keyCode(DOWN_ARROW);
pedromtz1000 0:f23fd07d1d96 55 L=0;}}
pedromtz1000 0:f23fd07d1d96 56
pedromtz1000 0:f23fd07d1d96 57 //When not moving
pedromtz1000 0:f23fd07d1d96 58 if (z>-150 && z<150){
pedromtz1000 0:f23fd07d1d96 59 status[0] = status[1];
pedromtz1000 0:f23fd07d1d96 60 status[1] = 0;
pedromtz1000 0:f23fd07d1d96 61
pedromtz1000 0:f23fd07d1d96 62 if (L==0) {
pedromtz1000 0:f23fd07d1d96 63 //keyboard.keyCode(' ');
pedromtz1000 0:f23fd07d1d96 64 //keyboard.printf("OK");
pedromtz1000 0:f23fd07d1d96 65 //pc.printf("Break\n\r"); //Just a Reference
pedromtz1000 0:f23fd07d1d96 66 L=1;}}
pedromtz1000 0:f23fd07d1d96 67
pedromtz1000 0:f23fd07d1d96 68 wait_ms(50);
pedromtz1000 0:f23fd07d1d96 69 }
pedromtz1000 0:f23fd07d1d96 70 }