Will Porter / Mbed 2 deprecated FinalProjectKeyboard

Dependencies:   USBDevice mbed

Fork of FinalProjectKeyboard by PecMan

Revision:
0:f23fd07d1d96
Child:
1:8546d208bd4f
diff -r 000000000000 -r f23fd07d1d96 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 27 01:38:09 2016 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "USBKeyboard.h"
+
+Serial pc(USBTX, USBRX);
+
+//AnalogIn inputx(PTB0); // AnalogIn inputx(PTB0);
+//AnalogIn inputy(PTB1); //AnalogIn inputy(PTB1);
+AnalogIn inputz(PTB2); //AnalogIn inputz(PTB2);
+
+//DigitalIn calibrate(PTD7);
+DigitalOut LED(LED1);
+
+int main() {
+LED=0;     
+pc.baud(9600);   // baud rate: 9600 bps interaction with computer
+
+wait(5);
+
+int z1=0; // variable for initialization
+z1 = inputz.read_u16();
+
+int z=0; // variable for z axes
+
+//************Eric Algorithm******************
+int status[]={0,0}; //0 means break,1 is up, 2 is down. status(0) is last, status(1) is current
+int L=1; // 0 = not outputting, =1 is ouputting
+//********************************************
+USBKeyboard keyboard;
+    while (true) {
+        
+         z = inputz.read_u16()-z1; //Calibration
+       
+        //if(calibrate){
+          //  pc.printf("Hey There\n\r");
+          // }
+        
+         //Establish Down
+         if (z<-1100) { 
+         status[0] = status[1];
+         status[1] = 1;
+         
+         if (L==1) {
+         //pc.printf("Up\n\r"); //Output Up
+         keyboard.keyCode(UP_ARROW);
+         L=0;}}
+         
+         //Establish Up
+         if(z>2500) {
+         status[0] = status[1];
+         status[1] = 2;
+         
+         if (L==1) {
+         //pc.printf("Down\n\r"); //Output Down
+         keyboard.keyCode(DOWN_ARROW);
+         L=0;}}
+         
+         //When not moving
+         if (z>-150 && z<150){
+         status[0] = status[1];
+         status[1] = 0;
+         
+         if (L==0) {
+         //keyboard.keyCode(' ');
+         //keyboard.printf("OK");
+         //pc.printf("Break\n\r"); //Just a Reference
+         L=1;}}
+         
+        wait_ms(50);
+        }
+}