pong game added to the main sketch

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor

Fork of MainSketch by IoT Ox

Files at this revision

API Documentation at this revision

Comitter:
mlin
Date:
Tue May 23 23:04:03 2017 +0000
Parent:
7:c2bc477a07da
Child:
9:eee503060d69
Commit message:
changed the way the the X and Y position are polled and adjusted

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Jun 15 09:00:27 2016 +0000
+++ b/main.cpp	Tue May 23 23:04:03 2017 +0000
@@ -9,19 +9,19 @@
 #include "Arial28x28.h"
 #include "font_big.h"
 
-
-Serial pc (USBTX,USBRX);
+DigitalIn sw_w(SW3);
+Serial pc(USBTX,USBRX,"pc");
 
 
 
 
 // the display has a backlight switch on board
-DigitalOut LCD_LED(PTA13);   // may not be needed on mikroelectronika board
-DigitalOut pwr(PTD7); // ditto
+//DigitalOut LCD_LED(PTA4);   // may not be needed on mikroelectronika board
+//DigitalOut pwr(PTD7); // ditto
 
 // the TFT is connected to SPI pin 5-7
 //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc for lpc1768
-SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
+SPI_TFT_ILI9341 TFT(PTD6, PTD7, PTD5, PTD2, PTD4, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
 //NB better combination to use a coherent 2x4 block for lcd
 //   SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTA16, PTA17, PTC16,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
 //   DigitalOut LCD_LED(PTC17);
@@ -33,6 +33,7 @@
 int readX()
 {
     int delta=0,xv1=0,xv2=0,k=0;
+    int temp1=0,temp2=0;
 
     AnalogIn yp(PTB3);
     AnalogIn ym(PTB2);
@@ -44,11 +45,16 @@
     // 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
-        xv1+=(int)ym.read_u16();  // get value
-        xv2+=(int)yp.read_u16(); // get other value
+        temp1= (int)ym.read_u16();
+        temp2 = (int)yp.read_u16();
+        xv1+=temp1;  // get value
+        xv2+=temp2; // get other value
+        delta+= abs(temp1-temp2)/10;
+        pc.printf("val1 = %d - val2 = %d-diff = %d\n\r",temp1,temp2,temp1-temp2);
     }
-    delta=abs(xv2-xv1)/10;
+    //delta=abs(xv2-xv1)/10;
     if(delta<300) touching=1;
     else touching=0;
     pc.printf("delta=%d \t %d\n\r",delta,touching);
@@ -70,7 +76,7 @@
     // but do need to disconnect yp
     //yp.PinMode(PullNone)
     int yval=(int)xm.read_u16();  // get value
-
+    pc.printf("yval=%d",yval);
     yp=0;
     ym=0;
     return(yval);
@@ -96,14 +102,14 @@
 
 int main()
 {
-    pc.baud(115200);
+   // pc.baud(115200);
     int color=0;
     int xpos=0,ypos=0,xp=0,yp=0,sw=0;;
-    pwr=1;
+    //pwr=1;
     wait(0.2);
 
     int i;
-    LCD_LED = 1;            // backlight on
+    //LCD_LED = 1;            // backlight on
 
     TFT.claim(stdout);        // send stdout to the TFT display
     TFT.set_orientation(1);
@@ -143,13 +149,13 @@
     TFT.cls();
     //   LCD_LED = 1;
     //cornwer markers
-    //TFT.fillcircle(10,10,5,0xffff);
-    //TFT.fillcircle(230,10,5,0xffff);
-    //TFT.fillcircle(230,310,5,0xffff);
-    //TFT.fillcircle(10,310,5,0xffff);
+    TFT.fillcircle(10,10,5,0xffff);
+    TFT.fillcircle(230,10,5,0xffff);
+    TFT.fillcircle(230,310,5,0xffff);
+    TFT.fillcircle(10,310,5,0xffff);
     drawbuttons();
     while(1==1) {
-
+        while (sw_w == 1) {}
         xpos=readX();
         ypos=readY();
         // top chunk of the screen is the button area //
@@ -186,7 +192,7 @@
             // if(xp>100 && xp<150) color=0x001f;
         }
 
-        wait(0.1);
+        wait(1);
 
     }