![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Test code for the touch display, should output the number 12.
Dependencies: SPI_TFT_ILI9341 TFT_fonts mbed
Fork of TFT_Mikroelectronika_IL9341_sketchpad by
main.cpp
- Committer:
- JHutchinson
- Date:
- 2017-05-24
- Revision:
- 9:6b60556b4cdf
- Parent:
- 8:3ae0674601ec
- Child:
- 10:0352f75f87c1
File content as of revision 9:6b60556b4cdf:
// example to test the TFT Display from Mikroelectronika #include "stdio.h" #include "mbed.h" #include "SPI_TFT_ILI9341.h" #include "string" #include "Arial12x12.h" #include "Arial24x23.h" #include "Arial28x28.h" #include "font_big.h" Serial pc (USBTX,USBRX); // the display has a backlight switch on board DigitalOut LCD_LED(PTA13); // 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 //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); int touching=0; // Subroutine to read the x location of the touch point // need to set x+ to 3V and ground x- then read analogue voltage on ym //nb need to add a check for actual touch as opposed to random crap int readX() { int delta=0,xv1=0,xv2=0,k=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) 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 } 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(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); 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) int yval=(int)xm.read_u16(); // get value yp=0; ym=0; return(yval); } void drawbuttons() { TFT.fillrect(0,0,50,50,Red); TFT.fillrect(50,0,100,50,Green); TFT.fillrect(100,0,150,50,Blue); TFT.fillrect(150,0,200,50,White); TFT.fillrect(200,0,240,50,Black); TFT.rect(0,0,50,50,White); TFT.rect(50,0,100,50,White); TFT.rect(100,0,150,50,White); TFT.rect(150,0,200,50,White); TFT.rect(200,0,240,50,White); } int main() { pc.baud(115200); pwr=1; wait(0.2); LCD_LED = 1; // backlight on TFT.claim(stdout); // send stdout to the TFT display TFT.set_orientation(1); TFT.background(Black); // set background to black TFT.foreground(White); // set chars to white TFT.cls(); // clear the screen //first show the 4 directions TFT.set_orientation(0); TFT.background(Black); TFT.cls(); TFT.set_font((unsigned char*) Arial12x12); TFT.locate(0,0); printf(" 0 Hello Mbed 0"); }