tes
Dependencies: TFT_fonts mbed sharp_mlcd
Fork of Sharp_Memory_LCD_Test by
main.cpp
- Committer:
- masato
- Date:
- 2014-05-11
- Revision:
- 1:443ce3a02a88
- Parent:
- 0:eb868b2d7042
File content as of revision 1:443ce3a02a88:
#include "mbed.h" #include "sharp_mlcd.h" #include "Arial12x12.h" sharp_mlcd lcd("LCD"); Serial pc(USBTX, USBRX); const static char mbedlogo128x48[768] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc7,0x83,0xe0,0x3c,0x7c,0x00,0x7e,0x00,0x3e,0x3c,0x00,0x00,0x00, 0x00,0x00,0x03,0xdf,0xef,0xf8,0x3d,0xfe,0x01,0xff,0x80,0x7f,0xbc,0x00,0x00,0x00, 0x00,0x00,0x03,0xff,0xff,0xf8,0x3f,0xff,0x03,0xff,0xc0,0xff,0xfc,0x00,0x00,0x00, 0x00,0x00,0x03,0xf1,0xfc,0x7c,0x3f,0x0f,0x87,0xc3,0xe1,0xf0,0xfc,0x00,0x00,0x00, 0x00,0x00,0x03,0xe0,0xf8,0x3c,0x3e,0x07,0x87,0x81,0xe1,0xe0,0x7c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0xe3,0xc0,0x3c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0xf3,0xc0,0x3c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0xff,0xf3,0xc0,0x3c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0x03,0xcf,0x00,0x03,0xc0,0x3c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3e,0x03,0xcf,0x00,0x03,0xc0,0x7c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3e,0x07,0x87,0x80,0x01,0xe0,0x7c,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3f,0x0f,0x87,0xc1,0xc1,0xf0,0xfc,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3f,0xff,0x03,0xff,0xf0,0xff,0xfc,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3d,0xfe,0x01,0xff,0xe0,0x7f,0xbc,0x00,0x00,0x00, 0x00,0x00,0x03,0xc0,0xf0,0x3c,0x3c,0xfc,0x00,0x7f,0x00,0x3f,0x3c,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; const static struct Bitmap logo = { 128, 48, 16, (char*)mbedlogo128x48, }; const char target[] = #if defined(TARGET_NUCLEO_L152RE) "STM32 Nucleo L152RE" #elif defined(TARGET_KL05Z) "Freescale FRDM-KL05Z" #else "????" #endif ; Ticker timer; void attime() { lcd.attime(); } static const unsigned char logo16_glcd_bmp[] = { 0x00, 0xc0, // B00000000, B11000000, 0x01, 0xc0, // B00000001, B11000000, 0x01, 0xc0, // B00000001, B11000000, 0x03, 0xe0, // B00000011, B11100000, 0xf3, 0xe0, // B11110011, B11100000, 0xfe, 0xf8, // B11111110, B11111000, 0x7e, 0xff, // B01111110, B11111111, 0x33, 0x9f, // B00110011, B10011111, 0x1f, 0xfc, // B00011111, B11111100, 0x0d, 0x70, // B00001101, B01110000, 0x1b, 0xa0, // B00011011, B10100000, 0x3f, 0xe0, // B00111111, B11100000, 0x3f, 0xf0, // B00111111, B11110000, 0x7c, 0xf0, // B01111100, B11110000, 0x70, 0x70, // B01110000, B01110000, 0x00, 0x30 }; // B00000000, B00110000 }; const static struct Bitmap snow = { 16, 16, 2, (char*)logo16_glcd_bmp, }; #define NUMFLAKES 16 #define XPOS 0 #define YPOS 1 #define DELTAY 2 void testdrawbitmap(struct Bitmap bitmap) { uint8_t icons[NUMFLAKES][3]; srand((unsigned int)time(NULL)); // srandom(666); // whatever seed int i; // initialize for (uint8_t f=0; f< NUMFLAKES; f++) { icons[f][XPOS] = rand() % lcd.width(); // display.width(); icons[f][YPOS] = 0; icons[f][DELTAY] = rand() % 5 + 1; #if 0 Serial.print("x: "); Serial.print(icons[f][XPOS], DEC); Serial.print(" y: "); Serial.print(icons[f][YPOS], DEC); Serial.print(" dy: "); Serial.println(icons[f][DELTAY], DEC); #endif } lcd.setmode(XOR); i = 0; while (1) { // draw each icon for (uint8_t f=0; f< NUMFLAKES; f++) { lcd.print_bm(bitmap, icons[f][XPOS], icons[f][YPOS], 1); } lcd.copy_to_lcd(); wait(0.2); // delay(200); // then erase it + move it for (uint8_t f=0; f< NUMFLAKES; f++) { lcd.print_bm(bitmap, icons[f][XPOS], icons[f][YPOS], 1); // move it icons[f][YPOS] += icons[f][DELTAY]; // if its gone, reinit if (icons[f][YPOS] > lcd.height()) { // display.height()) { icons[f][XPOS] = rand() % lcd.width(); // display.width(); icons[f][YPOS] = 0; icons[f][DELTAY] = rand() % 5 + 1; } } if (i++ > 100) break; } lcd.setmode(NORMAL); } void testdrawline() { for (int16_t i=0; i<lcd.width(); i+=4) { lcd.line(0, 0, i, lcd.height()-1, 1); lcd.copy_to_lcd(); } for (int16_t i=0; i<lcd.height(); i+=4) { lcd.line(0, 0, lcd.width()-1, i, 1); lcd.copy_to_lcd(); } wait(0.25); // delay(250); #if 0 lcd.cls(); for (int16_t i=0; i<lcd.width(); i+=4) { lcd.line(0, lcd.height()-1, i, 0, 1); lcd.copy_to_lcd(); } for (int16_t i=lcd.height()-1; i>=0; i-=4) { lcd.line(0, lcd.height()-1, lcd.width()-1, i, 1); lcd.copy_to_lcd(); } wait(0.25); // delay(250); lcd.cls(); for (int16_t i=lcd.width()-1; i>=0; i-=4) { lcd.line(lcd.width()-1, lcd.height()-1, i, 0, 1); lcd.copy_to_lcd(); } for (int16_t i=lcd.height()-1; i>=0; i-=4) { lcd.line(lcd.width()-1, lcd.height()-1, 0, i, 1); lcd.copy_to_lcd(); } wait(0.25); // delay(250); lcd.cls(); for (int16_t i=0; i<lcd.height(); i+=4) { lcd.line(lcd.width()-1, 0, 0, i, 1); lcd.copy_to_lcd(); } for (int16_t i=0; i<lcd.width(); i+=4) { lcd.line(lcd.width()-1, 0, i, lcd.height()-1, 1); lcd.copy_to_lcd(); } wait(0.25); #endif } int main() { pc.printf("%s\r\n", target); timer.attach(attime, 0.5); lcd.setmode(NORMAL); // lcd.set_font((unsigned char*)Arial24x23); lcd.set_font((unsigned char*)Arial12x12); lcd.set_auto_up(0); while (1) { lcd.cls(); lcd.locate(0,0); pc.printf("\r\n %s!\r\n This is Sharp Memory LCD demo.", target); lcd.printf("\r\n %s!\r\n This is Sharp Memory LCD demo.", target); wait(1); lcd.cls(); testdrawline(); wait(1); lcd.cls(); testdrawbitmap(snow); wait(1); lcd.cls(); wait(1); lcd.print_bm(logo, 0, 0, 1); lcd.copy_to_lcd(); lcd.printf("\r\n\r\n %s", target); lcd.copy_to_lcd(); wait(10); } }