LCD example for NXP Rapid IoT Prototyping kit using hexiwear SDK. Read more at https://www.hackster.io/marcomerli/riotwear-mbed-2b2011.

Dependencies:   GraphicsDisplay ColorMemLCD Large_fonts

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