![](/media/cache/group/mouse.jpg.50x50_q85.jpg)
Full layout 'HUB' with functioning navigation between all screens and active temp/state display
Dependencies: ID12RFID SPI_TFT_ILI9341 TFT_fonts mbed
Fork of Welcome_Screen_TFT by
main.cpp@6:18c7288b5e00, 2016-06-14 (annotated)
- Committer:
- cstevens
- Date:
- Tue Jun 14 11:01:24 2016 +0000
- Revision:
- 6:18c7288b5e00
- Parent:
- 5:424af4fa03ab
- Child:
- 7:ceeced183454
touch nearly working;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cstevens | 4:14043cafbec7 | 1 | // example to test the TFT Display from Mikroelectronika |
dreschpe | 0:7c3b9bfd6ead | 2 | |
dreschpe | 0:7c3b9bfd6ead | 3 | #include "stdio.h" |
dreschpe | 0:7c3b9bfd6ead | 4 | #include "mbed.h" |
dreschpe | 0:7c3b9bfd6ead | 5 | #include "SPI_TFT_ILI9341.h" |
dreschpe | 0:7c3b9bfd6ead | 6 | #include "string" |
dreschpe | 0:7c3b9bfd6ead | 7 | #include "Arial12x12.h" |
dreschpe | 0:7c3b9bfd6ead | 8 | #include "Arial24x23.h" |
dreschpe | 0:7c3b9bfd6ead | 9 | #include "Arial28x28.h" |
dreschpe | 0:7c3b9bfd6ead | 10 | #include "font_big.h" |
cstevens | 4:14043cafbec7 | 11 | |
cstevens | 6:18c7288b5e00 | 12 | |
cstevens | 6:18c7288b5e00 | 13 | Serial pc (USBTX,USBRX); |
cstevens | 4:14043cafbec7 | 14 | |
dreschpe | 0:7c3b9bfd6ead | 15 | |
dreschpe | 0:7c3b9bfd6ead | 16 | |
pegcjs | 3:676adf84c914 | 17 | |
cstevens | 6:18c7288b5e00 | 18 | // the display has a backlight switch on board |
cstevens | 6:18c7288b5e00 | 19 | DigitalOut LCD_LED(PTA13); // may not be needed on mikroelectronika board |
cstevens | 5:424af4fa03ab | 20 | DigitalOut pwr(PTD7); // ditto |
dreschpe | 0:7c3b9bfd6ead | 21 | |
dreschpe | 0:7c3b9bfd6ead | 22 | // the TFT is connected to SPI pin 5-7 |
pegcjs | 1:e0479f60cd48 | 23 | //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc for lpc1768 |
cstevens | 5:424af4fa03ab | 24 | SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z |
cstevens | 6:18c7288b5e00 | 25 | //NB better combination to use a coherent 2x4 block for lcd |
pegcjs | 3:676adf84c914 | 26 | // SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTA16, PTA17, PTC16,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z |
cstevens | 6:18c7288b5e00 | 27 | // DigitalOut LCD_LED(PTC17); |
cstevens | 6:18c7288b5e00 | 28 | |
cstevens | 6:18c7288b5e00 | 29 | |
cstevens | 6:18c7288b5e00 | 30 | // Subroutine to read the x location of the touch point |
cstevens | 6:18c7288b5e00 | 31 | // need to set x+ to 3V and ground x- then read analogue voltage on ym |
cstevens | 6:18c7288b5e00 | 32 | //nb need to add a check for actual touch as opposed to random crap |
cstevens | 6:18c7288b5e00 | 33 | int readX() |
cstevens | 6:18c7288b5e00 | 34 | { |
cstevens | 6:18c7288b5e00 | 35 | AnalogIn yp(PTB2); |
cstevens | 6:18c7288b5e00 | 36 | AnalogIn ym(PTB3); |
cstevens | 6:18c7288b5e00 | 37 | DigitalOut xp(PTB0); |
cstevens | 6:18c7288b5e00 | 38 | DigitalOut xm(PTB1); |
cstevens | 6:18c7288b5e00 | 39 | |
cstevens | 6:18c7288b5e00 | 40 | xp=1; // set positive sdie of x high |
cstevens | 6:18c7288b5e00 | 41 | xm=0; |
cstevens | 6:18c7288b5e00 | 42 | // dont need to do anyhting to set low side as it should be fine. |
cstevens | 6:18c7288b5e00 | 43 | // but do need to disconnect yp |
cstevens | 6:18c7288b5e00 | 44 | //yp.PinMode(PullNone) |
cstevens | 6:18c7288b5e00 | 45 | int xval=(int)ym.read_u16(); // get value |
cstevens | 6:18c7288b5e00 | 46 | return(xval); |
cstevens | 6:18c7288b5e00 | 47 | } |
cstevens | 6:18c7288b5e00 | 48 | // subroutine to read y values - has different pin functions .. |
cstevens | 6:18c7288b5e00 | 49 | int readY() |
cstevens | 6:18c7288b5e00 | 50 | { |
cstevens | 6:18c7288b5e00 | 51 | DigitalOut yp(PTB2); |
cstevens | 6:18c7288b5e00 | 52 | DigitalOut ym(PTB3); |
cstevens | 6:18c7288b5e00 | 53 | AnalogIn xp(PTB0); |
cstevens | 6:18c7288b5e00 | 54 | AnalogIn xm(PTB1); |
cstevens | 6:18c7288b5e00 | 55 | |
cstevens | 6:18c7288b5e00 | 56 | yp=1; // set positive sdie of x high |
cstevens | 6:18c7288b5e00 | 57 | ym=0; |
cstevens | 6:18c7288b5e00 | 58 | // dont need to do anyhting to set low side as it should be fine. |
cstevens | 6:18c7288b5e00 | 59 | // but do need to disconnect yp |
cstevens | 6:18c7288b5e00 | 60 | //yp.PinMode(PullNone) |
cstevens | 6:18c7288b5e00 | 61 | int yval=(int)xm.read_u16(); // get value |
cstevens | 6:18c7288b5e00 | 62 | return(yval); |
cstevens | 6:18c7288b5e00 | 63 | } |
cstevens | 6:18c7288b5e00 | 64 | |
cstevens | 6:18c7288b5e00 | 65 | |
cstevens | 4:14043cafbec7 | 66 | |
dreschpe | 0:7c3b9bfd6ead | 67 | int main() |
dreschpe | 0:7c3b9bfd6ead | 68 | { |
cstevens | 6:18c7288b5e00 | 69 | pc.baud(115200); |
cstevens | 6:18c7288b5e00 | 70 | |
cstevens | 6:18c7288b5e00 | 71 | int xpos=0,ypos=0,xp=0,yp=0; |
pegcjs | 3:676adf84c914 | 72 | pwr=1; |
pegcjs | 3:676adf84c914 | 73 | wait(0.2); |
cstevens | 6:18c7288b5e00 | 74 | |
dreschpe | 0:7c3b9bfd6ead | 75 | int i; |
pegcjs | 2:25bfb21253a6 | 76 | LCD_LED = 1; // backlight on |
cstevens | 6:18c7288b5e00 | 77 | |
dreschpe | 0:7c3b9bfd6ead | 78 | TFT.claim(stdout); // send stdout to the TFT display |
dreschpe | 0:7c3b9bfd6ead | 79 | TFT.set_orientation(1); |
dreschpe | 0:7c3b9bfd6ead | 80 | TFT.background(Black); // set background to black |
dreschpe | 0:7c3b9bfd6ead | 81 | TFT.foreground(White); // set chars to white |
dreschpe | 0:7c3b9bfd6ead | 82 | TFT.cls(); // clear the screen |
dreschpe | 0:7c3b9bfd6ead | 83 | |
dreschpe | 0:7c3b9bfd6ead | 84 | //first show the 4 directions |
dreschpe | 0:7c3b9bfd6ead | 85 | TFT.set_orientation(0); |
dreschpe | 0:7c3b9bfd6ead | 86 | TFT.background(Black); |
dreschpe | 0:7c3b9bfd6ead | 87 | TFT.cls(); |
dreschpe | 0:7c3b9bfd6ead | 88 | |
dreschpe | 0:7c3b9bfd6ead | 89 | TFT.set_font((unsigned char*) Arial12x12); |
dreschpe | 0:7c3b9bfd6ead | 90 | TFT.locate(0,0); |
cstevens | 6:18c7288b5e00 | 91 | printf(" 0 Hello Mbed 0"); |
dreschpe | 0:7c3b9bfd6ead | 92 | TFT.set_orientation(1); |
dreschpe | 0:7c3b9bfd6ead | 93 | TFT.locate(0,0); |
cstevens | 6:18c7288b5e00 | 94 | printf(" 1 Hello Mbed 1"); |
dreschpe | 0:7c3b9bfd6ead | 95 | TFT.set_orientation(2); |
dreschpe | 0:7c3b9bfd6ead | 96 | TFT.locate(0,0); |
cstevens | 6:18c7288b5e00 | 97 | printf(" 2 Hello Mbed 2"); |
dreschpe | 0:7c3b9bfd6ead | 98 | TFT.set_orientation(3); |
dreschpe | 0:7c3b9bfd6ead | 99 | TFT.locate(0,0); |
cstevens | 6:18c7288b5e00 | 100 | printf(" 3 Hello Mbed 3"); |
pegcjs | 1:e0479f60cd48 | 101 | TFT.set_orientation(3); |
dreschpe | 0:7c3b9bfd6ead | 102 | TFT.set_font((unsigned char*) Arial24x23); |
dreschpe | 0:7c3b9bfd6ead | 103 | TFT.locate(50,100); |
cstevens | 6:18c7288b5e00 | 104 | TFT.printf("TFT orientation 3"); |
cstevens | 6:18c7288b5e00 | 105 | TFT.set_orientation(1); |
cstevens | 6:18c7288b5e00 | 106 | for(i=0; i<10; i++) { |
cstevens | 6:18c7288b5e00 | 107 | wait(1); // wait one seconds |
cstevens | 6:18c7288b5e00 | 108 | TFT.locate(50,160); |
cstevens | 6:18c7288b5e00 | 109 | TFT.printf("count %d",i); |
cstevens | 6:18c7288b5e00 | 110 | } |
cstevens | 6:18c7288b5e00 | 111 | TFT.set_orientation(1); |
cstevens | 6:18c7288b5e00 | 112 | TFT.cls(); |
cstevens | 6:18c7288b5e00 | 113 | // LCD_LED = 1; |
cstevens | 6:18c7288b5e00 | 114 | TFT.circle(120,120,10,0xffff); |
cstevens | 6:18c7288b5e00 | 115 | while(1==1) { |
dreschpe | 0:7c3b9bfd6ead | 116 | |
cstevens | 6:18c7288b5e00 | 117 | xpos=readX(); |
cstevens | 6:18c7288b5e00 | 118 | ypos=readY(); |
cstevens | 6:18c7288b5e00 | 119 | pc.printf("xpos=%d\t,\typo=%d",xpos,ypos); |
cstevens | 6:18c7288b5e00 | 120 | xp=(240*xpos)/60000; |
cstevens | 6:18c7288b5e00 | 121 | yp=(320*ypos)/60000; |
cstevens | 6:18c7288b5e00 | 122 | pc.printf("\txp=%d\t,\typo=%d\n\r",xp,yp); |
cstevens | 6:18c7288b5e00 | 123 | if(xp>5 && yp>5) TFT.circle(xp,yp,5,Yellow); |
cstevens | 6:18c7288b5e00 | 124 | wait(0.1); |
cstevens | 6:18c7288b5e00 | 125 | |
pegcjs | 1:e0479f60cd48 | 126 | } |
cstevens | 6:18c7288b5e00 | 127 | |
dreschpe | 0:7c3b9bfd6ead | 128 | } |