test program for Sharp memory LCD
Dependencies: TFT_fonts mbed sharp_mlcd
main.cpp
00001 #include "mbed.h" 00002 #include "sharp_mlcd.h" 00003 00004 #include "Arial12x12.h" 00005 00006 sharp_mlcd lcd("LCD"); 00007 Serial pc(USBTX, USBRX); 00008 00009 const static 00010 char mbedlogo128x48[768] 00011 = { 00012 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00013 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00014 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00015 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00016 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00017 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00018 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00019 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00020 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00021 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00022 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00023 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00024 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00025 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00026 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00027 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00028 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 00029 0x00,0x00,0x03,0xc7,0x83,0xe0,0x3c,0x7c,0x00,0x7e,0x00,0x3e,0x3c,0x00,0x00,0x00, 00030 0x00,0x00,0x03,0xdf,0xef,0xf8,0x3d,0xfe,0x01,0xff,0x80,0x7f,0xbc,0x00,0x00,0x00, 00031 0x00,0x00,0x03,0xff,0xff,0xf8,0x3f,0xff,0x03,0xff,0xc0,0xff,0xfc,0x00,0x00,0x00, 00032 0x00,0x00,0x03,0xf1,0xfc,0x7c,0x3f,0x0f,0x87,0xc3,0xe1,0xf0,0xfc,0x00,0x00,0x00, 00033 0x00,0x00,0x03,0xe0,0xf8,0x3c,0x3e,0x07,0x87,0x81,0xe1,0xe0,0x7c,0x00,0x00,0x00, 00034 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0xe3,0xc0,0x3c,0x00,0x00,0x00, 00035 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0xf3,0xc0,0x3c,0x00,0x00,0x00, 00036 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 00037 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 00038 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 00039 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0x03,0xc0,0x3c,0x00,0x00,0x00, 00040 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3e,0x03,0xcf,0x00,0x03,0xc0,0x7c,0x00,0x00,0x00, 00041 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3e,0x07,0x87,0x80,0x01,0xe0,0x7c,0x00,0x00,0x00, 00042 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3f,0x0f,0x87,0xc1,0xc1,0xf0,0xfc,0x00,0x00,0x00, 00043 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3f,0xff,0x03,0xff,0xf0,0xff,0xfc,0x00,0x00,0x00, 00044 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3d,0xfe,0x01,0xff,0xe0,0x7f,0xbc,0x00,0x00,0x00, 00045 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0xfc,0x00,0x7f,0x00,0x3f,0x3c,0x00,0x00,0x00, 00046 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00047 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00048 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00049 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00050 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00051 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00052 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00053 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00054 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00055 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00056 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00057 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00058 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 00059 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 00060 }; 00061 00062 00063 const static struct Bitmap logo = { 00064 128, 00065 48, 00066 16, 00067 (char*)mbedlogo128x48, 00068 }; 00069 00070 const char target[] = 00071 #if defined(TARGET_NUCLEO_L152RE) 00072 "STM32 Nucleo L152RE" 00073 #elif defined(TARGET_KL05Z) 00074 "Freescale FRDM-KL05Z" 00075 #else 00076 "????" 00077 #endif 00078 ; 00079 00080 Ticker timer; 00081 00082 void attime() { 00083 lcd.attime(); 00084 } 00085 00086 static const unsigned char logo16_glcd_bmp[] = 00087 { 0x00, 0xc0, // B00000000, B11000000, 00088 0x01, 0xc0, // B00000001, B11000000, 00089 0x01, 0xc0, // B00000001, B11000000, 00090 0x03, 0xe0, // B00000011, B11100000, 00091 0xf3, 0xe0, // B11110011, B11100000, 00092 0xfe, 0xf8, // B11111110, B11111000, 00093 0x7e, 0xff, // B01111110, B11111111, 00094 0x33, 0x9f, // B00110011, B10011111, 00095 0x1f, 0xfc, // B00011111, B11111100, 00096 0x0d, 0x70, // B00001101, B01110000, 00097 0x1b, 0xa0, // B00011011, B10100000, 00098 0x3f, 0xe0, // B00111111, B11100000, 00099 0x3f, 0xf0, // B00111111, B11110000, 00100 0x7c, 0xf0, // B01111100, B11110000, 00101 0x70, 0x70, // B01110000, B01110000, 00102 0x00, 0x30 }; // B00000000, B00110000 }; 00103 00104 const static struct Bitmap snow = { 00105 16, 00106 16, 00107 2, 00108 (char*)logo16_glcd_bmp, 00109 }; 00110 00111 #define NUMFLAKES 16 00112 #define XPOS 0 00113 #define YPOS 1 00114 #define DELTAY 2 00115 00116 void testdrawbitmap(struct Bitmap bitmap) { 00117 uint8_t icons[NUMFLAKES][3]; 00118 srand((unsigned int)time(NULL)); // srandom(666); // whatever seed 00119 int i; 00120 00121 // initialize 00122 for (uint8_t f=0; f< NUMFLAKES; f++) { 00123 icons[f][XPOS] = rand() % lcd.width(); // display.width(); 00124 icons[f][YPOS] = 0; 00125 icons[f][DELTAY] = rand() % 5 + 1; 00126 #if 0 00127 Serial.print("x: "); 00128 Serial.print(icons[f][XPOS], DEC); 00129 Serial.print(" y: "); 00130 Serial.print(icons[f][YPOS], DEC); 00131 Serial.print(" dy: "); 00132 Serial.println(icons[f][DELTAY], DEC); 00133 #endif 00134 } 00135 lcd.setmode(XOR); 00136 i = 0; 00137 while (1) { 00138 // draw each icon 00139 for (uint8_t f=0; f< NUMFLAKES; f++) { 00140 lcd.print_bm(bitmap, icons[f][XPOS], icons[f][YPOS], 1); 00141 } 00142 lcd.copy_to_lcd(); 00143 wait(0.2); // delay(200); 00144 00145 // then erase it + move it 00146 for (uint8_t f=0; f< NUMFLAKES; f++) { 00147 lcd.print_bm(bitmap, icons[f][XPOS], icons[f][YPOS], 1); 00148 // move it 00149 icons[f][YPOS] += icons[f][DELTAY]; 00150 // if its gone, reinit 00151 if (icons[f][YPOS] > lcd.height()) { // display.height()) { 00152 icons[f][XPOS] = rand() % lcd.width(); // display.width(); 00153 icons[f][YPOS] = 0; 00154 icons[f][DELTAY] = rand() % 5 + 1; 00155 } 00156 } 00157 if (i++ > 100) break; 00158 } 00159 lcd.setmode(NORMAL); 00160 } 00161 00162 00163 void testdrawline() { 00164 for (int16_t i=0; i<lcd.width(); i+=4) { 00165 lcd.line(0, 0, i, lcd.height()-1, 1); 00166 lcd.copy_to_lcd(); 00167 } 00168 for (int16_t i=0; i<lcd.height(); i+=4) { 00169 lcd.line(0, 0, lcd.width()-1, i, 1); 00170 lcd.copy_to_lcd(); 00171 } 00172 wait(0.25); // delay(250); 00173 #if 0 00174 lcd.cls(); 00175 for (int16_t i=0; i<lcd.width(); i+=4) { 00176 lcd.line(0, lcd.height()-1, i, 0, 1); 00177 lcd.copy_to_lcd(); 00178 } 00179 for (int16_t i=lcd.height()-1; i>=0; i-=4) { 00180 lcd.line(0, lcd.height()-1, lcd.width()-1, i, 1); 00181 lcd.copy_to_lcd(); 00182 } 00183 wait(0.25); // delay(250); 00184 00185 lcd.cls(); 00186 for (int16_t i=lcd.width()-1; i>=0; i-=4) { 00187 lcd.line(lcd.width()-1, lcd.height()-1, i, 0, 1); 00188 lcd.copy_to_lcd(); 00189 } 00190 for (int16_t i=lcd.height()-1; i>=0; i-=4) { 00191 lcd.line(lcd.width()-1, lcd.height()-1, 0, i, 1); 00192 lcd.copy_to_lcd(); 00193 } 00194 wait(0.25); // delay(250); 00195 00196 lcd.cls(); 00197 for (int16_t i=0; i<lcd.height(); i+=4) { 00198 lcd.line(lcd.width()-1, 0, 0, i, 1); 00199 lcd.copy_to_lcd(); 00200 } 00201 for (int16_t i=0; i<lcd.width(); i+=4) { 00202 lcd.line(lcd.width()-1, 0, i, lcd.height()-1, 1); 00203 lcd.copy_to_lcd(); 00204 } 00205 wait(0.25); 00206 #endif 00207 } 00208 00209 int main() { 00210 pc.printf("%s\r\n", target); 00211 timer.attach(attime, 0.5); 00212 lcd.setmode(NORMAL); 00213 // lcd.set_font((unsigned char*)Arial24x23); 00214 lcd.set_font((unsigned char*)Arial12x12); 00215 lcd.set_auto_up(0); 00216 while (1) { 00217 lcd.cls(); 00218 lcd.locate(0,0); 00219 pc.printf("\r\n %s!\r\n This is Sharp Memory LCD demo.", target); 00220 lcd.printf("\r\n %s!\r\n This is Sharp Memory LCD demo.", target); 00221 wait(1); 00222 lcd.cls(); 00223 testdrawline(); 00224 wait(1); 00225 lcd.cls(); 00226 testdrawbitmap(snow); 00227 wait(1); 00228 lcd.cls(); 00229 wait(1); 00230 lcd.print_bm(logo, 0, 0, 1); 00231 lcd.copy_to_lcd(); 00232 lcd.printf("\r\n\r\n %s", target); 00233 lcd.copy_to_lcd(); 00234 00235 wait(10); 00236 } 00237 }
Generated on Mon Aug 1 2022 04:51:07 by 1.7.2