Library to calculate movement and to draw the objects in the pong game

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed

Fork of MainSketch by IoT Ox

Revision:
9:eee503060d69
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Poll.h	Wed May 24 03:11:29 2017 +0000
@@ -0,0 +1,75 @@
+
+int readX()
+{
+    int delta=0,xv1=0,xv2=0,k=0;
+    int temp1=0,temp2=0;
+
+    AnalogIn yp(PTB3);
+    AnalogIn ym(PTB2);
+    DigitalOut xp(PTB0);
+    DigitalOut xm(PTB1);
+
+    xp=1; // set positive sdie of x high
+    xm=0;
+    // dont need to do anyhting to set low side as it should be fine.
+    // but do need to disconnect yp
+    //yp.PinMode(PullNone)
+    delta = 0;
+    for(k=0; k<10; k++) { // make 10 readings to average
+        temp1= (int)ym.read_u16();
+        temp2 = (int)yp.read_u16();
+        xv1+=temp1;  // get value
+        xv2+=temp2; // get other value
+        delta+= abs(temp1-temp2)/10; //gets individual differences
+       // pc.printf("val1 = %d - val2 = %d-diff = %d\n\r",temp1,temp2,temp1-temp2);
+        //observing behaviour when touching / nt touching
+        
+    }
+    //delta=abs(xv2-xv1)/10;
+    if(delta<300) touching=1;
+    else touching=0;
+    pc.printf("delta=%d \t %d\n\r",delta,touching);
+    xp=0;
+    xm=0;
+    return (240 - (240 * ((xv1 + xv2) / 2 / 10 - 5800)) / 51200); //returns the average of both
+    //return(xv2/10); //maybe better to return the average of both....
+}
+// subroutine to read y values - has different pin functions ..
+int readY()
+{
+    DigitalOut yp(PTB3);
+    DigitalOut ym(PTB2);
+    AnalogIn xp(PTB0);
+    AnalogIn xm(PTB1);
+    int delta=0,yv1=0,yv2=0,k=0;
+    int temp1=0,temp2=0;
+    yp=1; // set positive sdie of x high
+    ym=0;
+    // dont need to do anyhting to set low side as it should be fine.
+    // but do need to disconnect yp
+    //yp.PinMode(PullNone)
+    delta = 0;
+    for(k=0; k<10; k++) { // make 10 readings to average
+        temp1= (int)xm.read_u16();
+        temp2 = (int)xp.read_u16();
+        yv1+=temp1;  // get value
+        yv2+=temp2; // get other value
+        delta+= abs(temp1-temp2)/10;
+        //pc.printf("val1 = %d - val2 = %d-diff = %d\n\r",temp1,temp2,temp1-temp2);
+    }
+    //int yval=(int)xm.read_u16();  // get value
+    //pc.printf("yval=%d",yval);
+    yp=0;
+    ym=0;
+    return (320 - (320 * ((yv1 + yv2)/ 20 - 3000)) / 58300);   // returns Y
+//    return(yval);
+
+}
+
+
+
+void poll(){
+    int xp,yp = 0;
+    xp=readX();
+    yp=readY();
+}
\ No newline at end of file