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
main.cpp@0:375bc0c22bf6, 2016-06-23 (annotated)
- Committer:
- KURETA90
- Date:
- Thu Jun 23 02:26:44 2016 +0000
- Revision:
- 0:375bc0c22bf6
- Child:
- 2:25d611652243
An example program of displaying color bitmaps or characters on Color Memory LCD.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KURETA90 | 0:375bc0c22bf6 | 1 | #include "stdio.h" |
KURETA90 | 0:375bc0c22bf6 | 2 | #include "mbed.h" |
KURETA90 | 0:375bc0c22bf6 | 3 | #include "ColorMemLCD.h" |
KURETA90 | 0:375bc0c22bf6 | 4 | //#include "SDFileSystem.h" |
KURETA90 | 0:375bc0c22bf6 | 5 | |
KURETA90 | 0:375bc0c22bf6 | 6 | #include "string" |
KURETA90 | 0:375bc0c22bf6 | 7 | #include "Prototype24x27.h" |
KURETA90 | 0:375bc0c22bf6 | 8 | #include "Prototype_num21x25.h" |
KURETA90 | 0:375bc0c22bf6 | 9 | //#include "meirio_num11x14.h" |
KURETA90 | 0:375bc0c22bf6 | 10 | |
KURETA90 | 0:375bc0c22bf6 | 11 | #include "bmp_caterpillar_4bit.h" |
KURETA90 | 0:375bc0c22bf6 | 12 | #include "bmp_leaf_4bit.h" |
KURETA90 | 0:375bc0c22bf6 | 13 | #include "bmp_watch_4bit.h" |
KURETA90 | 0:375bc0c22bf6 | 14 | |
KURETA90 | 0:375bc0c22bf6 | 15 | #include "symb_block.h" |
KURETA90 | 0:375bc0c22bf6 | 16 | #include "symb_block_rev.h" |
KURETA90 | 0:375bc0c22bf6 | 17 | |
KURETA90 | 0:375bc0c22bf6 | 18 | //SDFileSystem sd( PTE3, PTE1, PTE2, PTE4, "sd" ); // mosi,miso,sck,cs |
KURETA90 | 0:375bc0c22bf6 | 19 | ColorMemLCD LCD( PTD2, PTD3, PTD1, PTD0, PTC4, PTD3, "TFT" ); // mosi, miso, sclk, cs, reset, (power) |
KURETA90 | 0:375bc0c22bf6 | 20 | Ticker pollingTimer; |
KURETA90 | 0:375bc0c22bf6 | 21 | |
KURETA90 | 0:375bc0c22bf6 | 22 | void pollingTimerHandler() |
KURETA90 | 0:375bc0c22bf6 | 23 | { |
KURETA90 | 0:375bc0c22bf6 | 24 | LCD.polling(); |
KURETA90 | 0:375bc0c22bf6 | 25 | } |
KURETA90 | 0:375bc0c22bf6 | 26 | |
KURETA90 | 0:375bc0c22bf6 | 27 | int main() |
KURETA90 | 0:375bc0c22bf6 | 28 | { |
KURETA90 | 0:375bc0c22bf6 | 29 | int i,j,k; |
KURETA90 | 0:375bc0c22bf6 | 30 | int pic_height, window_height; |
KURETA90 | 0:375bc0c22bf6 | 31 | int Divide = 8; // separate for 8 windows to save memory |
KURETA90 | 0:375bc0c22bf6 | 32 | int Block = LCD_DISP_HEIGHT / Divide; |
KURETA90 | 0:375bc0c22bf6 | 33 | |
KURETA90 | 0:375bc0c22bf6 | 34 | pollingTimer.attach( &pollingTimerHandler, 1.0 ); |
KURETA90 | 0:375bc0c22bf6 | 35 | LCD.command_AllClear(); |
KURETA90 | 0:375bc0c22bf6 | 36 | |
KURETA90 | 0:375bc0c22bf6 | 37 | /* SD read */ |
KURETA90 | 0:375bc0c22bf6 | 38 | //LCD.BMP_24(0,0,"/sd/sample.bmp"); |
KURETA90 | 0:375bc0c22bf6 | 39 | |
KURETA90 | 0:375bc0c22bf6 | 40 | while(1) { |
KURETA90 | 0:375bc0c22bf6 | 41 | |
KURETA90 | 0:375bc0c22bf6 | 42 | /* Turn white - whole the screen */ |
KURETA90 | 0:375bc0c22bf6 | 43 | LCD.background( LCD_COLOR_WHITE ); |
KURETA90 | 0:375bc0c22bf6 | 44 | for(j = 0 ; j <Divide ; j++) { |
KURETA90 | 0:375bc0c22bf6 | 45 | LCD.window(0, j*Block, LCD_DISP_WIDTH, Block); |
KURETA90 | 0:375bc0c22bf6 | 46 | LCD.cls(); |
KURETA90 | 0:375bc0c22bf6 | 47 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 48 | } |
KURETA90 | 0:375bc0c22bf6 | 49 | |
KURETA90 | 0:375bc0c22bf6 | 50 | /* Hello */ |
KURETA90 | 0:375bc0c22bf6 | 51 | pic_height = 44; |
KURETA90 | 0:375bc0c22bf6 | 52 | window_height = 44; |
KURETA90 | 0:375bc0c22bf6 | 53 | LCD.foreground( LCD_COLOR_GREEN ); |
KURETA90 | 0:375bc0c22bf6 | 54 | LCD.window( 0, 10, LCD_DISP_WIDTH, window_height); |
KURETA90 | 0:375bc0c22bf6 | 55 | LCD.cls(); |
KURETA90 | 0:375bc0c22bf6 | 56 | LCD.Bitmap4bit(82, 10, 88, pic_height, (unsigned char *)bmp_caterpillar_4bit); |
KURETA90 | 0:375bc0c22bf6 | 57 | LCD.locate(4, 10); |
KURETA90 | 0:375bc0c22bf6 | 58 | LCD.set_font( (unsigned char*)Prototype24x27 ); |
KURETA90 | 0:375bc0c22bf6 | 59 | LCD.printf("Hello"); |
KURETA90 | 0:375bc0c22bf6 | 60 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 61 | wait(0.8); |
KURETA90 | 0:375bc0c22bf6 | 62 | |
KURETA90 | 0:375bc0c22bf6 | 63 | /* world */ |
KURETA90 | 0:375bc0c22bf6 | 64 | pic_height = 88; |
KURETA90 | 0:375bc0c22bf6 | 65 | window_height = 44; |
KURETA90 | 0:375bc0c22bf6 | 66 | LCD.window(0, 132, LCD_DISP_WIDTH, pic_height); |
KURETA90 | 0:375bc0c22bf6 | 67 | LCD.cls(); |
KURETA90 | 0:375bc0c22bf6 | 68 | LCD.locate(92, 148); |
KURETA90 | 0:375bc0c22bf6 | 69 | LCD.set_font( (unsigned char*)Prototype24x27 ); |
KURETA90 | 0:375bc0c22bf6 | 70 | LCD.printf("world"); |
KURETA90 | 0:375bc0c22bf6 | 71 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 72 | for(j=0; j<pic_height/window_height; j++){ |
KURETA90 | 0:375bc0c22bf6 | 73 | LCD.window( 0, 60+j*window_height, LCD_DISP_WIDTH, window_height); |
KURETA90 | 0:375bc0c22bf6 | 74 | LCD.Bitmap4bit( 0, 60, 176, pic_height, (unsigned char *)bmp_leaf_4bit ); |
KURETA90 | 0:375bc0c22bf6 | 75 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 76 | } |
KURETA90 | 0:375bc0c22bf6 | 77 | wait(0.8); |
KURETA90 | 0:375bc0c22bf6 | 78 | |
KURETA90 | 0:375bc0c22bf6 | 79 | LCD.fillcircle( 40, 136, 18, LCD_COLOR_WHITE ); |
KURETA90 | 0:375bc0c22bf6 | 80 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 81 | wait(1); |
KURETA90 | 0:375bc0c22bf6 | 82 | LCD.fillcircle( 160, 122, 12, LCD_COLOR_WHITE ); |
KURETA90 | 0:375bc0c22bf6 | 83 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 84 | wait(0.2); |
KURETA90 | 0:375bc0c22bf6 | 85 | LCD.fillcircle( 120, 132, 14, LCD_COLOR_WHITE ); |
KURETA90 | 0:375bc0c22bf6 | 86 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 87 | wait(1); |
KURETA90 | 0:375bc0c22bf6 | 88 | |
KURETA90 | 0:375bc0c22bf6 | 89 | LCD.setBlinkMode( LCD_BLINKMODE_INVERSE ); |
KURETA90 | 0:375bc0c22bf6 | 90 | wait(0.2); |
KURETA90 | 0:375bc0c22bf6 | 91 | LCD.setBlinkMode( LCD_BLINKMODE_NONE ); |
KURETA90 | 0:375bc0c22bf6 | 92 | wait(0.2); |
KURETA90 | 0:375bc0c22bf6 | 93 | |
KURETA90 | 0:375bc0c22bf6 | 94 | /* Cube */ |
KURETA90 | 0:375bc0c22bf6 | 95 | LCD.background( LCD_COLOR_WHITE); |
KURETA90 | 0:375bc0c22bf6 | 96 | for(k=0; k<7; k++){ // 6 times |
KURETA90 | 0:375bc0c22bf6 | 97 | for(j=0; j<Divide; j++){ |
KURETA90 | 0:375bc0c22bf6 | 98 | LCD.window(0, j*Block, LCD_DISP_WIDTH, Block); |
KURETA90 | 0:375bc0c22bf6 | 99 | for(i=0; i<4; i++){ |
KURETA90 | 0:375bc0c22bf6 | 100 | LCD.foreground( ((j+1+ k*(i*5))%6 +1) << 1 ); // except White & Black ( )%6 +1 |
KURETA90 | 0:375bc0c22bf6 | 101 | if((j+k)%2) LCD.symbol( i*44, j*Block, (unsigned char *)symb_block ); |
KURETA90 | 0:375bc0c22bf6 | 102 | else LCD.symbol( i*44, j*Block, (unsigned char *)symb_block_rev ); |
KURETA90 | 0:375bc0c22bf6 | 103 | } |
KURETA90 | 0:375bc0c22bf6 | 104 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 105 | } |
KURETA90 | 0:375bc0c22bf6 | 106 | wait(0.2); |
KURETA90 | 0:375bc0c22bf6 | 107 | LCD.setBlinkMode( LCD_BLINKMODE_INVERSE ); |
KURETA90 | 0:375bc0c22bf6 | 108 | wait(0.2); |
KURETA90 | 0:375bc0c22bf6 | 109 | LCD.setBlinkMode( LCD_BLINKMODE_NONE ); |
KURETA90 | 0:375bc0c22bf6 | 110 | wait(0.2); |
KURETA90 | 0:375bc0c22bf6 | 111 | } |
KURETA90 | 0:375bc0c22bf6 | 112 | wait(0.5); |
KURETA90 | 0:375bc0c22bf6 | 113 | |
KURETA90 | 0:375bc0c22bf6 | 114 | /* Watch */ |
KURETA90 | 0:375bc0c22bf6 | 115 | LCD.background( LCD_COLOR_WHITE); |
KURETA90 | 0:375bc0c22bf6 | 116 | for(j=0; j<Divide; j++){ |
KURETA90 | 0:375bc0c22bf6 | 117 | LCD.window(0, j*Block, LCD_DISP_WIDTH, Block); |
KURETA90 | 0:375bc0c22bf6 | 118 | LCD.Bitmap4bit( 0, 0, 176, 176, (unsigned char *)bmp_watch_4bit ); |
KURETA90 | 0:375bc0c22bf6 | 119 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 120 | } |
KURETA90 | 0:375bc0c22bf6 | 121 | LCD.foreground( LCD_COLOR_BLUE ); |
KURETA90 | 0:375bc0c22bf6 | 122 | LCD.window( 0, 54, LCD_DISP_WIDTH, 25); |
KURETA90 | 0:375bc0c22bf6 | 123 | LCD.Bitmap4bit( 0, 0, 176, 176, (unsigned char *)bmp_watch_4bit ); // window back screen |
KURETA90 | 0:375bc0c22bf6 | 124 | LCD.set_font( (unsigned char*)Prototype_num21x25 ); |
KURETA90 | 0:375bc0c22bf6 | 125 | LCD.locate(22, 54); |
KURETA90 | 0:375bc0c22bf6 | 126 | LCD.printf("10:"); |
KURETA90 | 0:375bc0c22bf6 | 127 | for(k=0; k<40;k++){ |
KURETA90 | 0:375bc0c22bf6 | 128 | LCD.locate(72, 54); |
KURETA90 | 0:375bc0c22bf6 | 129 | LCD.printf("%02d",k+20); |
KURETA90 | 0:375bc0c22bf6 | 130 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 131 | wait((double)exp((double)(-k/3))); // time constant =3 |
KURETA90 | 0:375bc0c22bf6 | 132 | } |
KURETA90 | 0:375bc0c22bf6 | 133 | } |
KURETA90 | 0:375bc0c22bf6 | 134 | } |