Whitworth-EN173-Resources / Mbed 2 deprecated DisplayModule24_demo

Dependencies:   DmTouch_UniGraphic UniGraphic mbed

Fork of DisplayModule24_demo by Whitworth-EN173-2016

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Do not publish changes to this program back to the remote repository.  Fork your own copy, or else */
00002 #include "stdio.h"
00003 #include "mbed.h"
00004 #include "string"
00005 #include "ILI932x.h"
00006 #include "DmTouch.h"
00007 
00008 
00009 #include "Arial12x12.h"
00010 #include "Arial24x23.h"
00011 #include "pavement_48x34.h"
00012 
00013 Serial pc(USBTX, USBRX);
00014 
00015 /* Configure the DisplayModule ILI9325 2.4" display for 8-bit bus communication
00016 
00017     mbed pin    display pin
00018     --------    -----------
00019     p15         CS (L15)
00020     p17         RST (L17)
00021     p16         RS (L4)
00022     p14         WR (L5)
00023     p20         RD (L6)
00024     
00025     p30         DB8 (L7)
00026     p29         DB9 (L8)
00027     p28         DB10 (L9)
00028     p27         DB11 (L10)
00029     p26         DB12 (L11)
00030     p25         DB13 (L12)
00031     p24         DB14 (L13)
00032     p23         DB15 (L14)
00033     
00034     p1          GND (L1)
00035     p40         Vin (L2)
00036     p40         LED Backlight (L19)
00037 */  
00038 PinName dataBus[]= {p30, p29, p28, p27, p26, p25, p24, p23};
00039 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
00040 
00041 /* Additional connections to add touch response
00042 
00043     mbed pin    display pin
00044     --------    -----------
00045     p5          T_MOSI (R11)
00046     p6          T_MISO (R13)
00047     p7          T_CLK (R9)
00048     p8          T_CS (R10)
00049     p9          T_IRQ (R14)
00050 */
00051 DmTouch touch(DmTouch::DM_TFT24_104, p5, p6, p7, p8, p9);
00052 
00053 char orient=3;
00054 int x,y;
00055 uint16_t tx, ty;
00056 Timer t;
00057 
00058 int main()
00059 {
00060     bool down, lastDown;
00061     touch.init();
00062     t.start();
00063     myLCD.set_orientation(orient);
00064     myLCD.set_font((unsigned char*) Arial24x23);
00065     myLCD.background(Blue);    // set background to Blue
00066     myLCD.foreground(White);    // set chars to White
00067     myLCD.cls();                // clear the screen
00068     myLCD.locate(10,30);
00069     myLCD.printf("UniGraphics Demo\r\n");
00070     wait(2);
00071     
00072     while(1)
00073     {
00074         myLCD.cls();  // clear the screen
00075         myLCD.set_font((unsigned char*) Arial24x23);
00076         myLCD.locate(0,30);
00077         myLCD.printf("Orientation mode: %x\r\n", orient%4);
00078         wait(2);
00079         myLCD.printf("Font is\r\n");
00080         myLCD.printf("Arial24x23\r\n");
00081         wait(2);
00082         
00083         myLCD.background(Black);
00084         myLCD.foreground(White);
00085         myLCD.cls();                // clear the screen
00086         myLCD.set_font((unsigned char*) Arial12x12);
00087         myLCD.locate(0,10);
00088         myLCD.printf("Font changed to Arial12x12\r\n");
00089         myLCD.printf("Background and foreground color also changed.\n\r\n\r");
00090         wait(2);
00091         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");
00092         wait(2);
00093         myLCD.set_font((unsigned char*) Terminal6x8);
00094         myLCD.printf("Font changed to Terminal6x8\r\n");
00095         myLCD.printf("This is pretty small!\r\n");
00096         wait(2);
00097         
00098         myLCD.cls();
00099         myLCD.set_font((unsigned char*) Arial24x23);
00100         myLCD.locate(10,10);
00101         myLCD.printf("Draw lines\n\r");
00102         myLCD.line(0,50,myLCD.width()-1,50,Yellow);
00103         myLCD.line(myLCD.width()-50,51,myLCD.width()-50,myLCD.height()-1,Green);
00104         wait(2);        
00105         
00106         myLCD.cls();
00107         myLCD.locate(10,10);
00108         myLCD.printf("Draw rectangles");
00109         myLCD.rect(10,50,50,80,Red);
00110         myLCD.rect(15,55,45,75,Red);
00111         myLCD.rect(20,60,40,70,Red);
00112         myLCD.fillrect(160,130,200,240,Blue);
00113         wait(2);
00114         
00115         myLCD.cls();
00116         myLCD.locate(10,10);
00117         myLCD.printf("Draw circles");
00118         myLCD.circle(150,132,30,Yellow);
00119         myLCD.fillcircle(140,70,25,Cyan);
00120         wait(2);
00121         
00122         myLCD.cls();
00123         myLCD.set_font((unsigned char*) Arial12x12);
00124         myLCD.locate(10,10);
00125         myLCD.printf("Draw function with pixels");
00126         double s;
00127         for (unsigned short i=0; i<myLCD.width(); i++)
00128         {
00129         s =10 * sin((long double) i / 10 );
00130         myLCD.pixel(i,80 + (int)s ,White);
00131         }
00132         wait(3);
00133         
00134         // Touch screen demo
00135         myLCD.background(Blue);    // set background to Blue
00136         myLCD.foreground(White);    // set chars to White
00137         myLCD.cls();                // clear the screen
00138         myLCD.locate(10,30);
00139         myLCD.set_font((unsigned char*) Arial24x23);
00140         myLCD.printf("DmTouch Demo\r\n");
00141         myLCD.set_font((unsigned char*) Arial12x12);
00142         myLCD.locate(10,70);
00143         myLCD.printf("Coming soon...\r\nTouch screen and coordinates will display\r\n");
00144         myLCD.printf("Moves to next portion of demo after 30 seconds\r\n");
00145         wait(2);
00146         myLCD.background(Black);    // set background to Black
00147         myLCD.foreground(White);    // set chars to White
00148         myLCD.cls();                // clear the screen
00149 
00150         touch.setOrientation(orient);
00151         down = false;
00152         lastDown = false;
00153         tx = (uint16_t)0;
00154         ty = (uint16_t)0;
00155         myLCD.locate(20,20);
00156         myLCD.printf("x:");
00157         myLCD.locate(100, 20);
00158         myLCD.printf("y:");
00159 
00160         t.reset();
00161         while (t.read()<30) {
00162             touch.readTouchData(tx, ty, down);
00163             if (down) {
00164                 myLCD.locate(40, 20);
00165                 myLCD.printf("%5i", tx);
00166                 myLCD.locate(120, 20);
00167                 myLCD.printf("%5i", ty);
00168                 myLCD.fillcircle(tx, ty, 2, Red);
00169             } else if (lastDown) {
00170                 // no longer pressed, clean text
00171                 myLCD.locate(40, 20);
00172                 myLCD.printf("     ", tx);
00173                 myLCD.locate(120, 20);
00174                 myLCD.printf("     ", ty);
00175             }
00176             wait(0.040);
00177             lastDown = down;
00178           }
00179         
00180         
00181     // scroll test, only for TFT
00182     myLCD.cls();
00183     myLCD.set_font((unsigned char*) Arial24x23);
00184     myLCD.locate(2,10);
00185     myLCD.printf("Scrolling");
00186     myLCD.rect(0,0,myLCD.width()-1,myLCD.height()-1,White);
00187     myLCD.rect(1,1,myLCD.width()-2,myLCD.height()-2,Blue);
00188     myLCD.setscrollarea(0,myLCD.sizeY());
00189     wait(1);
00190     myLCD.scroll(1); //up 1
00191     wait(1);
00192     myLCD.scroll(0); //center
00193     wait(1);
00194     myLCD.scroll(myLCD.sizeY()-1); //down 1
00195     wait(1);
00196     myLCD.scroll(myLCD.sizeY()); // same as 0, center
00197     wait(1);
00198     myLCD.scroll(myLCD.sizeY()>>1); // half screen
00199     wait(1);
00200     myLCD.scrollreset(); // center
00201     wait(1);
00202     for(unsigned short i=1; i<=myLCD.sizeY(); i++)
00203     {
00204         myLCD.scroll(i);
00205         wait_ms(2);
00206     }
00207     wait(2);
00208     // color inversion
00209     for(unsigned short i=0; i<=8; i++)
00210     {
00211         myLCD.invert(i&1);
00212         wait_ms(200);
00213     }
00214     wait(2);
00215     // bmp 16bit test
00216     myLCD.cls();
00217     for(int y=0; y<myLCD.height(); y+=34)
00218     {
00219         for(int x=0; x<myLCD.width(); x+=48) myLCD.Bitmap(x,y,48,34,(unsigned char *)pavement_48x34);
00220     }
00221     wait(2);
00222     myLCD.set_orientation((++orient)%4);
00223     }
00224 }