IoT Ox / Mbed 2 deprecated MainSketch Featured

Dependencies:   RTC-DS1307 SPI_TFT_ILI9341 TFT_fonts mbed tsi_sensor

Fork of TFT_Mikroelectronika_IL9341_sketchpad by Oxford CWM Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers poll.h Source File

poll.h

00001 #include "stdio.h"
00002 #define PinXm A1
00003 #define PinXp A0
00004 #define PinYm A3
00005 #define PinYp A2
00006 
00007 #include "SPI_TFT_ILI9341.h"
00008 
00009 
00010 
00011 
00012 
00013 
00014 // example to test the TFT Display from Mikroelectronika
00015 
00016 
00017 
00018 // the display has a backlight switch on board
00019 //DigitalOut LCD_LED(PTA4);   // may not be needed on mikroelectronika board
00020 //DigitalOut pwr(PTD7); // ditto
00021 
00022 // the TFT is connected to SPI pin 5-7
00023 //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc for lpc1768
00024 SPI_TFT_ILI9341 TFT(PTA16, PTA17, PTA15, PTD2, PTD4, PTA13, "TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
00025 //NB better combination to use a coherent 2x4 block for lcd
00026 //   SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTA16, PTA17, PTC16,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
00027 //   DigitalOut LCD_LED(PTC17);
00028 int touching = 0;
00029 
00030 // Subroutine to read the x location of the touch point
00031 // need to set x+ to 3V and ground x- then read analogue voltage on ym
00032 //nb need to add a check for actual touch as opposed to random crap
00033 
00034 
00035 
00036 
00037 
00038 int readY()
00039 {
00040     int delta = 0, xv1 = 0, xv2 = 0, k = 0;
00041     int temp1 = 0, temp2 = 0;
00042 
00043     AnalogIn yp(PinYp);
00044     AnalogIn ym(PinYm);
00045     DigitalOut xp(PinXp);
00046     DigitalOut xm(PinXm);
00047 
00048     xp = 1; // set positive side of x high
00049     xm = 0;
00050     // dont need to do anyhting to set low side as it should be fine.
00051     // but do need to disconnect yp
00052     //yp.PinMode(PullNone)
00053     delta = 0;
00054     for(k = 0; k < 10; k++) { // make 10 readings to average
00055         temp1 = (int)ym.read_u16();
00056         temp2 = (int)yp.read_u16();
00057         xv1 += temp1;  // get value
00058         xv2 += temp2; // get other value
00059         delta += abs(temp1 - temp2) / 10; //gets individual differences
00060         // pc.printf("val1 = %d - val2 = %d-diff = %d\n\r",temp1,temp2,temp1-temp2);
00061         //observing behaviour when touching / nt touching
00062 
00063     }
00064     //delta=abs(xv2-xv1)/10;
00065     if(delta < 300) touching = 1;
00066     else touching = 0;
00067     //pc.printf("delta=%d \t %d\n\r",delta,touching);
00068     xp = 0;
00069     xm = 0;
00070     return (240 - (240 * ((xv2) / 1 / 10 - 5800)) / 51200); //returns the average of both
00071     //return(xv2/10); //maybe better to return the average of both....
00072 }
00073 // subroutine to read y values - has different pin functions ..
00074 int readX()
00075 {
00076     DigitalOut yp(PinYp);
00077     DigitalOut ym(PinYm);
00078     AnalogIn xp(PinXp);
00079     AnalogIn xm(PinXm);
00080     int delta = 0, yv1 = 0, yv2 = 0, k = 0;
00081     int temp1 = 0, temp2 = 0;
00082     yp = 1; // set positive sdie of x high
00083     ym = 0;
00084     // dont need to do anyhting to set low side as it should be fine.
00085     // but do need to disconnect yp
00086     //yp.PinMode(PullNone)
00087     delta = 0;
00088     for(k = 0; k < 10; k++) { // make 10 readings to average
00089         temp1 = (int)xm.read_u16();
00090         temp2 = (int)xp.read_u16();
00091         yv1 += temp1;  // get value
00092         yv2 += temp2; // get other value
00093         delta += abs(temp1 - temp2) / 10;
00094         //pc.printf("val1 = %d - val2 = %d-diff = %d\n\r",temp1,temp2,temp1-temp2);
00095     }
00096     //int yval=(int)xm.read_u16();  // get value
00097     //pc.printf("yval=%d",yval);
00098     yp = 0;
00099     ym = 0;
00100     return ((320 * ((yv2) / 1 / 10 - 3000)) / 58300);   // returns X
00101 //    return(yval);
00102 
00103 }
00104 
00105 
00106