TFT_ILI9163C test A fork of https://github.com/sumotoy/TFT_ILI9163C
Dependencies: Adafruit-GFX-Library TFT_ILI9163C mbed
Fork of IL9163C_test by
Diff: main.cpp
- Revision:
- 8:4fcf5494f425
- Parent:
- 5:f6052f005aef
- Child:
- 9:99e7307d5a59
--- a/main.cpp Tue Feb 03 11:14:00 2015 +0000 +++ b/main.cpp Wed Feb 04 10:59:10 2015 +0000 @@ -17,10 +17,12 @@ #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F -#define YELLOW 0xFFE0 +#define YELLOW 0xFFE0 #define WHITE 0xFFFF #define TRANSPARENT -1 +#define SPI_BITRATE 50000000L + TFT_ILI9163C display(__MOSI, __MISO, __SCLK, __CS, __DC, __RST); //TFT_ILI9163C display(__MOSI, __MISO, __SCLK, __CS, __DC); @@ -28,350 +30,341 @@ const float p = 3.1415926; -uint32_t millis() { - return t.read_ms(); -} - int32_t random(int32_t howbig) { - if (howbig == 0) { - return 0; - } - return rand() % howbig; + if (howbig == 0) { + return 0; + } + return rand() % howbig; } int32_t random(int32_t howsmall, int32_t howbig) { - if (howsmall >= howbig) { - return howsmall; - } - int32_t diff = howbig - howsmall +1; - return random(diff) + howsmall; + if (howsmall >= howbig) { + return howsmall; + } + int32_t diff = howbig - howsmall +1; + return random(diff) + howsmall; } void testlines(uint16_t color) { - display.clearScreen(); - for (int16_t x=0; x < display.width()-1; x+=6) { - display.drawLine(0, 0, x, display.height()-1, color); - } - for (int16_t y=0; y < display.height()-1; y+=6) { - display.drawLine(0, 0, display.width()-1, y, color); - } - display.clearScreen(); - for (int16_t x=0; x < display.width()-1; x+=6) { - display.drawLine(display.width()-1, 0, x, display.height()-1, color); - } - for (int16_t y=0; y < display.height()-1; y+=6) { - display.drawLine(display.width()-1, 0, 0, y, color); - } + display.clearScreen(); + for (int16_t x=0; x < display.width()-1; x+=6) { + display.drawLine(0, 0, x, display.height()-1, color); + } + for (int16_t y=0; y < display.height()-1; y+=6) { + display.drawLine(0, 0, display.width()-1, y, color); + } + display.clearScreen(); + for (int16_t x=0; x < display.width()-1; x+=6) { + display.drawLine(display.width()-1, 0, x, display.height()-1, color); + } + for (int16_t y=0; y < display.height()-1; y+=6) { + display.drawLine(display.width()-1, 0, 0, y, color); + } - display.clearScreen(); - for (int16_t x=0; x < display.width()-1; x+=6) { - display.drawLine(0, display.height()-1, x, 0, color); - } - for (int16_t y=0; y < display.height()-1; y+=6) { - display.drawLine(0, display.height()-1, display.width()-1, y, color); - } - display.clearScreen(); - for (int16_t x=0; x < display.width()-1; x+=6) { - display.drawLine(display.width()-1, display.height()-1, x, 0, color); - } - for (int16_t y=0; y < display.height()-1; y+=6) { - display.drawLine(display.width()-1, display.height()-1, 0, y, color); - } - wait_ms(500); + display.clearScreen(); + for (int16_t x=0; x < display.width()-1; x+=6) { + display.drawLine(0, display.height()-1, x, 0, color); + } + for (int16_t y=0; y < display.height()-1; y+=6) { + display.drawLine(0, display.height()-1, display.width()-1, y, color); + } + display.clearScreen(); + for (int16_t x=0; x < display.width()-1; x+=6) { + display.drawLine(display.width()-1, display.height()-1, x, 0, color); + } + for (int16_t y=0; y < display.height()-1; y+=6) { + display.drawLine(display.width()-1, display.height()-1, 0, y, color); + } + wait_ms(500); } void testdrawtext(char *text, uint16_t color) { - display.setTextSize(1); - display.setTextColor(WHITE); - display.setCursor(0,0); + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(0,0); - for (uint8_t i=0; i < 168; i++) { - if (i == '\n') continue; - display.writeChar(i); - if ((i > 0) && (i % 21 == 0)) - display.printf("\n"); - } + for (uint8_t i=0; i < 168; i++) { + if (i == '\n') continue; + display.writeChar(i); + if ((i > 0) && (i % 21 == 0)) + display.printf("\n"); + } } void testfastlines(uint16_t color1, uint16_t color2) { - display.clearScreen(); - for (int16_t y=0; y < display.height()-1; y+=5) { - display.drawFastHLine(0, y, display.width()-1, color1); - } - for (int16_t x=0; x < display.width()-1; x+=5) { - display.drawFastVLine(x, 0, display.height()-1, color2); - } + display.clearScreen(); + for (int16_t y=0; y < display.height()-1; y+=5) { + display.drawFastHLine(0, y, display.width()-1, color1); + } + for (int16_t x=0; x < display.width()-1; x+=5) { + display.drawFastVLine(x, 0, display.height()-1, color2); + } } void testdrawrects(uint16_t color) { - display.clearScreen(); - for (int16_t x=0; x < display.height()-1; x+=6) { - display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color); - } + display.clearScreen(); + for (int16_t x=0; x < display.height()-1; x+=6) { + display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color); + } } void testfillrects(uint16_t color1, uint16_t color2) { - display.clearScreen(); - for (int16_t x=display.height()-1; x > 6; x-=6) { - display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1); - display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2); - } + display.clearScreen(); + for (int16_t x=display.height()-1; x > 6; x-=6) { + display.fillRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color1); + display.drawRect((display.width()-1)/2 -x/2, (display.height()-1)/2 -x/2 , x, x, color2); + } } void testfillcircles(uint8_t radius, uint16_t color) { - for (uint8_t x=radius; x < display.width()-1; x+=radius*2) { - for (uint8_t y=radius; y < display.height()-1; y+=radius*2) { - display.fillCircle(x, y, radius, color); + for (uint8_t x=radius; x < display.width()-1; x+=radius*2) { + for (uint8_t y=radius; y < display.height()-1; y+=radius*2) { + display.fillCircle(x, y, radius, color); + } } - } } void testdrawcircles(uint8_t radius, uint16_t color) { - for (int16_t x=0; x < (display.width()-1)+radius; x+=radius*2) { - for (int16_t y=0; y < (display.height())-1+radius; y+=radius*2) { - display.drawCircle(x, y, radius, color); + for (int16_t x=0; x < (display.width()-1)+radius; x+=radius*2) { + for (int16_t y=0; y < (display.height())-1+radius; y+=radius*2) { + display.drawCircle(x, y, radius, color); + } } - } } void testtriangles() { - display.clearScreen(); - int color = 0xF800; - int t; - int w = display.width()/2; - int x = display.height(); - int y = 0; - int z = display.width(); - for(t = 0 ; t <= 15; t+=1) { - display.drawTriangle(w, y, y, x, z, x, color); - x-=4; - y+=4; - z-=4; - color+=100; - } + display.clearScreen(); + int color = 0xF800; + int t; + int w = display.width()/2; + int x = display.height(); + int y = 0; + int z = display.width(); + for(t = 0 ; t <= 15; t+=1) { + display.drawTriangle(w, y, y, x, z, x, color); + x-=4; + y+=4; + z-=4; + color+=100; + } } void testroundrects() { - display.clearScreen(); - int color = 100; - int i; - int t; - for(t = 0 ; t <= 4; t+=1) { - int x = 0; - int y = 0; - int w = display.width(); - int h = display.height(); - for(i = 0 ; i <= 24; i+=1) { - display.drawRoundRect(x, y, w, h, 5, color); - x+=2; - y+=3; - w-=4; - h-=6; - color+=1100; + display.clearScreen(); + int color = 100; + int i; + int t; + for(t = 0 ; t <= 4; t+=1) { + int x = 0; + int y = 0; + int w = display.width(); + int h = display.height(); + for(i = 0 ; i <= 24; i+=1) { + display.drawRoundRect(x, y, w, h, 5, color); + x+=2; + y+=3; + w-=4; + h-=6; + color+=1100; + } + color+=100; } - color+=100; - } } void tftPrintTest() { - display.clearScreen(); - display.setCursor(0, 5); - display.setTextColor(RED); - display.setTextSize(1); - display.printf("Hello World!\n"); - display.setTextColor(YELLOW, GREEN); - display.setTextSize(2); - display.printf("Hello Wo"); - display.setTextColor(BLUE); - display.setTextSize(3); - display.printf("%.2f", 12.57); - wait_ms(1500); - display.setCursor(0, 5); - display.clearScreen(); - display.setTextColor(WHITE); - display.setTextSize(0); - display.printf("Hello World!\n"); - display.setTextSize(1); - display.setTextColor(GREEN); - display.printf("%5f", p); - display.printf(" Want pi?\n"); - display.printf("%x", 8675309); - display.printf(" Print HEX\n"); - display.setTextColor(WHITE); - display.printf("Sketch has been\n"); - display.printf("running for: \n"); - display.setTextColor(MAGENTA); - display.printf("%d", millis() / 1000); - display.setTextColor(WHITE); - display.printf(" sec."); + display.clearScreen(); + display.setCursor(0, 5); + display.setTextColor(RED); + display.setTextSize(1); + display.printf("Hello World!\n"); + display.setTextColor(YELLOW, GREEN); + display.setTextSize(2); + display.printf("Hello Wo"); + display.setTextColor(BLUE); + display.setTextSize(3); + display.printf("%.2f", 12.57); + wait_ms(1500); + display.setCursor(0, 5); + display.clearScreen(); + display.setTextColor(WHITE); + display.setTextSize(0); + display.printf("Hello World!\n"); + display.setTextSize(1); + display.setTextColor(GREEN); + display.printf("%5f", p); + display.printf(" Want pi?\n"); + display.printf("%x", 8675309); + display.printf(" Print HEX\n"); + display.setTextColor(WHITE); + display.printf("Sketch has been\n"); + display.printf("running for: \n"); + display.setTextColor(MAGENTA); + display.printf("%d", t.read_ms() / 1000); + display.setTextColor(WHITE); + display.printf(" sec."); } -void randomRect(bool fill){ - display.clearScreen(); - uint8_t k,c; - for (k = 0; k < 16; k++) { - for (c = 0; c < 32; c++) { - uint8_t cx, cy, x, y, w, h; - // center - cx = random(0,display.width()); - cy = random(0,display.height()); - // size - w = random(0,30 + 6); - h = random(0,20 + 4); - // upper-left - x = cx - w / 2; - y = cy - h / 2; +void randomRect(bool fill) { + display.clearScreen(); + uint8_t k,c; + for (k = 0; k < 16; k++) { + for (c = 0; c < 32; c++) { + uint8_t cx, cy, x, y, w, h; + // center + cx = random(0,display.width()); + cy = random(0,display.height()); + // size + w = random(0,30 + 6); + h = random(0,20 + 4); + // upper-left + x = cx - w / 2; + y = cy - h / 2; // if (x < 0) x = 0; // if (y < 0) y = 0; - // adjust size - if (x + w > display.width()) w = display.width() - x; - if (y + h > display.height()) h = display.height() - y; - if (fill){ - display.fillRect(x, y, w, h,random(0x0010,0xFFFF)); - } - else { - display.drawRect(x, y, w, h,random(0x0010,0xFFFF)); - } + // adjust size + if (x + w > display.width()) w = display.width() - x; + if (y + h > display.height()) h = display.height() - y; + if (fill) { + display.fillRect(x, y, w, h,random(0x0010,0xFFFF)); + } else { + display.drawRect(x, y, w, h,random(0x0010,0xFFFF)); + } + } + display.clearScreen(); } - display.clearScreen(); - } } -void randomCircles(bool fill){ - display.clearScreen(); - uint8_t k,c; - for (k = 0; k < display.height(); k++) { - for (c = 0; c < display.height()/2; c++) { - // coordinates - uint8_t x = random(0,120 + 3), y = random(0,90 + 2), r = random(0,40 + 1); - if (x - r < 0) r = x; - if (x + r > (display.width()-1)) r = (display.width() - 1) - x; - if (y - r < 0) r = y; - if (y + r > (display.height()-1)) r = (display.height() - 1) - y; - if (fill){ - display.fillCircle(x, y, r,random(0x0010,0xFFFF)); - } - else { - display.drawCircle(x, y, r,random(0x0010,0xFFFF)); - } +void randomCircles(bool fill) { + display.clearScreen(); + uint8_t k,c; + for (k = 0; k < display.height(); k++) { + for (c = 0; c < display.height()/2; c++) { + // coordinates + uint8_t x = random(0,120 + 3), y = random(0,90 + 2), r = random(0,40 + 1); + if (x - r < 0) r = x; + if (x + r > (display.width()-1)) r = (display.width() - 1) - x; + if (y - r < 0) r = y; + if (y + r > (display.height()-1)) r = (display.height() - 1) - y; + if (fill) { + display.fillCircle(x, y, r,random(0x0010,0xFFFF)); + } else { + display.drawCircle(x, y, r,random(0x0010,0xFFFF)); + } + } + if (!fill)display.clearScreen(); } - if (!fill)display.clearScreen(); - } } -void randomLines(){ - display.clearScreen(); - uint8_t k,c; - for (k = 0; k < display.height(); k++) { - for (c = 0; c < display.height()/2; c++) { - uint8_t x1 = random(0,display.width()), y1 = random(0,display.height()), x2 = random(0,display.width()), y2 = random(0,display.height()); - display.drawLine(x1, y1, x2, y2,random(0x0010,0xFFFF)); +void randomLines() { + display.clearScreen(); + uint8_t k,c; + for (k = 0; k < display.height(); k++) { + for (c = 0; c < display.height()/2; c++) { + uint8_t x1 = random(0,display.width()), y1 = random(0,display.height()), x2 = random(0,display.width()), y2 = random(0,display.height()); + display.drawLine(x1, y1, x2, y2,random(0x0010,0xFFFF)); + } + display.clearScreen(); } - display.clearScreen(); - } } -void randomPoints(){ - display.clearScreen(); - for (uint8_t k = 0; k < 128; k++) { - for (uint16_t c = 0; c < 1000; c++) { - uint8_t x = random(0,display.width()), y = random(0,display.height()); - display.drawPixel(x, y, random(0x0010,0xFFFF)); +void randomPoints() { + display.clearScreen(); + for (uint8_t k = 0; k < 128; k++) { + for (uint16_t c = 0; c < 1000; c++) { + uint8_t x = random(0,display.width()), y = random(0,display.height()); + display.drawPixel(x, y, random(0x0010,0xFFFF)); + } + display.clearScreen(); } - display.clearScreen(); - } } void loop() { - - testlines(random(0x0010,0xFFFF)); - randomLines(); - //randomCircles(1); - randomCircles(0); - randomRect(1); - randomRect(1); - randomRect(1); - randomRect(1); - randomRect(1); - randomRect(0); - randomRect(0); - randomRect(0); - randomRect(0); - randomRect(0); - randomRect(0); - randomPoints(); + + testlines(random(0x0010,0xFFFF)); + randomLines(); + //randomCircles(1); + randomCircles(0); + randomRect(1); + randomRect(1); + randomRect(1); + randomRect(1); + randomRect(1); + randomRect(0); + randomRect(0); + randomRect(0); + randomRect(0); + randomRect(0); + randomRect(0); + randomPoints(); } void setup(void) { - - t.start(); - - display.begin(); -// display.setBitrate(10000000L); -// display.setBitrate(25000000L); - display.setBitrate(50000000L); - display.setRotation(2); + + t.start(); + + display.begin(); + display.setBitrate(SPI_BITRATE); + display.setRotation(2); // lcdTestPattern(); // delay(1000); - display.clearScreen(); - display.setCursor(0,0); - display.printf("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa"); - wait_ms(1000); + display.clearScreen(); + display.setCursor(0,0); + display.printf("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa"); + wait_ms(1000); - tftPrintTest(); - wait_ms(2000); + tftPrintTest(); + wait_ms(2000); - //a single pixel - display.drawPixel(display.width()/2, display.height()/2, GREEN); - wait_ms(500); + //a single pixel + display.drawPixel(display.width()/2, display.height()/2, GREEN); + wait_ms(500); - // line draw test - testlines(YELLOW); - wait_ms(500); + // line draw test + testlines(YELLOW); + wait_ms(500); - // optimized lines - testfastlines(RED, BLUE); - wait_ms(500); + // optimized lines + testfastlines(RED, BLUE); + wait_ms(500); - testdrawrects(GREEN); - wait_ms(1000); + testdrawrects(GREEN); + wait_ms(1000); - testfillrects(BLUE, YELLOW); - wait_ms(1000); + testfillrects(BLUE, YELLOW); + wait_ms(1000); - randomRect(0); - wait_ms(100); - randomCircles(0); - wait_ms(100); - randomLines(); - wait_ms(100); - randomPoints(); - wait_ms(500); - - display.clearScreen(); - testfillcircles(10, BLUE); - testdrawcircles(10, WHITE); - wait_ms(1000); + randomRect(0); + wait_ms(100); + randomCircles(0); + wait_ms(100); + randomLines(); + wait_ms(100); + randomPoints(); + wait_ms(500); - testroundrects(); - wait_ms(500); + display.clearScreen(); + testfillcircles(10, BLUE); + testdrawcircles(10, WHITE); + wait_ms(1000); - testtriangles(); - wait_ms(500); + testroundrects(); + wait_ms(500); + testtriangles(); + wait_ms(500); } int main() { setup(); - + while (true) { loop(); }