Frank Vannieuwkerke / Mbed 2 deprecated LPC1768_Mini-DK

Dependencies:   Mini-DK mbed SDFileSystem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 This file contains 3 examples:
00003 
00004 ONE   : Original example with paint demo.
00005 TWO   : Example for displaying a bitmap read from SD card.
00006         Download the house.bmp bitmap file from http://mbed.org/media/uploads/frankvnk/house.bmp
00007         Copy this file to the root of an SD card, insert it into the Mini-DK.
00008 THREE : Example for copying a bitmap from SD to flash memory, use it as background and
00009         write text without disrupting the background image.
00010         Download the house.bmp bitmap file from http://mbed.org/media/uploads/frankvnk/house.bmp
00011         Copy this file to the root of an SD card, insert it into the Mini-DK.
00012 
00013 IMPORTANT:
00014 If copy to flash option is not needed - enable //#define NO_FLASH_BUFFER in Mini_DK.h
00015 
00016 
00017 UNCOMMENT THE DESIRED CODE TO TEST.
00018 
00019 */
00020 
00021 // =========================================================================================================
00022 // ================================================== ONE ==================================================
00023 // =========================================================================================================
00024 #include "stdio.h"
00025 #include "mbed.h"
00026 #include "Mini_DK.h"
00027 
00028 extern unsigned char p1[];  // the mbed logo
00029 #define RGB565CONVERT(red, green, blue) (uint16_t)( (( red   >> 3 ) << 11 ) | (( green >> 2 ) << 5  ) | ( blue  >> 3 ))
00030 
00031 DigitalOut led(DK_LED1);
00032 // TFT -> mosi, miso, sclk, cs
00033 SPI_TFT TFT(LCD_SDI, LCD_SDO, LCD_SCK, LCD_CS,"TFT");
00034 // ADS7843 -> mosi, miso, sclk, cs, irq, SPI_TFT
00035 TouchScreenADS7843 TP(TP_SDI ,TP_SDO ,TP_SCK ,TP_CS ,TP_IRQ, &TFT);
00036 
00037 int main()
00038 {
00039     // Structs for storing touchpanel calibration data.
00040     // Can be written to external storage (eg : eeprom),
00041     // read back on startup and written to the touchpanel.
00042     // As a result, the real calibration only needs to be done once.
00043     Matrix matrix;
00044     Coordinate ScreenSample[3];
00045 
00046     unsigned short LCD_id;
00047     TFT.claim(stdout);        // send stdout to the TFT display
00048     // Disable stdout buffering, allows us to omit \n with printf.
00049     // More info at http://www.cplusplus.com/reference/cstdio/setvbuf/
00050     setvbuf ( stdout , NULL , _IONBF , NULL );
00051 
00052     TFT.background(Black);    // set background to black
00053     TFT.foreground(White);    // set chars to white
00054 
00055 
00056     // LCD demo
00057     // first show the 4 directions
00058     TFT.cls();
00059     TFT.set_font((unsigned char*) Arial12x12);
00060     TFT.set_orientation(0);
00061     TFT.locate(0,0);
00062     printf("  Hello Mbed 0");
00063     TFT.set_orientation(1);
00064     TFT.locate(0,0);
00065     printf("  Hello Mbed 1");
00066     TFT.set_orientation(2);
00067     TFT.locate(0,0);
00068     printf("  Hello Mbed 2");
00069     TFT.set_orientation(3);
00070     TFT.locate(0,0);
00071     printf("  Hello Mbed 3");
00072     TFT.set_orientation(1);
00073     TFT.set_font((unsigned char*) Arial24x23);
00074     TFT.locate(50,100);
00075     printf("TFT orientation");
00076 
00077     wait(2);
00078 
00079     // draw some graphics
00080     TFT.cls();
00081     TFT.set_orientation(1);
00082     TFT.set_font((unsigned char*) Arial24x23);
00083     TFT.locate(120,115);
00084     printf("Graphic");
00085     TFT.line(0,0,100,200,Green);
00086     TFT.rect(100,50,50,50,Red);
00087     TFT.fillrect(180,25,40,45,Blue);
00088     TFT.draw_ellipse(80, 150, 33, 33, White);
00089     TFT.fill_ellipse(80, 50, 33, 33, White);
00090     wait(2);
00091     TFT.cls();
00092     TFT.draw_ellipse(160, 120, 100, 50, Yellow);
00093     TFT.draw_ellipse(160, 120, 100, 100, Blue);
00094     TFT.fill_ellipse(160, 120, 80, 40, Green);
00095     wait(2);
00096 
00097     // bigger text
00098     TFT.foreground(White);
00099     TFT.background(Blue);
00100     TFT.cls();
00101     TFT.set_font((unsigned char*) Arial24x23);
00102     TFT.locate(0,0);
00103     printf("Different Fonts :");
00104 
00105     TFT.set_font((unsigned char*) Neu42x35);
00106     TFT.locate(0,50);
00107     printf("Hello");
00108     TFT.set_font((unsigned char*) Arial24x23);
00109     TFT.locate(50,100);
00110     printf("Hello");
00111     TFT.set_font((unsigned char*) Arial12x12);
00112     TFT.locate(55,150);
00113     printf("Hello");
00114 
00115     TFT.set_orientation(2);
00116     TFT.set_font((unsigned char*) Arial24x23);
00117     TFT.locate(10,10);
00118     printf("Hi mbed");
00119     wait(2);
00120 
00121     // mbed logo
00122     TFT.set_orientation(1);
00123     TFT.background(Black);
00124     TFT.cls();
00125     TFT.Bitmap(90,90,172,55,p1);
00126 
00127     // Read LCD ID
00128     TFT.set_orientation(0);
00129     LCD_id = TFT.Read_ID();
00130     TFT.locate(10,10);
00131     printf("LCD: ILI%04X", LCD_id);
00132     wait(2);
00133 
00134     // RGB color wheel demo (cycle through all colors)
00135     TFT.cls();
00136     TFT.foreground(Yellow);    // set chars to yellow
00137     TFT.set_font((unsigned char*) Arial12x12);
00138     TFT.locate(10,10);
00139     printf("RGB color wheel (2x)");
00140 
00141     uint8_t r = 255, g = 0,  b = 0, step = 1, i;
00142     for (i=0;i<2;i++)
00143     {
00144         for(;g<255;g+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from FF0000 to FFFF00 : red to yellow
00145         for(;r>0;r-=step)   {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from FFFF00 to 00FF00 : yellow to green
00146         for(;b<255;b+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from 00FF00 to 00FFFF : green to cyan
00147         for(;g>0;g-=step)   {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from 00FFFF to 0000FF : cyan to blue
00148         for(;r<255;r+=step) {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from 0000FF to FF00FF : blue to purple
00149         for(;b>0;b-=step)   {TFT.fillrect(70,110,100,100,RGB565CONVERT(r, g, b));}      // Cycle from FF00FF to FF0000 : purple to red
00150     }
00151     wait(2);
00152 
00153     // Touchpanel demo
00154     TP.TouchPanel_Calibrate();
00155     TFT.set_font((unsigned char*) Arial12x12);
00156     TFT.set_orientation(0);
00157 
00158     TFT.cls();
00159     TFT.locate(0,20);
00160     // read calibration results
00161     TP.GetCalibration(&matrix, &ScreenSample[0]);
00162     printf("Read calibration results.\n");
00163     printf("matrix.An = %d\n", matrix.An);
00164     printf("matrix.Bn = %d\n", matrix.Bn);
00165     printf("matrix.Cn = %d\n", matrix.Cn);
00166     printf("matrix.Dn = %d\n", matrix.Dn);
00167     printf("matrix.En = %d\n", matrix.En);
00168     printf("matrix.Fn = %d\n", matrix.Fn);
00169     printf("matrix.Di = %d\n", matrix.Divider);
00170     for (i=0;i<3;i++)
00171         printf("sample x[%d] = %d\nsample y[%d] = %d\n", i, ScreenSample[i].x, i, ScreenSample[i].y);
00172     // Write calibration results
00173     printf("\nWrite calibration results...\n");
00174     TP.SetCalibration(&matrix, &ScreenSample[0]);
00175     printf("Done.\nTouch panel to read again.\n");
00176     while(TP._tp_irq);
00177     // read calibration results
00178     TFT.cls();
00179     TFT.locate(0,20);
00180     printf("Calibration results.\n\n");
00181     printf("matrix.An = %d\n", matrix.An);
00182     printf("matrix.Bn = %d\n", matrix.Bn);
00183     printf("matrix.Cn = %d\n", matrix.Cn);
00184     printf("matrix.Dn = %d\n", matrix.Dn);
00185     printf("matrix.En = %d\n", matrix.En);
00186     printf("matrix.Fn = %d\n", matrix.Fn);
00187     printf("matrix.Di = %d\n", matrix.Divider);
00188     for (i=0;i<3;i++)
00189         printf("sample x[%d] = %d\nsample y[%d] = %d\n", i, ScreenSample[i].x, i, ScreenSample[i].y);
00190 
00191     TFT.locate(0,0);
00192     printf(" X:");
00193     TFT.locate(70,0);
00194     printf(" Y:");
00195     while (1)
00196     {
00197         if (!TP._tp_irq)
00198         {
00199             if (TP.Read_Ads7843())
00200             {
00201                 TP.getDisplayPoint() ;
00202                 TP.TP_DrawPoint(TP.display.x,TP.display.y, Blue);
00203                 TFT.locate(25,0);
00204                 printf("%03d",TP.display.x);
00205                 TFT.locate(95,0);
00206                 printf("%03d",TP.display.y);
00207                 // Touchscreen area is larger than LCD area.
00208                 // We use the bottom area outside the LCD area to clear the screen (y value > 320).
00209                 if (TP.display.y > 320)
00210                 {
00211                     TFT.cls();
00212                     TFT.locate(0,0);
00213                     printf(" X:");
00214                     TFT.locate(70,0);
00215                     printf(" Y:");
00216                 }
00217             }
00218         }
00219     }
00220 }
00221 
00222 /*
00223 // =========================================================================================================
00224 // ================================================== TWO ==================================================
00225 // =========================================================================================================
00226 
00227 #include "stdio.h"
00228 #include "mbed.h"
00229 #include "SDFileSystem.h"
00230 #include "Mini_DK.h"
00231 
00232 // SD card
00233 SDFileSystem sd(SD_SDI, SD_SDO, SD_SCK, SD_CS, "sd");
00234 // TFT -> mosi, miso, sclk, cs
00235 SPI_TFT TFT(LCD_SDI, LCD_SDO, LCD_SCK, LCD_CS,"TFT");
00236 // ADS7843 -> mosi, miso, sclk, cs, irq, SPI_TFT
00237 TouchScreenADS7843 TP(TP_SDI ,TP_SDO ,TP_SCK ,TP_CS ,TP_IRQ, &TFT);
00238 
00239 int main()
00240 {
00241     TFT.background(Black);    // set background to black
00242     TFT.foreground(White);    // set chars to white
00243 
00244     TFT.claim(stdout);        // send stdout to the TFT display
00245     // Disable stdout buffering, allows us to omit \n with printf.
00246     // More info at http://www.cplusplus.com/reference/cstdio/setvbuf/
00247     setvbuf ( stdout , NULL , _IONBF , NULL );
00248 
00249     TFT.cls();
00250     TFT.set_font((unsigned char*) Arial12x12);
00251     TFT.set_orientation(1);
00252 
00253     DISABLE_LCD_MISO;
00254     int dummy = TFT.Bitmap(0,0,"/sd/house.bmp");
00255     ENABLE_LCD_MISO;
00256     TFT.locate(0,0);
00257     printf("%02d",dummy); 
00258 }
00259 */
00260 
00261 /*
00262 // =========================================================================================================
00263 // ================================================= THREE =================================================
00264 // =========================================================================================================
00265 
00266 #include "stdio.h"
00267 #include "mbed.h"
00268 #include "SDFileSystem.h"
00269 #include "Mini_DK.h"
00270  
00271 // SD card
00272 SDFileSystem sd(SD_SDI, SD_SDO, SD_SCK, SD_CS, "sd");
00273 // TFT -> mosi, miso, sclk, cs
00274 SPI_TFT TFT(LCD_SDI, LCD_SDO, LCD_SCK, LCD_CS,"TFT");
00275 // ADS7843 -> mosi, miso, sclk, cs, irq, SPI_TFT
00276 TouchScreenADS7843 TP(TP_SDI ,TP_SDO ,TP_SCK ,TP_CS ,TP_IRQ, &TFT);
00277 
00278 
00279 Timer timer;
00280  
00281 int main()
00282 {
00283     DISABLE_LCD_MISO;
00284     TFT.background(Black);    // set background to black
00285     TFT.foreground(White);    // set chars to white
00286  
00287     TFT.claim(stdout);        // send stdout to the TFT display
00288     // Disable stdout buffering, allows us to omit \n with printf.
00289     // More info at http://www.cplusplus.com/reference/cstdio/setvbuf/
00290     setvbuf ( stdout , NULL , _IONBF , NULL );
00291 
00292     TFT.cls();
00293     TFT.set_font((unsigned char*) Arial12x12);
00294     TFT.set_orientation(1);
00295     
00296     TFT.locate(0,200);
00297     printf("Loading from SD...");
00298     TFT.Bitmap(0,0,"/sd/house.bmp");
00299     
00300     TFT.locate(0,0);
00301     printf("Copying to flash...");
00302     TFT.fileToFlash("/sd/house.bmp");
00303     TFT.locate(0,40);
00304     printf("Done: CLS in 2 seconds");
00305     wait(2);
00306     TFT.backgroundImage(false);
00307     TFT.cls();
00308     wait(2);
00309     TFT.backgroundImage(true);
00310    
00311     
00312     timer.reset();
00313     timer.start();
00314     TFT.cls();
00315     timer.stop();
00316     TFT.foreground(Black);
00317     TFT.locate(0,200);
00318     printf("Wrote background in %d ms",timer.read_ms());
00319     TFT.foreground(Black);
00320 
00321     TFT.set_orientation(3);
00322     TFT.locate(0,200);
00323     printf("Wrote background in %d ms",timer.read_ms());
00324 
00325     wait(5);
00326     TFT.cls();
00327     TFT.set_font((unsigned char*) Neu42x35);
00328     TFT.locate(0,50);
00329     printf("Orient = 3");
00330     TFT.set_orientation(0);
00331     TFT.locate(0,50);
00332     printf("Orient = 0");
00333     wait(5);
00334 
00335     TFT.set_orientation(0);
00336     TFT.cls();
00337     TFT.locate(0,50);
00338     printf("Orient = 0");
00339     
00340     while(1);
00341 }
00342 */