
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@2:25d611652243, 2019-11-29 (annotated)
- Committer:
- batman52
- Date:
- Fri Nov 29 16:46:40 2019 +0000
- Revision:
- 2:25d611652243
- Parent:
- 0:375bc0c22bf6
LCD example for NXP Rapid IoT Prototyping kit, using hexiwear SDK
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 | |
KURETA90 | 0:375bc0c22bf6 | 5 | #include "string" |
KURETA90 | 0:375bc0c22bf6 | 6 | #include "Prototype24x27.h" |
KURETA90 | 0:375bc0c22bf6 | 7 | #include "Prototype_num21x25.h" |
KURETA90 | 0:375bc0c22bf6 | 8 | //#include "meirio_num11x14.h" |
KURETA90 | 0:375bc0c22bf6 | 9 | |
KURETA90 | 0:375bc0c22bf6 | 10 | #include "bmp_caterpillar_4bit.h" |
KURETA90 | 0:375bc0c22bf6 | 11 | #include "bmp_leaf_4bit.h" |
KURETA90 | 0:375bc0c22bf6 | 12 | #include "bmp_watch_4bit.h" |
KURETA90 | 0:375bc0c22bf6 | 13 | |
KURETA90 | 0:375bc0c22bf6 | 14 | #include "symb_block.h" |
KURETA90 | 0:375bc0c22bf6 | 15 | #include "symb_block_rev.h" |
KURETA90 | 0:375bc0c22bf6 | 16 | |
batman52 | 2:25d611652243 | 17 | DigitalOut lcd_light(PTE12, 1); // 1 = ON, 0 = OFF |
batman52 | 2:25d611652243 | 18 | // mosi, miso, sclk, cs, reset, power |
batman52 | 2:25d611652243 | 19 | ColorMemLCD LCD( PTB22, PTB23, PTB21, PTB20, PTD15, PTD9, "TFT"); |
batman52 | 2:25d611652243 | 20 | |
batman52 | 2:25d611652243 | 21 | #if(1) |
batman52 | 2:25d611652243 | 22 | #define WAIT_S(x) wait(x) |
batman52 | 2:25d611652243 | 23 | #else |
batman52 | 2:25d611652243 | 24 | #define WAIT_S(x) Thread::wait(x*1000) |
batman52 | 2:25d611652243 | 25 | #endif |
batman52 | 2:25d611652243 | 26 | |
KURETA90 | 0:375bc0c22bf6 | 27 | Ticker pollingTimer; |
KURETA90 | 0:375bc0c22bf6 | 28 | |
batman52 | 2:25d611652243 | 29 | /* |
KURETA90 | 0:375bc0c22bf6 | 30 | void pollingTimerHandler() |
KURETA90 | 0:375bc0c22bf6 | 31 | { |
KURETA90 | 0:375bc0c22bf6 | 32 | LCD.polling(); |
KURETA90 | 0:375bc0c22bf6 | 33 | } |
batman52 | 2:25d611652243 | 34 | */ |
KURETA90 | 0:375bc0c22bf6 | 35 | |
KURETA90 | 0:375bc0c22bf6 | 36 | int main() |
KURETA90 | 0:375bc0c22bf6 | 37 | { |
KURETA90 | 0:375bc0c22bf6 | 38 | int i,j,k; |
KURETA90 | 0:375bc0c22bf6 | 39 | int pic_height, window_height; |
KURETA90 | 0:375bc0c22bf6 | 40 | int Divide = 8; // separate for 8 windows to save memory |
KURETA90 | 0:375bc0c22bf6 | 41 | int Block = LCD_DISP_HEIGHT / Divide; |
KURETA90 | 0:375bc0c22bf6 | 42 | |
batman52 | 2:25d611652243 | 43 | // pollingTimer.attach( &pollingTimerHandler, 1.0 ); |
KURETA90 | 0:375bc0c22bf6 | 44 | LCD.command_AllClear(); |
KURETA90 | 0:375bc0c22bf6 | 45 | |
KURETA90 | 0:375bc0c22bf6 | 46 | while(1) { |
KURETA90 | 0:375bc0c22bf6 | 47 | |
KURETA90 | 0:375bc0c22bf6 | 48 | /* Turn white - whole the screen */ |
KURETA90 | 0:375bc0c22bf6 | 49 | LCD.background( LCD_COLOR_WHITE ); |
KURETA90 | 0:375bc0c22bf6 | 50 | for(j = 0 ; j <Divide ; j++) { |
KURETA90 | 0:375bc0c22bf6 | 51 | LCD.window(0, j*Block, LCD_DISP_WIDTH, Block); |
KURETA90 | 0:375bc0c22bf6 | 52 | LCD.cls(); |
KURETA90 | 0:375bc0c22bf6 | 53 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 54 | } |
KURETA90 | 0:375bc0c22bf6 | 55 | |
KURETA90 | 0:375bc0c22bf6 | 56 | /* Hello */ |
KURETA90 | 0:375bc0c22bf6 | 57 | pic_height = 44; |
KURETA90 | 0:375bc0c22bf6 | 58 | window_height = 44; |
KURETA90 | 0:375bc0c22bf6 | 59 | LCD.foreground( LCD_COLOR_GREEN ); |
KURETA90 | 0:375bc0c22bf6 | 60 | LCD.window( 0, 10, LCD_DISP_WIDTH, window_height); |
KURETA90 | 0:375bc0c22bf6 | 61 | LCD.cls(); |
KURETA90 | 0:375bc0c22bf6 | 62 | LCD.Bitmap4bit(82, 10, 88, pic_height, (unsigned char *)bmp_caterpillar_4bit); |
KURETA90 | 0:375bc0c22bf6 | 63 | LCD.locate(4, 10); |
KURETA90 | 0:375bc0c22bf6 | 64 | LCD.set_font( (unsigned char*)Prototype24x27 ); |
KURETA90 | 0:375bc0c22bf6 | 65 | LCD.printf("Hello"); |
KURETA90 | 0:375bc0c22bf6 | 66 | LCD.update(); |
batman52 | 2:25d611652243 | 67 | WAIT_S(0.8); |
KURETA90 | 0:375bc0c22bf6 | 68 | |
KURETA90 | 0:375bc0c22bf6 | 69 | /* world */ |
KURETA90 | 0:375bc0c22bf6 | 70 | pic_height = 88; |
KURETA90 | 0:375bc0c22bf6 | 71 | window_height = 44; |
KURETA90 | 0:375bc0c22bf6 | 72 | LCD.window(0, 132, LCD_DISP_WIDTH, pic_height); |
KURETA90 | 0:375bc0c22bf6 | 73 | LCD.cls(); |
KURETA90 | 0:375bc0c22bf6 | 74 | LCD.locate(92, 148); |
KURETA90 | 0:375bc0c22bf6 | 75 | LCD.set_font( (unsigned char*)Prototype24x27 ); |
KURETA90 | 0:375bc0c22bf6 | 76 | LCD.printf("world"); |
KURETA90 | 0:375bc0c22bf6 | 77 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 78 | for(j=0; j<pic_height/window_height; j++){ |
KURETA90 | 0:375bc0c22bf6 | 79 | LCD.window( 0, 60+j*window_height, LCD_DISP_WIDTH, window_height); |
KURETA90 | 0:375bc0c22bf6 | 80 | LCD.Bitmap4bit( 0, 60, 176, pic_height, (unsigned char *)bmp_leaf_4bit ); |
KURETA90 | 0:375bc0c22bf6 | 81 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 82 | } |
batman52 | 2:25d611652243 | 83 | WAIT_S(0.8); |
KURETA90 | 0:375bc0c22bf6 | 84 | |
KURETA90 | 0:375bc0c22bf6 | 85 | LCD.fillcircle( 40, 136, 18, LCD_COLOR_WHITE ); |
batman52 | 2:25d611652243 | 86 | LCD.update(); |
batman52 | 2:25d611652243 | 87 | WAIT_S(1); |
KURETA90 | 0:375bc0c22bf6 | 88 | LCD.fillcircle( 160, 122, 12, LCD_COLOR_WHITE ); |
batman52 | 2:25d611652243 | 89 | LCD.update(); |
batman52 | 2:25d611652243 | 90 | WAIT_S(0.2); |
KURETA90 | 0:375bc0c22bf6 | 91 | LCD.fillcircle( 120, 132, 14, LCD_COLOR_WHITE ); |
KURETA90 | 0:375bc0c22bf6 | 92 | LCD.update(); |
batman52 | 2:25d611652243 | 93 | WAIT_S(1); |
KURETA90 | 0:375bc0c22bf6 | 94 | |
batman52 | 2:25d611652243 | 95 | LCD.setBlinkMode( LCD_BLINKMODE_INVERSE ); |
batman52 | 2:25d611652243 | 96 | WAIT_S(0.2); |
KURETA90 | 0:375bc0c22bf6 | 97 | LCD.setBlinkMode( LCD_BLINKMODE_NONE ); |
batman52 | 2:25d611652243 | 98 | WAIT_S(0.2); |
KURETA90 | 0:375bc0c22bf6 | 99 | |
KURETA90 | 0:375bc0c22bf6 | 100 | /* Cube */ |
KURETA90 | 0:375bc0c22bf6 | 101 | LCD.background( LCD_COLOR_WHITE); |
KURETA90 | 0:375bc0c22bf6 | 102 | for(k=0; k<7; k++){ // 6 times |
KURETA90 | 0:375bc0c22bf6 | 103 | for(j=0; j<Divide; j++){ |
KURETA90 | 0:375bc0c22bf6 | 104 | LCD.window(0, j*Block, LCD_DISP_WIDTH, Block); |
KURETA90 | 0:375bc0c22bf6 | 105 | for(i=0; i<4; i++){ |
KURETA90 | 0:375bc0c22bf6 | 106 | LCD.foreground( ((j+1+ k*(i*5))%6 +1) << 1 ); // except White & Black ( )%6 +1 |
KURETA90 | 0:375bc0c22bf6 | 107 | if((j+k)%2) LCD.symbol( i*44, j*Block, (unsigned char *)symb_block ); |
KURETA90 | 0:375bc0c22bf6 | 108 | else LCD.symbol( i*44, j*Block, (unsigned char *)symb_block_rev ); |
KURETA90 | 0:375bc0c22bf6 | 109 | } |
KURETA90 | 0:375bc0c22bf6 | 110 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 111 | } |
batman52 | 2:25d611652243 | 112 | WAIT_S(0.2); |
KURETA90 | 0:375bc0c22bf6 | 113 | LCD.setBlinkMode( LCD_BLINKMODE_INVERSE ); |
batman52 | 2:25d611652243 | 114 | WAIT_S(0.2); |
KURETA90 | 0:375bc0c22bf6 | 115 | LCD.setBlinkMode( LCD_BLINKMODE_NONE ); |
batman52 | 2:25d611652243 | 116 | WAIT_S(0.2); |
KURETA90 | 0:375bc0c22bf6 | 117 | } |
batman52 | 2:25d611652243 | 118 | WAIT_S(0.5); |
KURETA90 | 0:375bc0c22bf6 | 119 | |
KURETA90 | 0:375bc0c22bf6 | 120 | /* Watch */ |
KURETA90 | 0:375bc0c22bf6 | 121 | LCD.background( LCD_COLOR_WHITE); |
KURETA90 | 0:375bc0c22bf6 | 122 | for(j=0; j<Divide; j++){ |
KURETA90 | 0:375bc0c22bf6 | 123 | LCD.window(0, j*Block, LCD_DISP_WIDTH, Block); |
KURETA90 | 0:375bc0c22bf6 | 124 | LCD.Bitmap4bit( 0, 0, 176, 176, (unsigned char *)bmp_watch_4bit ); |
KURETA90 | 0:375bc0c22bf6 | 125 | LCD.update(); |
KURETA90 | 0:375bc0c22bf6 | 126 | } |
KURETA90 | 0:375bc0c22bf6 | 127 | LCD.foreground( LCD_COLOR_BLUE ); |
KURETA90 | 0:375bc0c22bf6 | 128 | LCD.window( 0, 54, LCD_DISP_WIDTH, 25); |
KURETA90 | 0:375bc0c22bf6 | 129 | LCD.Bitmap4bit( 0, 0, 176, 176, (unsigned char *)bmp_watch_4bit ); // window back screen |
KURETA90 | 0:375bc0c22bf6 | 130 | LCD.set_font( (unsigned char*)Prototype_num21x25 ); |
KURETA90 | 0:375bc0c22bf6 | 131 | LCD.locate(22, 54); |
KURETA90 | 0:375bc0c22bf6 | 132 | LCD.printf("10:"); |
KURETA90 | 0:375bc0c22bf6 | 133 | for(k=0; k<40;k++){ |
KURETA90 | 0:375bc0c22bf6 | 134 | LCD.locate(72, 54); |
KURETA90 | 0:375bc0c22bf6 | 135 | LCD.printf("%02d",k+20); |
KURETA90 | 0:375bc0c22bf6 | 136 | LCD.update(); |
batman52 | 2:25d611652243 | 137 | WAIT_S((double)exp((double)(-k/3))); // time constant =3 |
KURETA90 | 0:375bc0c22bf6 | 138 | } |
KURETA90 | 0:375bc0c22bf6 | 139 | } |
KURETA90 | 0:375bc0c22bf6 | 140 | } |