![](/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@7:1dbfaba27e99, 2016-01-13 (annotated)
- Committer:
- JLarkin
- Date:
- Wed Jan 13 23:56:43 2016 +0000
- Revision:
- 7:1dbfaba27e99
- Parent:
- 6:6b6e93790b4c
- Child:
- 8:9484e01decd9
Good to go.
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 | 6:6b6e93790b4c | 5 | |
Geremia | 0:2ccd65a72ab8 | 6 | #include "Arial12x12.h" |
Geremia | 0:2ccd65a72ab8 | 7 | #include "Arial24x23.h" |
Geremia | 4:818956c30cae | 8 | #include "pavement_48x34.h" |
Geremia | 0:2ccd65a72ab8 | 9 | |
Geremia | 0:2ccd65a72ab8 | 10 | Serial pc(USBTX, USBRX); |
Geremia | 0:2ccd65a72ab8 | 11 | |
JLarkin | 7:1dbfaba27e99 | 12 | /* Configure the DisplayModule ILI9325 2.4" display for 8-bit bus communication |
JLarkin | 6:6b6e93790b4c | 13 | |
JLarkin | 6:6b6e93790b4c | 14 | mbed pin display pin |
JLarkin | 6:6b6e93790b4c | 15 | -------- ----------- |
JLarkin | 7:1dbfaba27e99 | 16 | p15 CS (L15) |
JLarkin | 7:1dbfaba27e99 | 17 | p17 RST (L17) |
JLarkin | 7:1dbfaba27e99 | 18 | p16 RS (L4) |
JLarkin | 7:1dbfaba27e99 | 19 | p14 WR (L5) |
JLarkin | 7:1dbfaba27e99 | 20 | p20 RD (L6) |
JLarkin | 6:6b6e93790b4c | 21 | |
JLarkin | 7:1dbfaba27e99 | 22 | p30 DB8 (L7) |
JLarkin | 7:1dbfaba27e99 | 23 | p29 DB9 (L8) |
JLarkin | 7:1dbfaba27e99 | 24 | p28 DB10 (L9) |
JLarkin | 7:1dbfaba27e99 | 25 | p27 DB11 (L10) |
JLarkin | 7:1dbfaba27e99 | 26 | p26 DB12 (L11) |
JLarkin | 7:1dbfaba27e99 | 27 | p25 DB13 (L12) |
JLarkin | 7:1dbfaba27e99 | 28 | p24 DB14 (L13) |
JLarkin | 7:1dbfaba27e99 | 29 | p23 DB15 (L14) |
JLarkin | 6:6b6e93790b4c | 30 | |
JLarkin | 7:1dbfaba27e99 | 31 | p1 GND (L1) |
JLarkin | 7:1dbfaba27e99 | 32 | p40 Vin (L2) |
JLarkin | 6:6b6e93790b4c | 33 | */ |
JLarkin | 7:1dbfaba27e99 | 34 | PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23}; |
JLarkin | 7:1dbfaba27e99 | 35 | 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 | 36 | |
JLarkin | 6:6b6e93790b4c | 37 | char orient=3; |
JLarkin | 7:1dbfaba27e99 | 38 | int x,y; |
JLarkin | 7:1dbfaba27e99 | 39 | |
Geremia | 0:2ccd65a72ab8 | 40 | int main() |
Geremia | 0:2ccd65a72ab8 | 41 | { |
Geremia | 4:818956c30cae | 42 | myLCD.set_orientation(orient); |
Geremia | 0:2ccd65a72ab8 | 43 | t.start(); |
JLarkin | 6:6b6e93790b4c | 44 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 6:6b6e93790b4c | 45 | myLCD.background(Blue); // set background to red |
JLarkin | 6:6b6e93790b4c | 46 | myLCD.foreground(White); // set chars to black |
Geremia | 4:818956c30cae | 47 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 48 | myLCD.locate(10,30); |
JLarkin | 6:6b6e93790b4c | 49 | myLCD.printf("UniGraphics Demo\r\n"); |
Geremia | 1:083257298075 | 50 | wait(2); |
Geremia | 0:2ccd65a72ab8 | 51 | |
JLarkin | 6:6b6e93790b4c | 52 | while(1) |
JLarkin | 6:6b6e93790b4c | 53 | { |
JLarkin | 6:6b6e93790b4c | 54 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 55 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 6:6b6e93790b4c | 56 | myLCD.locate(0,30); |
JLarkin | 6:6b6e93790b4c | 57 | myLCD.printf("Orientation mode: %x\r\n", orient%4); |
JLarkin | 6:6b6e93790b4c | 58 | wait(2); |
JLarkin | 6:6b6e93790b4c | 59 | myLCD.printf("Font is\r\n"); |
JLarkin | 6:6b6e93790b4c | 60 | myLCD.printf("Arial24x23\r\n"); |
JLarkin | 6:6b6e93790b4c | 61 | wait(2); |
JLarkin | 6:6b6e93790b4c | 62 | |
JLarkin | 6:6b6e93790b4c | 63 | myLCD.background(Black); |
JLarkin | 6:6b6e93790b4c | 64 | myLCD.foreground(White); |
JLarkin | 6:6b6e93790b4c | 65 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 66 | myLCD.set_font((unsigned char*) Arial12x12); |
JLarkin | 6:6b6e93790b4c | 67 | myLCD.locate(0,10); |
JLarkin | 6:6b6e93790b4c | 68 | myLCD.printf("Font changed to Arial12x12\r\n"); |
JLarkin | 6:6b6e93790b4c | 69 | myLCD.printf("Background and foreground color also changed.\n\r\n\r"); |
JLarkin | 6:6b6e93790b4c | 70 | wait(2); |
JLarkin | 6:6b6e93790b4c | 71 | 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 | 72 | wait(2); |
JLarkin | 6:6b6e93790b4c | 73 | myLCD.set_font((unsigned char*) Terminal6x8); |
JLarkin | 6:6b6e93790b4c | 74 | myLCD.printf("Font changed to Terminal6x8\r\n"); |
JLarkin | 6:6b6e93790b4c | 75 | myLCD.printf("This is pretty small!\r\n"); |
JLarkin | 6:6b6e93790b4c | 76 | wait(2); |
JLarkin | 6:6b6e93790b4c | 77 | |
JLarkin | 6:6b6e93790b4c | 78 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 79 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 6:6b6e93790b4c | 80 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 81 | myLCD.printf("Draw lines\n\r"); |
JLarkin | 6:6b6e93790b4c | 82 | myLCD.line(0,50,myLCD.width()-1,50,Yellow); |
JLarkin | 6:6b6e93790b4c | 83 | myLCD.line(myLCD.width()-50,51,myLCD.width()-50,myLCD.height()-1,Green); |
JLarkin | 6:6b6e93790b4c | 84 | wait(2); |
JLarkin | 6:6b6e93790b4c | 85 | |
JLarkin | 6:6b6e93790b4c | 86 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 87 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 88 | myLCD.printf("Draw rectangles"); |
JLarkin | 6:6b6e93790b4c | 89 | myLCD.rect(10,50,50,80,Red); |
JLarkin | 6:6b6e93790b4c | 90 | myLCD.rect(15,55,45,75,Red); |
JLarkin | 6:6b6e93790b4c | 91 | myLCD.rect(20,60,40,70,Red); |
JLarkin | 6:6b6e93790b4c | 92 | myLCD.fillrect(160,130,200,240,Blue); |
JLarkin | 6:6b6e93790b4c | 93 | wait(2); |
JLarkin | 6:6b6e93790b4c | 94 | |
JLarkin | 6:6b6e93790b4c | 95 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 96 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 97 | myLCD.printf("Draw circles"); |
JLarkin | 6:6b6e93790b4c | 98 | myLCD.circle(150,132,30,Yellow); |
JLarkin | 6:6b6e93790b4c | 99 | myLCD.fillcircle(140,70,25,Cyan); |
JLarkin | 6:6b6e93790b4c | 100 | wait(2); |
JLarkin | 6:6b6e93790b4c | 101 | |
JLarkin | 6:6b6e93790b4c | 102 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 103 | myLCD.set_font((unsigned char*) Arial12x12); |
JLarkin | 6:6b6e93790b4c | 104 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 105 | myLCD.printf("Draw function with pixels"); |
JLarkin | 6:6b6e93790b4c | 106 | double s; |
JLarkin | 6:6b6e93790b4c | 107 | for (unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 0:2ccd65a72ab8 | 108 | { |
Geremia | 0:2ccd65a72ab8 | 109 | s =10 * sin((long double) i / 10 ); |
JLarkin | 6:6b6e93790b4c | 110 | myLCD.pixel(i,80 + (int)s ,White); |
Geremia | 0:2ccd65a72ab8 | 111 | } |
JLarkin | 6:6b6e93790b4c | 112 | wait(3); |
JLarkin | 6:6b6e93790b4c | 113 | |
Geremia | 2:2b781c215ac0 | 114 | // scroll test, only for TFT |
Geremia | 4:818956c30cae | 115 | myLCD.cls(); |
Geremia | 4:818956c30cae | 116 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 5:c69049e461b7 | 117 | myLCD.locate(2,10); |
Geremia | 4:818956c30cae | 118 | myLCD.printf("Scrolling"); |
Geremia | 4:818956c30cae | 119 | myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); |
Geremia | 4:818956c30cae | 120 | myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); |
Geremia | 4:818956c30cae | 121 | myLCD.setscrollarea(0,myLCD.sizeY()); |
Geremia | 2:2b781c215ac0 | 122 | wait(1); |
Geremia | 4:818956c30cae | 123 | myLCD.scroll(1); //up 1 |
Geremia | 2:2b781c215ac0 | 124 | wait(1); |
Geremia | 4:818956c30cae | 125 | myLCD.scroll(0); //center |
Geremia | 2:2b781c215ac0 | 126 | wait(1); |
Geremia | 4:818956c30cae | 127 | myLCD.scroll(myLCD.sizeY()-1); //down 1 |
Geremia | 2:2b781c215ac0 | 128 | wait(1); |
Geremia | 4:818956c30cae | 129 | myLCD.scroll(myLCD.sizeY()); // same as 0, center |
Geremia | 2:2b781c215ac0 | 130 | wait(1); |
Geremia | 4:818956c30cae | 131 | myLCD.scroll(myLCD.sizeY()>>1); // half screen |
Geremia | 2:2b781c215ac0 | 132 | wait(1); |
Geremia | 4:818956c30cae | 133 | myLCD.scrollreset(); // center |
Geremia | 2:2b781c215ac0 | 134 | wait(1); |
Geremia | 4:818956c30cae | 135 | for(unsigned short i=1; i<=myLCD.sizeY(); i++) |
Geremia | 2:2b781c215ac0 | 136 | { |
Geremia | 4:818956c30cae | 137 | myLCD.scroll(i); |
Geremia | 2:2b781c215ac0 | 138 | wait_ms(2); |
Geremia | 2:2b781c215ac0 | 139 | } |
Geremia | 2:2b781c215ac0 | 140 | wait(2); |
Geremia | 2:2b781c215ac0 | 141 | // color inversion |
Geremia | 2:2b781c215ac0 | 142 | for(unsigned short i=0; i<=8; i++) |
Geremia | 2:2b781c215ac0 | 143 | { |
Geremia | 4:818956c30cae | 144 | myLCD.invert(i&1); |
Geremia | 2:2b781c215ac0 | 145 | wait_ms(200); |
Geremia | 2:2b781c215ac0 | 146 | } |
Geremia | 2:2b781c215ac0 | 147 | wait(2); |
Geremia | 4:818956c30cae | 148 | // bmp 16bit test |
Geremia | 4:818956c30cae | 149 | myLCD.cls(); |
Geremia | 4:818956c30cae | 150 | t.reset(); |
Geremia | 4:818956c30cae | 151 | for(int y=0; y<myLCD.height(); y+=34) |
Geremia | 4:818956c30cae | 152 | { |
Geremia | 4:818956c30cae | 153 | for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); |
Geremia | 4:818956c30cae | 154 | } |
Geremia | 4:818956c30cae | 155 | wait(2); |
JLarkin | 6:6b6e93790b4c | 156 | myLCD.set_orientation((++orient)%4); |
Geremia | 0:2ccd65a72ab8 | 157 | } |
Geremia | 0:2ccd65a72ab8 | 158 | } |