An example program of displaying color bitmaps or characters on Color Memory LCD.

Dependencies:   ColorMemLCD GraphicsDisplay Large_fonts SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "stdio.h"
00002 #include "mbed.h"
00003 #include "ColorMemLCD.h"
00004 //#include "SDFileSystem.h"
00005 
00006 #include "string"
00007 #include "Prototype24x27.h"
00008 #include "Prototype_num21x25.h"
00009 //#include "meirio_num11x14.h"
00010 
00011 #include "bmp_caterpillar_4bit.h"
00012 #include "bmp_leaf_4bit.h"
00013 #include "bmp_watch_4bit.h"
00014 
00015 #include "symb_block.h"
00016 #include "symb_block_rev.h"
00017 
00018 //SDFileSystem        sd( PTE3, PTE1, PTE2, PTE4, "sd" );          // mosi,miso,sck,cs
00019 ColorMemLCD    LCD( PTD2, PTD3, PTD1, PTD0, PTC4, PTD3, "TFT" );   // mosi, miso, sclk, cs, reset, (power)
00020 Ticker pollingTimer;
00021 
00022 void pollingTimerHandler()
00023 {
00024     LCD.polling();
00025 }
00026 
00027 int main()
00028 {
00029     int i,j,k;
00030     int pic_height, window_height;
00031     int Divide = 8;                // separate for 8 windows to save memory
00032     int Block = LCD_DISP_HEIGHT / Divide; 
00033 
00034     pollingTimer.attach( &pollingTimerHandler, 1.0 );
00035     LCD.command_AllClear();
00036     
00037     /*  SD read  */
00038     //LCD.BMP_24(0,0,"/sd/sample.bmp");
00039 
00040     while(1) {
00041         
00042         /* Turn white - whole the screen */
00043         LCD.background( LCD_COLOR_WHITE );
00044         for(j = 0 ; j <Divide ; j++) {
00045             LCD.window(0, j*Block, LCD_DISP_WIDTH, Block);
00046             LCD.cls();
00047             LCD.update();
00048         }
00049 
00050         /* Hello */
00051         pic_height = 44;
00052         window_height = 44; 
00053         LCD.foreground( LCD_COLOR_GREEN );
00054         LCD.window( 0, 10, LCD_DISP_WIDTH, window_height);
00055         LCD.cls();
00056         LCD.Bitmap4bit(82, 10, 88, pic_height, (unsigned char *)bmp_caterpillar_4bit);
00057         LCD.locate(4, 10);
00058         LCD.set_font( (unsigned char*)Prototype24x27 );
00059         LCD.printf("Hello");
00060         LCD.update();
00061         wait(0.8);      
00062 
00063         /* world */  
00064         pic_height = 88;
00065         window_height = 44; 
00066         LCD.window(0, 132, LCD_DISP_WIDTH, pic_height);
00067         LCD.cls();
00068         LCD.locate(92, 148);
00069         LCD.set_font( (unsigned char*)Prototype24x27 );
00070         LCD.printf("world");
00071         LCD.update();
00072         for(j=0; j<pic_height/window_height; j++){
00073             LCD.window( 0, 60+j*window_height, LCD_DISP_WIDTH, window_height);
00074             LCD.Bitmap4bit( 0, 60, 176, pic_height, (unsigned char *)bmp_leaf_4bit );
00075             LCD.update();
00076         }
00077         wait(0.8);
00078         
00079         LCD.fillcircle(  40, 136, 18, LCD_COLOR_WHITE );
00080         LCD.update();
00081         wait(1); 
00082         LCD.fillcircle( 160, 122, 12, LCD_COLOR_WHITE );
00083         LCD.update();
00084         wait(0.2); 
00085         LCD.fillcircle( 120, 132, 14, LCD_COLOR_WHITE );
00086         LCD.update();   
00087         wait(1); 
00088                 
00089         LCD.setBlinkMode( LCD_BLINKMODE_INVERSE );
00090         wait(0.2); 
00091         LCD.setBlinkMode( LCD_BLINKMODE_NONE );
00092         wait(0.2);        
00093        
00094         /*  Cube  */
00095         LCD.background( LCD_COLOR_WHITE);        
00096         for(k=0; k<7; k++){ // 6 times
00097             for(j=0; j<Divide; j++){
00098                 LCD.window(0, j*Block, LCD_DISP_WIDTH, Block);
00099                 for(i=0; i<4; i++){
00100                     LCD.foreground( ((j+1+ k*(i*5))%6 +1) << 1 );  // except White & Black  ( )%6 +1                    
00101                     if((j+k)%2) LCD.symbol( i*44, j*Block, (unsigned char *)symb_block );
00102                     else        LCD.symbol( i*44, j*Block, (unsigned char *)symb_block_rev );
00103                 }
00104                 LCD.update();
00105             }
00106             wait(0.2);
00107             LCD.setBlinkMode( LCD_BLINKMODE_INVERSE );
00108             wait(0.2); 
00109             LCD.setBlinkMode( LCD_BLINKMODE_NONE );
00110             wait(0.2);     
00111         }
00112         wait(0.5); 
00113            
00114         /*  Watch  */
00115         LCD.background( LCD_COLOR_WHITE); 
00116         for(j=0; j<Divide; j++){
00117             LCD.window(0, j*Block, LCD_DISP_WIDTH, Block);
00118             LCD.Bitmap4bit( 0, 0, 176, 176, (unsigned char *)bmp_watch_4bit );
00119             LCD.update();
00120         }
00121         LCD.foreground( LCD_COLOR_BLUE );
00122         LCD.window( 0, 54, LCD_DISP_WIDTH, 25);
00123         LCD.Bitmap4bit( 0, 0, 176, 176, (unsigned char *)bmp_watch_4bit ); // window back screen
00124         LCD.set_font( (unsigned char*)Prototype_num21x25 );
00125         LCD.locate(22, 54);        
00126         LCD.printf("10:");
00127         for(k=0; k<40;k++){
00128             LCD.locate(72, 54);        
00129             LCD.printf("%02d",k+20);
00130             LCD.update();
00131             wait((double)exp((double)(-k/3))); // time constant =3
00132         }
00133     }
00134 }