![](/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@8:9484e01decd9, 2016-01-14 (annotated)
- Committer:
- JLarkin
- Date:
- Thu Jan 14 19:32:42 2016 +0000
- Revision:
- 8:9484e01decd9
- Parent:
- 7:1dbfaba27e99
- Child:
- 9:8917e707fe8e
Removed lingering references to the timer
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); |
JLarkin | 6:6b6e93790b4c | 43 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 6:6b6e93790b4c | 44 | myLCD.background(Blue); // set background to red |
JLarkin | 6:6b6e93790b4c | 45 | myLCD.foreground(White); // set chars to black |
Geremia | 4:818956c30cae | 46 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 47 | myLCD.locate(10,30); |
JLarkin | 6:6b6e93790b4c | 48 | myLCD.printf("UniGraphics Demo\r\n"); |
Geremia | 1:083257298075 | 49 | wait(2); |
Geremia | 0:2ccd65a72ab8 | 50 | |
JLarkin | 6:6b6e93790b4c | 51 | while(1) |
JLarkin | 6:6b6e93790b4c | 52 | { |
JLarkin | 6:6b6e93790b4c | 53 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 54 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 6:6b6e93790b4c | 55 | myLCD.locate(0,30); |
JLarkin | 6:6b6e93790b4c | 56 | myLCD.printf("Orientation mode: %x\r\n", orient%4); |
JLarkin | 6:6b6e93790b4c | 57 | wait(2); |
JLarkin | 6:6b6e93790b4c | 58 | myLCD.printf("Font is\r\n"); |
JLarkin | 6:6b6e93790b4c | 59 | myLCD.printf("Arial24x23\r\n"); |
JLarkin | 6:6b6e93790b4c | 60 | wait(2); |
JLarkin | 6:6b6e93790b4c | 61 | |
JLarkin | 6:6b6e93790b4c | 62 | myLCD.background(Black); |
JLarkin | 6:6b6e93790b4c | 63 | myLCD.foreground(White); |
JLarkin | 6:6b6e93790b4c | 64 | myLCD.cls(); // clear the screen |
JLarkin | 6:6b6e93790b4c | 65 | myLCD.set_font((unsigned char*) Arial12x12); |
JLarkin | 6:6b6e93790b4c | 66 | myLCD.locate(0,10); |
JLarkin | 6:6b6e93790b4c | 67 | myLCD.printf("Font changed to Arial12x12\r\n"); |
JLarkin | 6:6b6e93790b4c | 68 | myLCD.printf("Background and foreground color also changed.\n\r\n\r"); |
JLarkin | 6:6b6e93790b4c | 69 | wait(2); |
JLarkin | 6:6b6e93790b4c | 70 | 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 | 71 | wait(2); |
JLarkin | 6:6b6e93790b4c | 72 | myLCD.set_font((unsigned char*) Terminal6x8); |
JLarkin | 6:6b6e93790b4c | 73 | myLCD.printf("Font changed to Terminal6x8\r\n"); |
JLarkin | 6:6b6e93790b4c | 74 | myLCD.printf("This is pretty small!\r\n"); |
JLarkin | 6:6b6e93790b4c | 75 | wait(2); |
JLarkin | 6:6b6e93790b4c | 76 | |
JLarkin | 6:6b6e93790b4c | 77 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 78 | myLCD.set_font((unsigned char*) Arial24x23); |
JLarkin | 6:6b6e93790b4c | 79 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 80 | myLCD.printf("Draw lines\n\r"); |
JLarkin | 6:6b6e93790b4c | 81 | myLCD.line(0,50,myLCD.width()-1,50,Yellow); |
JLarkin | 6:6b6e93790b4c | 82 | myLCD.line(myLCD.width()-50,51,myLCD.width()-50,myLCD.height()-1,Green); |
JLarkin | 6:6b6e93790b4c | 83 | wait(2); |
JLarkin | 6:6b6e93790b4c | 84 | |
JLarkin | 6:6b6e93790b4c | 85 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 86 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 87 | myLCD.printf("Draw rectangles"); |
JLarkin | 6:6b6e93790b4c | 88 | myLCD.rect(10,50,50,80,Red); |
JLarkin | 6:6b6e93790b4c | 89 | myLCD.rect(15,55,45,75,Red); |
JLarkin | 6:6b6e93790b4c | 90 | myLCD.rect(20,60,40,70,Red); |
JLarkin | 6:6b6e93790b4c | 91 | myLCD.fillrect(160,130,200,240,Blue); |
JLarkin | 6:6b6e93790b4c | 92 | wait(2); |
JLarkin | 6:6b6e93790b4c | 93 | |
JLarkin | 6:6b6e93790b4c | 94 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 95 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 96 | myLCD.printf("Draw circles"); |
JLarkin | 6:6b6e93790b4c | 97 | myLCD.circle(150,132,30,Yellow); |
JLarkin | 6:6b6e93790b4c | 98 | myLCD.fillcircle(140,70,25,Cyan); |
JLarkin | 6:6b6e93790b4c | 99 | wait(2); |
JLarkin | 6:6b6e93790b4c | 100 | |
JLarkin | 6:6b6e93790b4c | 101 | myLCD.cls(); |
JLarkin | 6:6b6e93790b4c | 102 | myLCD.set_font((unsigned char*) Arial12x12); |
JLarkin | 6:6b6e93790b4c | 103 | myLCD.locate(10,10); |
JLarkin | 6:6b6e93790b4c | 104 | myLCD.printf("Draw function with pixels"); |
JLarkin | 6:6b6e93790b4c | 105 | double s; |
JLarkin | 6:6b6e93790b4c | 106 | for (unsigned short i=0; i<myLCD.width(); i++) |
Geremia | 0:2ccd65a72ab8 | 107 | { |
Geremia | 0:2ccd65a72ab8 | 108 | s =10 * sin((long double) i / 10 ); |
JLarkin | 6:6b6e93790b4c | 109 | myLCD.pixel(i,80 + (int)s ,White); |
Geremia | 0:2ccd65a72ab8 | 110 | } |
JLarkin | 6:6b6e93790b4c | 111 | wait(3); |
JLarkin | 6:6b6e93790b4c | 112 | |
Geremia | 2:2b781c215ac0 | 113 | // scroll test, only for TFT |
Geremia | 4:818956c30cae | 114 | myLCD.cls(); |
Geremia | 4:818956c30cae | 115 | myLCD.set_font((unsigned char*) Arial24x23); |
Geremia | 5:c69049e461b7 | 116 | myLCD.locate(2,10); |
Geremia | 4:818956c30cae | 117 | myLCD.printf("Scrolling"); |
Geremia | 4:818956c30cae | 118 | myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White); |
Geremia | 4:818956c30cae | 119 | myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue); |
Geremia | 4:818956c30cae | 120 | myLCD.setscrollarea(0,myLCD.sizeY()); |
Geremia | 2:2b781c215ac0 | 121 | wait(1); |
Geremia | 4:818956c30cae | 122 | myLCD.scroll(1); //up 1 |
Geremia | 2:2b781c215ac0 | 123 | wait(1); |
Geremia | 4:818956c30cae | 124 | myLCD.scroll(0); //center |
Geremia | 2:2b781c215ac0 | 125 | wait(1); |
Geremia | 4:818956c30cae | 126 | myLCD.scroll(myLCD.sizeY()-1); //down 1 |
Geremia | 2:2b781c215ac0 | 127 | wait(1); |
Geremia | 4:818956c30cae | 128 | myLCD.scroll(myLCD.sizeY()); // same as 0, center |
Geremia | 2:2b781c215ac0 | 129 | wait(1); |
Geremia | 4:818956c30cae | 130 | myLCD.scroll(myLCD.sizeY()>>1); // half screen |
Geremia | 2:2b781c215ac0 | 131 | wait(1); |
Geremia | 4:818956c30cae | 132 | myLCD.scrollreset(); // center |
Geremia | 2:2b781c215ac0 | 133 | wait(1); |
Geremia | 4:818956c30cae | 134 | for(unsigned short i=1; i<=myLCD.sizeY(); i++) |
Geremia | 2:2b781c215ac0 | 135 | { |
Geremia | 4:818956c30cae | 136 | myLCD.scroll(i); |
Geremia | 2:2b781c215ac0 | 137 | wait_ms(2); |
Geremia | 2:2b781c215ac0 | 138 | } |
Geremia | 2:2b781c215ac0 | 139 | wait(2); |
Geremia | 2:2b781c215ac0 | 140 | // color inversion |
Geremia | 2:2b781c215ac0 | 141 | for(unsigned short i=0; i<=8; i++) |
Geremia | 2:2b781c215ac0 | 142 | { |
Geremia | 4:818956c30cae | 143 | myLCD.invert(i&1); |
Geremia | 2:2b781c215ac0 | 144 | wait_ms(200); |
Geremia | 2:2b781c215ac0 | 145 | } |
Geremia | 2:2b781c215ac0 | 146 | wait(2); |
Geremia | 4:818956c30cae | 147 | // bmp 16bit test |
Geremia | 4:818956c30cae | 148 | myLCD.cls(); |
Geremia | 4:818956c30cae | 149 | for(int y=0; y<myLCD.height(); y+=34) |
Geremia | 4:818956c30cae | 150 | { |
Geremia | 4:818956c30cae | 151 | for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34); |
Geremia | 4:818956c30cae | 152 | } |
Geremia | 4:818956c30cae | 153 | wait(2); |
JLarkin | 6:6b6e93790b4c | 154 | myLCD.set_orientation((++orient)%4); |
Geremia | 0:2ccd65a72ab8 | 155 | } |
Geremia | 0:2ccd65a72ab8 | 156 | } |