![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Using touch screen features of LCD screen.
Dependencies: DmTouch_UniGraphic UniGraphic mbed
Fork of DisplayModule24_demo by
main.cpp@9:8917e707fe8e, 2016-01-20 (annotated)
- Committer:
- JLarkin
- Date:
- Wed Jan 20 07:21:30 2016 +0000
- Revision:
- 9:8917e707fe8e
- Parent:
- 8:9484e01decd9
- Child:
- 10:ca16a309a737
Revised DmTouch to work with UniGraphics, multiple screen orientations, and flexible mbed pins.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Geremia | 0:2ccd65a72ab8 | 1 | #include "stdio.h" |
Geremia | 0:2ccd65a72ab8 | 2 | #include "mbed.h" |
Geremia | 0:2ccd65a72ab8 | 3 | #include "string" |
JLarkin | 7:1dbfaba27e99 | 4 | #include "ILI932x.h" |
JLarkin | 9:8917e707fe8e | 5 | #include "DmTouch.h" |
JLarkin | 9:8917e707fe8e | 6 | |
JLarkin | 6:6b6e93790b4c | 7 | |
Geremia | 0:2ccd65a72ab8 | 8 | #include "Arial12x12.h" |
Geremia | 0:2ccd65a72ab8 | 9 | #include "Arial24x23.h" |
Geremia | 4:818956c30cae | 10 | #include "pavement_48x34.h" |
Geremia | 0:2ccd65a72ab8 | 11 | |
Geremia | 0:2ccd65a72ab8 | 12 | Serial pc(USBTX, USBRX); |
Geremia | 0:2ccd65a72ab8 | 13 | |
JLarkin | 7:1dbfaba27e99 | 14 | /* Configure the DisplayModule ILI9325 2.4" display for 8-bit bus communication |
JLarkin | 6:6b6e93790b4c | 15 | |
JLarkin | 6:6b6e93790b4c | 16 | mbed pin display pin |
JLarkin | 6:6b6e93790b4c | 17 | -------- ----------- |
JLarkin | 7:1dbfaba27e99 | 18 | p15 CS (L15) |
JLarkin | 7:1dbfaba27e99 | 19 | p17 RST (L17) |
JLarkin | 7:1dbfaba27e99 | 20 | p16 RS (L4) |
JLarkin | 7:1dbfaba27e99 | 21 | p14 WR (L5) |
JLarkin | 7:1dbfaba27e99 | 22 | p20 RD (L6) |
JLarkin | 6:6b6e93790b4c | 23 | |
JLarkin | 7:1dbfaba27e99 | 24 | p30 DB8 (L7) |
JLarkin | 7:1dbfaba27e99 | 25 | p29 DB9 (L8) |
JLarkin | 7:1dbfaba27e99 | 26 | p28 DB10 (L9) |
JLarkin | 7:1dbfaba27e99 | 27 | p27 DB11 (L10) |
JLarkin | 7:1dbfaba27e99 | 28 | p26 DB12 (L11) |
JLarkin | 7:1dbfaba27e99 | 29 | p25 DB13 (L12) |
JLarkin | 7:1dbfaba27e99 | 30 | p24 DB14 (L13) |
JLarkin | 7:1dbfaba27e99 | 31 | p23 DB15 (L14) |
JLarkin | 6:6b6e93790b4c | 32 | |
JLarkin | 7:1dbfaba27e99 | 33 | p1 GND (L1) |
JLarkin | 7:1dbfaba27e99 | 34 | p40 Vin (L2) |
JLarkin | 9:8917e707fe8e | 35 | p40 LED Backlight (L19) |
JLarkin | 6:6b6e93790b4c | 36 | */ |
JLarkin | 7:1dbfaba27e99 | 37 | PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; |
JLarkin | 7:1dbfaba27e99 | 38 | ILI932x myLCD(BUS_8, dataBus, p15, p17, p16, p14, p20, "myLCD", 240, 320); // Bus 8 bit, bus pin array, CS, RST, DC, WR, RD, name, xpixels, ypixels |
Geremia | 0:2ccd65a72ab8 | 39 | |
JLarkin | 9:8917e707fe8e | 40 | /* Additional connections to add touch response |
JLarkin | 9:8917e707fe8e | 41 | |
JLarkin | 9:8917e707fe8e | 42 | mbed pin display pin |
JLarkin | 9:8917e707fe8e | 43 | -------- ----------- |
JLarkin | 9:8917e707fe8e | 44 | p5 T_MOSI (R11) |
JLarkin | 9:8917e707fe8e | 45 | p6 T_MISO (R13) |
JLarkin | 9:8917e707fe8e | 46 | p7 T_CLK (R9) |
JLarkin | 9:8917e707fe8e | 47 | p8 T_CS (R10) |
JLarkin | 9:8917e707fe8e | 48 | p9 T_IRQ (R14) |
JLarkin | 9:8917e707fe8e | 49 | */ |
JLarkin | 9:8917e707fe8e | 50 | DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9); |
JLarkin | 9:8917e707fe8e | 51 | |
JLarkin | 9:8917e707fe8e | 52 | char orient=0; |
JLarkin | 7:1dbfaba27e99 | 53 | int x,y; |
JLarkin | 9:8917e707fe8e | 54 | uint16_t tx, ty; |
JLarkin | 9:8917e707fe8e | 55 | Timer t; |
JLarkin | 7:1dbfaba27e99 | 56 | |
Geremia | 0:2ccd65a72ab8 | 57 | int main() |
Geremia | 0:2ccd65a72ab8 | 58 | { |
JLarkin | 9:8917e707fe8e | 59 | bool down, lastDown; |
JLarkin | 9:8917e707fe8e | 60 | touch.init(); |
JLarkin | 9:8917e707fe8e | 61 | t.start(); |
Geremia | 4:818956c30cae | 62 | myLCD.set_orientation(orient); |
JLarkin | 6:6b6e93790b4c | 63 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 9:8917e707fe8e | 64 | myLCD.background(Blue); // set background to Blue |
JLarkin | 9:8917e707fe8e | 65 | myLCD.foreground(White); // set chars to White |
Geremia | 4:818956c30cae | 66 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 67 | myLCD.locate(10,30); |
JLarkin | 6:6b6e93790b4c | 68 | myLCD.printf("UniGraphics Demo\r\n"); |
Geremia | 1:083257298075 | 69 | wait(2); |
Geremia | 0:2ccd65a72ab8 | 70 | |
JLarkin | 6:6b6e93790b4c | 71 | while(1) |
JLarkin | 6:6b6e93790b4c | 72 | { |
JLarkin | 6:6b6e93790b4c | 73 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 74 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 6:6b6e93790b4c | 75 | myLCD.locate(0,30); |
JLarkin | 6:6b6e93790b4c | 76 | myLCD.printf("Orientation mode: %x\r\n", orient%4); |
JLarkin | 6:6b6e93790b4c | 77 | wait(2); |
JLarkin | 6:6b6e93790b4c | 78 | myLCD.printf("Font is\r\n"); |
JLarkin | 6:6b6e93790b4c | 79 | myLCD.printf("Arial24x23\r\n"); |
JLarkin | 6:6b6e93790b4c | 80 | wait(2); |
JLarkin | 6:6b6e93790b4c | 81 | |
JLarkin | 6:6b6e93790b4c | 82 | myLCD.background(Black); |
JLarkin | 6:6b6e93790b4c | 83 | myLCD.foreground(White); |
JLarkin | 6:6b6e93790b4c | 84 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 85 | myLCD.set_font((unsigned char*) Arial12x12); |
JLarkin | 6:6b6e93790b4c | 86 | myLCD.locate(0,10); |
JLarkin | 6:6b6e93790b4c | 87 | myLCD.printf("Font changed to Arial12x12\r\n"); |
JLarkin | 6:6b6e93790b4c | 88 | myLCD.printf("Background and foreground color also changed.\n\r\n\r"); |
JLarkin | 6:6b6e93790b4c | 89 | wait(2); |
JLarkin | 6:6b6e93790b4c | 90 | myLCD.printf("Notice that if some text is too long to fit the width of the screen that it is automatically wrapped to the next line.\r\n\r\n"); |
JLarkin | 6:6b6e93790b4c | 91 | wait(2); |
JLarkin | 6:6b6e93790b4c | 92 | myLCD.set_font((unsigned char*) Terminal6x8); |
JLarkin | 6:6b6e93790b4c | 93 | myLCD.printf("Font changed to Terminal6x8\r\n"); |
JLarkin | 6:6b6e93790b4c | 94 | myLCD.printf("This is pretty small!\r\n"); |
JLarkin | 6:6b6e93790b4c | 95 | wait(2); |
JLarkin | 6:6b6e93790b4c | 96 | |
JLarkin | 6:6b6e93790b4c | 97 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 98 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 6:6b6e93790b4c | 99 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 100 | myLCD.printf("Draw lines\n\r"); |
JLarkin | 6:6b6e93790b4c | 101 | myLCD.line(0,50,myLCD.width()-1,50,Yellow); |
JLarkin | 6:6b6e93790b4c | 102 | myLCD.line(myLCD.width()-50,51,myLCD.width()-50,myLCD.height()-1,Green); |
JLarkin | 6:6b6e93790b4c | 103 | wait(2); |
JLarkin | 6:6b6e93790b4c | 104 | |
JLarkin | 6:6b6e93790b4c | 105 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 106 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 107 | myLCD.printf("Draw rectangles"); |
JLarkin | 6:6b6e93790b4c | 108 | myLCD.rect(10,50,50,80,Red); |
JLarkin | 6:6b6e93790b4c | 109 | myLCD.rect(15,55,45,75,Red); |
JLarkin | 6:6b6e93790b4c | 110 | myLCD.rect(20,60,40,70,Red); |
JLarkin | 6:6b6e93790b4c | 111 | myLCD.fillrect(160,130,200,240,Blue); |
JLarkin | 6:6b6e93790b4c | 112 | wait(2); |
JLarkin | 6:6b6e93790b4c | 113 | |
JLarkin | 6:6b6e93790b4c | 114 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 115 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 116 | myLCD.printf("Draw circles"); |
JLarkin | 6:6b6e93790b4c | 117 | myLCD.circle(150,132,30,Yellow); |
JLarkin | 6:6b6e93790b4c | 118 | myLCD.fillcircle(140,70,25,Cyan); |
JLarkin | 6:6b6e93790b4c | 119 | wait(2); |
JLarkin | 6:6b6e93790b4c | 120 | |
JLarkin | 6:6b6e93790b4c | 121 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 122 | myLCD.set_font((unsigned char*) Arial12x12); |
JLarkin | 6:6b6e93790b4c | 123 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 124 | myLCD.printf("Draw function with pixels"); |
JLarkin | 6:6b6e93790b4c | 125 | double s; |
JLarkin | 6:6b6e93790b4c | 126 | for (unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 0:2ccd65a72ab8 | 127 | { |
Geremia | 0:2ccd65a72ab8 | 128 | s =10 * sin((long double) i / 10 ); |
JLarkin | 6:6b6e93790b4c | 129 | myLCD.pixel(i,80 + (int)s ,White); |
Geremia | 0:2ccd65a72ab8 | 130 | } |
JLarkin | 6:6b6e93790b4c | 131 | wait(3); |
JLarkin | 6:6b6e93790b4c | 132 | |
JLarkin | 9:8917e707fe8e | 133 | // Touch screen demo |
JLarkin | 9:8917e707fe8e | 134 | myLCD.background(Blue); // set background to Blue |
JLarkin | 9:8917e707fe8e | 135 | myLCD.foreground(White); // set chars to White |
JLarkin | 9:8917e707fe8e | 136 | myLCD.cls(); // clear the screen |
JLarkin | 9:8917e707fe8e | 137 | myLCD.locate(10,30); |
JLarkin | 9:8917e707fe8e | 138 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 9:8917e707fe8e | 139 | myLCD.printf("DmTouch Demo\r\n"); |
JLarkin | 9:8917e707fe8e | 140 | myLCD.set_font((unsigned char*) Arial12x12); |
JLarkin | 9:8917e707fe8e | 141 | myLCD.locate(10,70); |
JLarkin | 9:8917e707fe8e | 142 | myLCD.printf("Coming soon...\r\nTouch screen and coordinates will display\r\n"); |
JLarkin | 9:8917e707fe8e | 143 | myLCD.printf("Moves to next portion of demo after 30 seconds\r\n"); |
JLarkin | 9:8917e707fe8e | 144 | wait(2); |
JLarkin | 9:8917e707fe8e | 145 | myLCD.background(Black); // set background to Black |
JLarkin | 9:8917e707fe8e | 146 | myLCD.foreground(White); // set chars to White |
JLarkin | 9:8917e707fe8e | 147 | myLCD.cls(); // clear the screen |
JLarkin | 9:8917e707fe8e | 148 | |
JLarkin | 9:8917e707fe8e | 149 | touch.setOrientation(orient); |
JLarkin | 9:8917e707fe8e | 150 | down = false; |
JLarkin | 9:8917e707fe8e | 151 | lastDown = false; |
JLarkin | 9:8917e707fe8e | 152 | tx = (uint16_t)0; |
JLarkin | 9:8917e707fe8e | 153 | ty = (uint16_t)0; |
JLarkin | 9:8917e707fe8e | 154 | myLCD.locate(20,20); |
JLarkin | 9:8917e707fe8e | 155 | myLCD.printf("x:"); |
JLarkin | 9:8917e707fe8e | 156 | myLCD.locate(100, 20); |
JLarkin | 9:8917e707fe8e | 157 | myLCD.printf("y:"); |
JLarkin | 9:8917e707fe8e | 158 | |
JLarkin | 9:8917e707fe8e | 159 | t.reset(); |
JLarkin | 9:8917e707fe8e | 160 | while (t.read()<30) { |
JLarkin | 9:8917e707fe8e | 161 | touch.readTouchData(tx, ty, down); |
JLarkin | 9:8917e707fe8e | 162 | if (down) { |
JLarkin | 9:8917e707fe8e | 163 | myLCD.locate(40, 20); |
JLarkin | 9:8917e707fe8e | 164 | myLCD.printf("%5i", tx); |
JLarkin | 9:8917e707fe8e | 165 | myLCD.locate(120, 20); |
JLarkin | 9:8917e707fe8e | 166 | myLCD.printf("%5i", ty); |
JLarkin | 9:8917e707fe8e | 167 | myLCD.fillcircle(tx, ty, 2, Red); |
JLarkin | 9:8917e707fe8e | 168 | } else if (lastDown) { |
JLarkin | 9:8917e707fe8e | 169 | // no longer pressed, clean text |
JLarkin | 9:8917e707fe8e | 170 | myLCD.locate(40, 20); |
JLarkin | 9:8917e707fe8e | 171 | myLCD.printf(" ", tx); |
JLarkin | 9:8917e707fe8e | 172 | myLCD.locate(120, 20); |
JLarkin | 9:8917e707fe8e | 173 | myLCD.printf(" ", ty); |
JLarkin | 9:8917e707fe8e | 174 | } |
JLarkin | 9:8917e707fe8e | 175 | wait(0.040); |
JLarkin | 9:8917e707fe8e | 176 | lastDown = down; |
JLarkin | 9:8917e707fe8e | 177 | } |
JLarkin | 9:8917e707fe8e | 178 | |
JLarkin | 9:8917e707fe8e | 179 | |
Geremia | 2:2b781c215ac0 | 180 | // scroll test, only for TFT |
Geremia | 4:818956c30cae | 181 | myLCD.cls(); |
Geremia | 4:818956c30cae | 182 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 5:c69049e461b7 | 183 | myLCD.locate(2,10); |
Geremia | 4:818956c30cae | 184 | myLCD.printf("Scrolling"); |
Geremia | 4:818956c30cae | 185 | myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); |
Geremia | 4:818956c30cae | 186 | myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); |
Geremia | 4:818956c30cae | 187 | myLCD.setscrollarea(0,myLCD.sizeY()); |
Geremia | 2:2b781c215ac0 | 188 | wait(1); |
Geremia | 4:818956c30cae | 189 | myLCD.scroll(1); //up 1 |
Geremia | 2:2b781c215ac0 | 190 | wait(1); |
Geremia | 4:818956c30cae | 191 | myLCD.scroll(0); //center |
Geremia | 2:2b781c215ac0 | 192 | wait(1); |
Geremia | 4:818956c30cae | 193 | myLCD.scroll(myLCD.sizeY()-1); //down 1 |
Geremia | 2:2b781c215ac0 | 194 | wait(1); |
Geremia | 4:818956c30cae | 195 | myLCD.scroll(myLCD.sizeY()); // same as 0, center |
Geremia | 2:2b781c215ac0 | 196 | wait(1); |
Geremia | 4:818956c30cae | 197 | myLCD.scroll(myLCD.sizeY()>>1); // half screen |
Geremia | 2:2b781c215ac0 | 198 | wait(1); |
Geremia | 4:818956c30cae | 199 | myLCD.scrollreset(); // center |
Geremia | 2:2b781c215ac0 | 200 | wait(1); |
Geremia | 4:818956c30cae | 201 | for(unsigned short i=1; i<=myLCD.sizeY(); i++) |
Geremia | 2:2b781c215ac0 | 202 | { |
Geremia | 4:818956c30cae | 203 | myLCD.scroll(i); |
Geremia | 2:2b781c215ac0 | 204 | wait_ms(2); |
Geremia | 2:2b781c215ac0 | 205 | } |
Geremia | 2:2b781c215ac0 | 206 | wait(2); |
Geremia | 2:2b781c215ac0 | 207 | // color inversion |
Geremia | 2:2b781c215ac0 | 208 | for(unsigned short i=0; i<=8; i++) |
Geremia | 2:2b781c215ac0 | 209 | { |
Geremia | 4:818956c30cae | 210 | myLCD.invert(i&1); |
Geremia | 2:2b781c215ac0 | 211 | wait_ms(200); |
Geremia | 2:2b781c215ac0 | 212 | } |
Geremia | 2:2b781c215ac0 | 213 | wait(2); |
Geremia | 4:818956c30cae | 214 | // bmp 16bit test |
Geremia | 4:818956c30cae | 215 | myLCD.cls(); |
Geremia | 4:818956c30cae | 216 | for(int y=0; y<myLCD.height(); y+=34) |
Geremia | 4:818956c30cae | 217 | { |
Geremia | 4:818956c30cae | 218 | for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); |
Geremia | 4:818956c30cae | 219 | } |
Geremia | 4:818956c30cae | 220 | wait(2); |
JLarkin | 6:6b6e93790b4c | 221 | myLCD.set_orientation((++orient)%4); |
Geremia | 0:2ccd65a72ab8 | 222 | } |
Geremia | 0:2ccd65a72ab8 | 223 | } |