Update examples

Now compatible with ESP8266
This commit is contained in:
Bodmer
2017-02-24 21:00:40 +00:00
parent 56f4599cfd
commit b7315803f4
17 changed files with 343 additions and 473 deletions

View File

@@ -2,20 +2,32 @@
//devised by the British mathematician John Horton Conway in 1970. //devised by the British mathematician John Horton Conway in 1970.
// https://en.wikipedia.org/wiki/Conway's_Game_of_Life // https://en.wikipedia.org/wiki/Conway's_Game_of_Life
// See license at end of file.
// Adapted by Bodmer
#include <TFT_eSPI.h> // Hardware-specific library #include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h> #include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define GRIDX 32 // Maximum number of generations until the screen is refreshed
#define GRIDY 24 #define MAX_GEN_COUNT 500
#define CELLXY 5
#define GEN_DELAY 0 // The ESP8266 has plenty of memory so we can create a large array
// 2 x 2 pixel cells, array size = 5120 bytes per array, runs fast
#define GRIDX 80
#define GRIDY 64
#define CELLXY 2
//Current grid // 1 x 1 pixel cells, array size = 20480 bytes per array
//#define GRIDX 160
//#define GRIDY 128
//#define CELLXY 1
#define GEN_DELAY 10 // Set a delay between each generation to slow things down
//Current grid and newgrid arrays are needed
uint8_t grid[GRIDX][GRIDY]; uint8_t grid[GRIDX][GRIDY];
//The new grid for the next generation //The new grid for the next generation
@@ -55,7 +67,7 @@ void loop() {
initGrid(); initGrid();
genCount = 300; genCount = MAX_GEN_COUNT;
drawGrid(); drawGrid();

View File

@@ -1,5 +1,5 @@
// We need this header file to use FLASH as storage with PROGMEM directive: // We need this header file to use FLASH as storage with PROGMEM directive:
#include <avr/pgmspace.h> #include <pgmspace.h>
// Icon width and height // Icon width and height
const uint16_t alertWidth = 32; const uint16_t alertWidth = 32;

View File

@@ -1,5 +1,5 @@
// We need this header file to use FLASH as storage with PROGMEM directive: // We need this header file to use FLASH as storage with PROGMEM directive:
#include <avr/pgmspace.h> #include <pgmspace.h>
// Icon width and height // Icon width and height
const uint16_t closeWidth = 32; const uint16_t closeWidth = 32;

View File

@@ -8,6 +8,7 @@
// Icons are stored in tabs, e.g. Alert.h etc // Icons are stored in tabs, e.g. Alert.h etc
// more than one icon can be in a header file. // more than one icon can be in a header file.
// Original sketch header follow:
/* /*
This sketch demonstrates loading images from arrays stored in program (FLASH) memory. This sketch demonstrates loading images from arrays stored in program (FLASH) memory.

View File

@@ -1,5 +1,5 @@
// We need this header file to use FLASH as storage with PROGMEM directive: // We need this header file to use FLASH as storage with PROGMEM directive:
#include <avr/pgmspace.h> #include <pgmspace.h>
// Icon width and height // Icon width and height
const uint16_t infoWidth = 32; const uint16_t infoWidth = 32;

View File

@@ -16,7 +16,7 @@ TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
int16_t h = 128; int16_t h = 128;
int16_t w = 160; int16_t w = 160;
int dly = 5; int dly = 10;
int16_t paddle_h = 25; int16_t paddle_h = 25;
int16_t paddle_w = 2; int16_t paddle_w = 2;
@@ -98,7 +98,7 @@ void initgame() {
tft.fillRect(0,h-26,w,h-1,BLACK); tft.fillRect(0,h-26,w,h-1,BLACK);
tft.setTextDatum(TC_DATUM); tft.setTextDatum(TC_DATUM);
tft.setTextColor(WHITE,GREY); tft.setTextColor(WHITE);
tft.drawString("TFT_eSPI example", w/2, h-26 , 2); tft.drawString("TFT_eSPI example", w/2, h-26 , 2);
} }

View File

@@ -1,43 +1,15 @@
/* /*
Display all the fonts. Display all the fast rendering fonts.
This sketch uses the GLCD (font 1) and fonts 2, 4, 6, 7, 8 This sketch uses the GLCD (font 1) and fonts 2, 4, 6, 7, 8
Make sure all the required fonts are loaded by editting the Make sure all the display driver and pin comnenctions are correct by
User_Setup.h file in the TFT_eSPI library folder. editting the User_Setup.h file in the TFT_eSPI library folder.
If using an UNO or Mega (ATmega328 or ATmega2560 processor) then for best
performance use the F_AS_T option found in the User_Setup.h file in the
TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
######################################################################### #########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
######################################################################### #########################################################################
*/ */
// New background colour // New background colour
#define TFT_BROWN 0x38E0 #define TFT_BROWN 0x38E0

View File

@@ -143,7 +143,7 @@ void analogMeter()
} }
tft.drawString("%RH", M_SIZE*(3 + 230 - 40), M_SIZE*(119 - 20), 2); // Units at bottom right tft.drawString("%RH", M_SIZE*(3 + 230 - 40), M_SIZE*(119 - 20), 2); // Units at bottom right
//tft.drawCentreString("%RH", M_SIZE*120, M_SIZE*75, 4); // Comment out to avoid font 4 tft.drawCentreString("%RH", M_SIZE*120, M_SIZE*75, 4); // Comment out to avoid font 4
tft.drawRect(1, M_SIZE*3, M_SIZE*236, M_SIZE*126, ST7735_BLACK); // Draw bezel line tft.drawRect(1, M_SIZE*3, M_SIZE*236, M_SIZE*126, ST7735_BLACK); // Draw bezel line
plotNeedle(0, 0); // Put meter needle at 0 plotNeedle(0, 0); // Put meter needle at 0
@@ -187,7 +187,7 @@ void plotNeedle(int value, byte ms_delay)
// Re-plot text under needle // Re-plot text under needle
tft.setTextColor(ST7735_BLACK, ST7735_WHITE); tft.setTextColor(ST7735_BLACK, ST7735_WHITE);
//tft.drawCentreString("%RH", M_SIZE*120, M_SIZE*75, 4); // // Comment out to avoid font 4 tft.drawCentreString("%RH", M_SIZE*120, M_SIZE*75, 4); // // Comment out to avoid font 4
// Store new needle end coords for next erase // Store new needle end coords for next erase
ltx = tx; ltx = tx;

View File

@@ -6,39 +6,14 @@
Needs fonts 2, 4, 6, 7 and 8 Needs fonts 2, 4, 6, 7 and 8
Make sure all the required fonts are loaded by editting the Make sure all the display driver and pin comnenctions are correct by
User_Setup.h file in the TFT_eSPI library folder. editting the User_Setup.h file in the TFT_eSPI library folder.
If using an UNO or Mega (ATmega328 or ATmega2560 processor) then for best Note that yield() or delay(0) must be called in long duration for/while
performance use the F_AS_T option found in the User_Setup.h file in the loops to stop the ESP8266 watchdog triggering.
TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
######################################################################### #########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
######################################################################### #########################################################################
*/ */
@@ -108,7 +83,7 @@ void loop() {
drawTime = millis(); drawTime = millis();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
tft.drawNumber(i, 0, 0, 6); yield(); tft.drawNumber(i, 0, 0, 6);
} }
drawTime = millis() - drawTime; drawTime = millis() - drawTime;
@@ -123,7 +98,7 @@ void loop() {
drawTime = millis(); drawTime = millis();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
tft.drawNumber(i, 0, 0, 7); yield(); tft.drawNumber(i, 0, 0, 7);
} }
drawTime = millis() - drawTime; drawTime = millis() - drawTime;
@@ -138,7 +113,7 @@ void loop() {
drawTime = millis(); drawTime = millis();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
tft.drawNumber(i, 0, 0, 8); yield(); tft.drawNumber(i, 0, 0, 8);
} }
drawTime = millis() - drawTime; drawTime = millis() - drawTime;

View File

@@ -95,7 +95,7 @@ void loop() {
if (omm != mm) { // Only redraw every minute to minimise flicker if (omm != mm) { // Only redraw every minute to minimise flicker
// Uncomment ONE of the next 2 lines, using the ghost image demonstrates text overlay as time is drawn over it // Uncomment ONE of the next 2 lines, using the ghost image demonstrates text overlay as time is drawn over it
tft.setTextColor(0x39C4, ST7735_BLACK); // Leave a 7 segment ghost image, comment out next line! tft.setTextColor(0x39C4, ST7735_BLACK); // Leave a 7 segment ghost image, comment out next line!
//tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Set font colour to back to wipe image //tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Set font colour to black to wipe image
// Font 7 is to show a pseudo 7 segment display. // Font 7 is to show a pseudo 7 segment display.
// Font 7 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : . // Font 7 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : .
tft.drawString("88:88",xpos,ypos,7); // Overwrite the text to clear it tft.drawString("88:88",xpos,ypos,7); // Overwrite the text to clear it
@@ -118,7 +118,7 @@ void loop() {
else { else {
tft.drawChar(':',xcolon,ypos,7); tft.drawChar(':',xcolon,ypos,7);
colour = random(0xFFFF); colour = random(0xFFFF);
// Erase the text with a rectangle // Erase the old text with a rectangle, the disadvantage of this method is increased display flicker
tft.fillRect (0, 64, 160, 20, ST7735_BLACK); tft.fillRect (0, 64, 160, 20, ST7735_BLACK);
tft.setTextColor(colour); tft.setTextColor(colour);
tft.drawRightString("Colour",75,64,4); // Right justified string drawing to x position 75 tft.drawRightString("Colour",75,64,4); // Right justified string drawing to x position 75

View File

@@ -1,11 +1,11 @@
/* /*
An example analogue clock using a TFT LCD screen to show the time An example analogue clock using a TFT LCD screen to show the time
use of some of the drawing commands with the ST7735 library. use of some of the drawing commands with the ST7735 library.
For a more accurate clock, it would be better to use the RTClib library. For a more accurate clock, it would be better to use the RTClib library.
But this is just a demo. But this is just a demo.
This examples uses the hardware SPI only. Non-hardware SPI Uses compile time to set the time so a reset will start with the compile time again
is just too slow (~8 times slower!)
Gilchrist 6/2/2014 1.0 Gilchrist 6/2/2014 1.0
Updated by Bodmer Updated by Bodmer
@@ -21,7 +21,7 @@ TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; // Saved H, M, S x & y multipliers float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; // Saved H, M, S x & y multipliers
float sdeg=0, mdeg=0, hdeg=0; float sdeg=0, mdeg=0, hdeg=0;
uint16_t osx=64, osy=64, omx=64, omy=64, ohx=64, ohy=64; // Saved H, M, S x & y coords uint16_t osx=64, osy=64, omx=64, omy=64, ohx=64, ohy=64; // Saved H, M, S x & y coords
uint16_t x0=0, x1=0, y0=0, y1=0; uint16_t x0=0, x1=0, yy0=0, yy1=0;
uint32_t targetTime = 0; // for next 1 second timeout uint32_t targetTime = 0; // for next 1 second timeout
static uint8_t conv2d(const char* p) { static uint8_t conv2d(const char* p) {
@@ -50,11 +50,11 @@ void setup(void) {
sx = cos((i-90)*0.0174532925); sx = cos((i-90)*0.0174532925);
sy = sin((i-90)*0.0174532925); sy = sin((i-90)*0.0174532925);
x0 = sx*57+64; x0 = sx*57+64;
y0 = sy*57+64; yy0 = sy*57+64;
x1 = sx*50+64; x1 = sx*50+64;
y1 = sy*50+64; yy1 = sy*50+64;
tft.drawLine(x0, y0, x1, y1, ST7735_BLUE); tft.drawLine(x0, yy0, x1, yy1, ST7735_BLUE);
} }
// Draw 60 dots // Draw 60 dots
@@ -62,13 +62,13 @@ void setup(void) {
sx = cos((i-90)*0.0174532925); sx = cos((i-90)*0.0174532925);
sy = sin((i-90)*0.0174532925); sy = sin((i-90)*0.0174532925);
x0 = sx*53+64; x0 = sx*53+64;
y0 = sy*53+64; yy0 = sy*53+64;
tft.drawPixel(x0, y0, ST7735_BLUE); tft.drawPixel(x0, yy0, ST7735_BLUE);
if(i==0 || i==180) tft.fillCircle(x0, y0, 1, ST7735_CYAN); if(i==0 || i==180) tft.fillCircle(x0, yy0, 1, ST7735_CYAN);
if(i==0 || i==180) tft.fillCircle(x0+1, y0, 1, ST7735_CYAN); if(i==0 || i==180) tft.fillCircle(x0+1, yy0, 1, ST7735_CYAN);
if(i==90 || i==270) tft.fillCircle(x0, y0, 1, ST7735_CYAN); if(i==90 || i==270) tft.fillCircle(x0, yy0, 1, ST7735_CYAN);
if(i==90 || i==270) tft.fillCircle(x0+1, y0, 1, ST7735_CYAN); if(i==90 || i==270) tft.fillCircle(x0+1, yy0, 1, ST7735_CYAN);
} }
tft.fillCircle(65, 65, 3, ST7735_RED); tft.fillCircle(65, 65, 3, ST7735_RED);

View File

@@ -20,7 +20,7 @@ void loop() {
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
// Draw some random circles // Draw some random filled elipses
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
{ {
int rx = random(40); int rx = random(40);
@@ -33,6 +33,7 @@ void loop() {
delay(2000); delay(2000);
tft.fillScreen(TFT_BLACK); tft.fillScreen(TFT_BLACK);
// Draw some random outline elipses
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
{ {
int rx = random(40); int rx = random(40);

View File

@@ -3,35 +3,14 @@
This sketch used font 2, 4, 7 This sketch used font 2, 4, 7
Make sure all the required fonts are loaded by editting the Make sure all the display driver and pin comnenctions are correct by
User_Setup.h file in the TFT_eSPI library folder. editting the User_Setup.h file in the TFT_eSPI library folder.
The library uses the hardware SPI pins only: Note that yield() or delay(0) must be called in long duration for/while
For UNO, Nano, Micro Pro ATmega328 based processors loops to stop the ESP8266 watchdog triggering.
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
######################################################################### #########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
######################################################################### #########################################################################
*/ */
@@ -83,7 +62,8 @@ void loop() {
tft.print("Float = "); tft.println(fnumber); // Print floating point number tft.print("Float = "); tft.println(fnumber); // Print floating point number
tft.print("Binary = "); tft.println((int)fnumber, BIN); // Print as integer value in binary tft.print("Binary = "); tft.println((int)fnumber, BIN); // Print as integer value in binary
tft.print("Hexadecimal = "); tft.println((int)fnumber, HEX); // Print as integer number in Hexadecimal tft.print("Hexadecimal = "); tft.println((int)fnumber, HEX); // Print as integer number in Hexadecimal
while(1);
while(1) yield(); // We must yield() to stop a watchdog timeout.
} }

View File

@@ -2,28 +2,16 @@
An example showing rainbow colours on a 1.8" TFT LCD screen An example showing rainbow colours on a 1.8" TFT LCD screen
and to show a basic example of font use. and to show a basic example of font use.
This examples uses the hardware SPI only. Non-hardware SPI Make sure all the display driver and pin comnenctions are correct by
is just too slow (~8 times slower!) editting the User_Setup.h file in the TFT_eSPI library folder.
Updated by Bodmer Note that yield() or delay(0) must be called in long duration for/while
loops to stop the ESP8266 watchdog triggering.
Colours: #########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
code color #########################################################################
0x0000 Black */
0xFFFF White
0xBDF7 Light Gray
0x7BEF Dark Gray
0xF800 Red
0xFFE0 Yellow
0xFBE0 Orange
0x79E0 Brown
0x7E0 Green
0x7FF Cyan
0x1F Blue
0xF81F Pink
*/
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip #include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h> #include <SPI.h>
@@ -48,14 +36,16 @@ void setup(void) {
void loop() { void loop() {
if (targetTime < millis()) { if (targetTime < millis()) {
targetTime = millis()+10000; targetTime = millis() + 10000;
for (int i = 0; i<160; i++) {
// Colour changing state machine
for (int i = 0; i < 160; i++) {
tft.drawFastVLine(i, 0, tft.height(), colour); tft.drawFastVLine(i, 0, tft.height(), colour);
switch (state) { switch (state) {
case 0: case 0:
green +=2; green += 2;
if (green == 64) { if (green == 64) {
green=63; green = 63;
state = 1; state = 1;
} }
break; break;
@@ -69,14 +59,14 @@ void loop() {
case 2: case 2:
blue ++; blue ++;
if (blue == 32) { if (blue == 32) {
blue=31; blue = 31;
state = 3; state = 3;
} }
break; break;
case 3: case 3:
green -=2; green -= 2;
if (green ==255) { if (green == 255) {
green=0; green = 0;
state = 4; state = 4;
} }
break; break;
@@ -95,23 +85,29 @@ void loop() {
} }
break; break;
} }
colour = red<<11 | green<<5 | blue; colour = red << 11 | green << 5 | blue;
} }
// The standard ADAFruit font still works as berfore // The standard ADAFruit font still works as before
tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Note these fonts do not plot the background colour tft.setTextColor(ST7735_BLACK);
tft.setCursor (12, 5); tft.setCursor (12, 5);
tft.print("Original ADAfruit font!"); tft.print("Original ADAfruit font!");
// The new larger fonts do not use the .setCursor call, coords are embedded // The new larger fonts do not use the .setCursor call, coords are embedded
tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Do not plot the background colour tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Do not plot the background colour
// Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!) // Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!)
tft.drawCentreString("Font size 2",80,14,2); // Draw text centre at position 80, 12 using font 2 tft.drawCentreString("Font size 2", 80, 14, 2); // Draw text centre at position 80, 12 using font 2
//tft.drawCentreString("Font size 2",81,12,2); // Draw text centre at position 80, 12 using font 2 //tft.drawCentreString("Font size 2",81,12,2); // Draw text centre at position 80, 12 using font 2
tft.drawCentreString("Font size 4",80,30,4); // Draw text centre at position 80, 24 using font 4
tft.drawCentreString("12.34",80,54,6); // Draw text centre at position 80, 24 using font 6 tft.drawCentreString("Font size 4", 80, 30, 4); // Draw text centre at position 80, 24 using font 4
tft.drawCentreString("12.34 is in font size 6",80,92,2); // Draw text centre at position 80, 90 using font 2
// Note the x position is the top of the font! tft.drawCentreString("12.34", 80, 54, 6); // Draw text centre at position 80, 24 using font 6
tft.drawCentreString("12.34 is in font size 6", 80, 92, 2); // Draw text centre at position 80, 90 using font 2
// Note the x position is the top left of the font!
// draw a floating point number // draw a floating point number
float pi = 3.14159; // Value to print float pi = 3.14159; // Value to print
@@ -119,8 +115,8 @@ void loop() {
int xpos = 50; // x position int xpos = 50; // x position
int ypos = 110; // y position int ypos = 110; // y position
int font = 2; // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : a p m int font = 2; // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : a p m
xpos+=tft.drawFloat(pi,precision,xpos,ypos,font); // Draw rounded number and return new xpos delta for next print position xpos += tft.drawFloat(pi, precision, xpos, ypos, font); // Draw rounded number and return new xpos delta for next print position
tft.drawString(" is pi",xpos,ypos,font); // Continue printing from new x position tft.drawString(" is pi", xpos, ypos, font); // Continue printing from new x position
} }
} }

View File

@@ -1,38 +1,16 @@
/* /*
Adapted from the Adafruit and Xark's PDQ graphicstest sketch. Adapted from the Adafruit and Xark's PDQ graphicstest sketch.
This sketch uses the GLCD font only. Disable other fonts to make This sketch uses the GLCD font only.
the sketch fit in an UNO!
Make sure all the required fonts are loaded by editting the Make sure all the display driver and pin comnenctions are correct by
User_Setup.h file in the TFT_eSPI library folder. editting the User_Setup.h file in the TFT_eSPI library folder.
The library uses the hardware SPI pins only: Note that yield() or delay(0) must be called in long duration for/while
For UNO, Nano, Micro Pro ATmega328 based processors loops to stop the ESP8266 watchdog triggering.
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
######################################################################### #########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
######################################################################### #########################################################################
*/ */
@@ -61,10 +39,12 @@ void setup()
void loop(void) void loop(void)
{ {
Serial.print(F(__DATE__ " " __TIME__ " - Flash=0x")); Serial.print(F(__DATE__ " " __TIME__ " - Flash=0x"));
Serial.print((uint16_t)__data_load_end, HEX); // These are not compatible with the ESP8266 core library
Serial.print(F(" RAM=0x")); //Serial.print((uint16_t)__data_load_end, HEX);
Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX); //Serial.print(F(" RAM=0x"));
//Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX);
Serial.println(F("Benchmark Time (microseconds)")); Serial.println(F("Benchmark Time (microseconds)"));
uint32_t usecHaD = testHaD(); uint32_t usecHaD = testHaD();
@@ -159,17 +139,16 @@ void loop(void)
tft.setTextSize(1); tft.setTextSize(1);
tft.setTextColor(TFT_WHITE); tft.setTextColor(TFT_WHITE);
tft.print(F("SPI LCD on 328p")); tft.println(F("SPI TFT on ESP8266"));
tft.setTextColor(TFT_YELLOW); tft.println(F(""));
tft.print(F("@"));
tft.setTextColor(TFT_WHITE);
tft.print(F("16MHz"));
tft.setTextSize(1); tft.setTextSize(1);
tft.setTextColor(tft.color565(0x80, 0x80, 0x80)); tft.setTextColor(tft.color565(0x80, 0x80, 0x80));
tft.print(F("Flash=0x"));
tft.print((uint16_t)__data_load_end, HEX); // These are not compatible with the ESP8266 core library
tft.print(F(" RAM=0x")); //tft.print(F("Flash=0x"));
tft.print((uint16_t)_end - (uint16_t)__data_start, HEX); //tft.print((uint16_t)__data_load_end, HEX);
//tft.print(F(" RAM=0x"));
//tft.print((uint16_t)_end - (uint16_t)__data_start, HEX);
tft.setTextColor(TFT_GREEN); tft.setTextColor(TFT_GREEN);
tft.print(F("Benchmark usec")); tft.print(F("Benchmark usec"));

View File

@@ -4,39 +4,14 @@
This sketch uses the GLCD font (font 1) only. Disable other fonts to make This sketch uses the GLCD font (font 1) only. Disable other fonts to make
the sketch fit in an UNO! the sketch fit in an UNO!
Make sure all the required fonts are loaded by editting the Make sure all the display driver and pin comnenctions are correct by
User_Setup.h file in the TFT_eSPI library folder. editting the User_Setup.h file in the TFT_eSPI library folder.
If using an UNO or Mega (ATmega328 or ATmega2560 processor) then for best Note that yield() or delay(0) must be called in long duration for/while
performance use the F_AS_T option found in the User_Setup.h file in the loops to stop the ESP8266 watchdog triggering.
TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
######################################################################### #########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
######################################################################### #########################################################################
*/ */

View File

@@ -4,40 +4,18 @@
// //
/* /*
This sketch uses the GLCD and font 2 only. Disable other fonts to make This sketch uses the GLCD and font 2 only.
the sketch fit in an UNO!
Make sure all the required fonts are loaded by editting the Make sure all the display driver and pin comnenctions are correct by
User_Setup.h file in the TFT_eSPI library folder. editting the User_Setup.h file in the TFT_eSPI library folder.
The library uses the hardware SPI pins only: Note that yield() or delay(0) must be called in long duration for/while
For UNO, Nano, Micro Pro ATmega328 based processors loops to stop the ESP8266 watchdog triggering.
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
######################################################################### #########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
######################################################################### #########################################################################
*/ */
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip #include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h> #include <SPI.h>
@@ -54,99 +32,95 @@ unsigned long runTime = 0;
void setup() void setup()
{ {
randomSeed(analogRead(A0)); randomSeed(analogRead(A0));
pinMode(7, OUTPUT); // Setup the LCD
digitalWrite(7, LOW);
delay(10);
digitalWrite(7, HIGH);
// Setup the LCD
myGLCD.init(); myGLCD.init();
myGLCD.setRotation(1); myGLCD.setRotation(1);
} }
void loop() void loop()
{ {
randomSeed(millis()); //randomSeed(millis());
//randomSeed(1234); // This ensure test is repeatable with exact same draws each loop randomSeed(1234); // This ensure test is repeatable with exact same draws each loop
int buf[TFT_W-2]; int buf[TFT_W - 2];
int x, x2; int x, x2;
int y, y2; int y, y2;
int r; int r;
runTime = millis(); runTime = millis();
// Clear the screen and draw the frame // Clear the screen and draw the frame
myGLCD.fillScreen(TFT_BLACK); myGLCD.fillScreen(TFT_BLACK);
myGLCD.fillRect(0, 0, TFT_W-1, 14,TFT_RED); myGLCD.fillRect(0, 0, TFT_W - 1, 14, TFT_RED);
myGLCD.fillRect(0, TFT_H-14, TFT_W-1, 14,TFT_GREY); myGLCD.fillRect(0, TFT_H - 14, TFT_W - 1, 14, TFT_GREY);
myGLCD.setTextColor(TFT_BLACK,TFT_RED); myGLCD.setTextColor(TFT_BLACK, TFT_RED);
myGLCD.drawCentreString("* TFT_S6D02A1 *", TFT_W/2, 4, 1); myGLCD.drawCentreString("* TFT_S6D02A1 *", TFT_W / 2, 4, 1);
myGLCD.setTextColor(TFT_YELLOW,TFT_GREY); myGLCD.setTextColor(TFT_YELLOW, TFT_GREY);
myGLCD.drawCentreString("Adapted by Bodmer", TFT_W/2, TFT_H-12,1); myGLCD.drawCentreString("Adapted by Bodmer", TFT_W / 2, TFT_H - 12, 1);
myGLCD.drawRect(0, 14, TFT_W-1, TFT_H-28, TFT_BLUE); myGLCD.drawRect(0, 14, TFT_W - 1, TFT_H - 28, TFT_BLUE);
// Draw crosshairs // Draw crosshairs
myGLCD.drawLine(TFT_W/2-1, 15, TFT_W/2-1, TFT_H-16,TFT_BLUE); myGLCD.drawLine(TFT_W / 2 - 1, 15, TFT_W / 2 - 1, TFT_H - 16, TFT_BLUE);
myGLCD.drawLine(1, TFT_H/2-1, TFT_W-2, TFT_H/2-1,TFT_BLUE); myGLCD.drawLine(1, TFT_H / 2 - 1, TFT_W - 2, TFT_H / 2 - 1, TFT_BLUE);
for (int i=9; i<TFT_W-1; i+=10) for (int i = 9; i < TFT_W - 1; i += 10)
myGLCD.drawLine(i, TFT_H/2-3, i, TFT_H/2+1,TFT_BLUE); myGLCD.drawLine(i, TFT_H / 2 - 3, i, TFT_H / 2 + 1, TFT_BLUE);
for (int i=19; i<TFT_H-20; i+=10) for (int i = 19; i < TFT_H - 20; i += 10)
myGLCD.drawLine(TFT_W/2-3, i, TFT_W/2+1, i,TFT_BLUE); myGLCD.drawLine(TFT_W / 2 - 3, i, TFT_W / 2 + 1, i, TFT_BLUE);
// Draw sin-, cos- and tan-lines // Draw sin-, cos- and tan-lines
myGLCD.setTextColor(TFT_CYAN); myGLCD.setTextColor(TFT_CYAN);
myGLCD.drawString("Sin", 5, 15,2); myGLCD.drawString("Sin", 5, 15, 2);
for (int i=1; i<TFT_W-2; i++) for (int i = 1; i < TFT_W - 2; i++)
{ {
myGLCD.drawPixel(i,TFT_H/2-1+(sin(((i*2.26)*3.14)/180)*48),TFT_CYAN); myGLCD.drawPixel(i, TFT_H / 2 - 1 + (sin(((i * 2.26) * 3.14) / 180) * 48), TFT_CYAN);
} }
myGLCD.setTextColor(TFT_RED); myGLCD.setTextColor(TFT_RED);
myGLCD.drawString("Cos", 5, 30,2); myGLCD.drawString("Cos", 5, 30, 2);
for (int i=1; i<TFT_W-2; i++) for (int i = 1; i < TFT_W - 2; i++)
{ {
myGLCD.drawPixel(i,TFT_H/2-1+(cos(((i*2.26)*3.14)/180)*48),TFT_RED); myGLCD.drawPixel(i, TFT_H / 2 - 1 + (cos(((i * 2.26) * 3.14) / 180) * 48), TFT_RED);
} }
myGLCD.setTextColor(TFT_YELLOW); myGLCD.setTextColor(TFT_YELLOW);
myGLCD.drawString("Tan", 5, 45,2); myGLCD.drawString("Tan", 5, 45, 2);
for (int i=1; i<TFT_W-2; i++) for (int i = 1; i < TFT_W - 2; i++)
{ {
myGLCD.drawPixel(i,TFT_H/2-1+(tan(((i*2.26)*3.14)/180)),TFT_YELLOW); myGLCD.drawPixel(i, TFT_H / 2 - 1 + (tan(((i * 2.26) * 3.14) / 180)), TFT_YELLOW);
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
myGLCD.drawLine(TFT_W/2-1, 15, TFT_W/2-1, TFT_H-16,TFT_BLUE); myGLCD.drawLine(TFT_W / 2 - 1, 15, TFT_W / 2 - 1, TFT_H - 16, TFT_BLUE);
myGLCD.drawLine(1, TFT_H/2-1, TFT_W-2, TFT_H/2-1,TFT_BLUE); myGLCD.drawLine(1, TFT_H / 2 - 1, TFT_W - 2, TFT_H / 2 - 1, TFT_BLUE);
int col = 0; int col = 0;
// Draw a moving sinewave // Draw a moving sinewave
x=1; x = 1;
for (int i=1; i<((TFT_W-3)*20); i++) for (int i = 1; i < ((TFT_W - 3) * 20); i++)
{ {
x++; x++;
if (x==TFT_W-2) if (x == TFT_W - 2)
x=1; x = 1;
if (i>TFT_W-2) if (i > TFT_W - 2)
{ {
if ((x==TFT_W/2-1)||(buf[x-1]==TFT_H/2-1)) if ((x == TFT_W / 2 - 1) || (buf[x - 1] == TFT_H / 2 - 1))
col = TFT_BLUE; col = TFT_BLUE;
else else
myGLCD.drawPixel(x,buf[x-1],TFT_BLACK); myGLCD.drawPixel(x, buf[x - 1], TFT_BLACK);
} }
y=TFT_H/2 +(sin(((i*2.2)*3.14)/180)*(49-(i / 100))); y = TFT_H / 2 + (sin(((i * 2.2) * 3.14) / 180) * (49 - (i / 100)));
myGLCD.drawPixel(x,y,TFT_BLUE); myGLCD.drawPixel(x, y, TFT_BLUE);
buf[x-1]=y; buf[x - 1] = y;
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
// Draw some filled rectangles // Draw some filled rectangles
for (int i=1; i<6; i++) for (int i = 1; i < 6; i++)
{ {
switch (i) switch (i)
{ {
@@ -166,15 +140,15 @@ int col = 0;
col = TFT_YELLOW; col = TFT_YELLOW;
break; break;
} }
myGLCD.fillRect(30+(i*10), 20+(i*10), 30, 30,col); myGLCD.fillRect(30 + (i * 10), 20 + (i * 10), 30, 30, col);
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
// Draw some filled, rounded rectangles // Draw some filled, rounded rectangles
for (int i=1; i<6; i++) for (int i = 1; i < 6; i++)
{ {
switch (i) switch (i)
{ {
@@ -194,15 +168,15 @@ int col = 0;
col = TFT_YELLOW; col = TFT_YELLOW;
break; break;
} }
myGLCD.fillRoundRect(TFT_W/2+20-(i*10), 20+(i*10), 30,30, 3,col); myGLCD.fillRoundRect(TFT_W / 2 + 20 - (i * 10), 20 + (i * 10), 30, 30, 3, col);
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
// Draw some filled circles // Draw some filled circles
for (int i=1; i<6; i++) for (int i = 1; i < 6; i++)
{ {
switch (i) switch (i)
{ {
@@ -222,142 +196,147 @@ int col = 0;
col = TFT_YELLOW; col = TFT_YELLOW;
break; break;
} }
myGLCD.fillCircle(45+(i*10),30+(i*10), 15,col); myGLCD.fillCircle(45 + (i * 10), 30 + (i * 10), 15, col);
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
// Draw some lines in a pattern // Draw some lines in a pattern
for (int i=15; i<TFT_H-16; i+=5) for (int i = 15; i < TFT_H - 16; i += 5)
{ {
myGLCD.drawLine(1, i, (i*1.44)-10, TFT_H-17,TFT_RED); myGLCD.drawLine(1, i, (i * 1.44) - 10, TFT_H - 17, TFT_RED);
} }
for (int i=TFT_H-17; i>15; i-=5) for (int i = TFT_H - 17; i > 15; i -= 5)
{ {
myGLCD.drawLine(TFT_W-3, i, (i*1.44)-11, 15,TFT_RED); myGLCD.drawLine(TFT_W - 3, i, (i * 1.44) - 11, 15, TFT_RED);
} }
for (int i=TFT_H-17; i>15; i-=5) for (int i = TFT_H - 17; i > 15; i -= 5)
{ {
myGLCD.drawLine(1, i, TFT_W+11-(i*1.44), 15,TFT_CYAN); myGLCD.drawLine(1, i, TFT_W + 11 - (i * 1.44), 15, TFT_CYAN);
} }
for (int i=15; i<TFT_H-16; i+=5) for (int i = 15; i < TFT_H - 16; i += 5)
{ {
myGLCD.drawLine(TFT_W-3, i, TFT_W+10-(i*1.44), TFT_H-17,TFT_CYAN); myGLCD.drawLine(TFT_W - 3, i, TFT_W + 10 - (i * 1.44), TFT_H - 17, TFT_CYAN);
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
// Draw some random circles // Draw some random circles
for (int i=0; i<100; i++) for (int i = 0; i < 100; i++)
{ {
x=32+random(TFT_W-2-32-30); x = 32 + random(TFT_W - 2 - 32 - 30);
y=45+random(TFT_H-19-45-30); y = 45 + random(TFT_H - 19 - 45 - 30);
r=random(30); r = random(30);
myGLCD.drawCircle(x, y, r,random(0xFFFF)); myGLCD.drawCircle(x, y, r, random(0xFFFF));
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
// Draw some random rectangles // Draw some random rectangles
for (int i=0; i<100; i++) for (int i = 0; i < 100; i++)
{ {
x=2+random(TFT_W-4); x = 2 + random(TFT_W - 4);
y=16+random(TFT_H-33); y = 16 + random(TFT_H - 33);
x2=2+random(TFT_H-4); x2 = 2 + random(TFT_H - 4);
y2=16+random(TFT_H-33); y2 = 16 + random(TFT_H - 33);
if (x2<x) { if (x2 < x) {
r=x;x=x2;x2=r; r = x; x = x2; x2 = r;
} }
if (y2<y) { if (y2 < y) {
r=y;y=y2;y2=r; r = y; y = y2; y2 = r;
} }
myGLCD.drawRect(x, y, x2-x, y2-y,random(0xFFFF)); myGLCD.drawRect(x, y, x2 - x, y2 - y, random(0xFFFF));
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
// Draw some random rounded rectangles // Draw some random rounded rectangles
for (int i=0; i<100; i++) for (int i = 0; i < 100; i++)
{ {
x=2+random(TFT_W-4); x = 2 + random(TFT_W - 4);
y=16+random(TFT_H-33); y = 16 + random(TFT_H - 33);
x2=2+random(TFT_W-4); x2 = 2 + random(TFT_W - 4);
y2=16+random(TFT_H-33); y2 = 16 + random(TFT_H - 33);
// We need to get the width and height and do some window checking // We need to get the width and height and do some window checking
if (x2<x) { if (x2 < x) {
r=x;x=x2;x2=r; r = x; x = x2; x2 = r;
} }
if (y2<y) { if (y2 < y) {
r=y;y=y2;y2=r; r = y; y = y2; y2 = r;
} }
// We need a minimum size of 6 // We need a minimum size of 6
if((x2-x)<6) x2=x+6; if ((x2 - x) < 6) x2 = x + 6;
if((y2-y)<6) y2=y+6; if ((y2 - y) < 6) y2 = y + 6;
myGLCD.drawRoundRect(x, y, x2-x,y2-y, 3,random(0xFFFF)); myGLCD.drawRoundRect(x, y, x2 - x, y2 - y, 3, random(0xFFFF));
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
//randomSeed(1234); //randomSeed(1234);
int colour = 0; int colour = 0;
for (int i=0; i<100; i++) for (int i = 0; i < 100; i++)
{ {
x=2+random(TFT_W-4); x = 2 + random(TFT_W - 4);
y=16+random(TFT_H-31); y = 16 + random(TFT_H - 31);
x2=2+random(TFT_W-4); x2 = 2 + random(TFT_W - 4);
y2=16+random(TFT_H-31); y2 = 16 + random(TFT_H - 31);
colour=random(0xFFFF); colour = random(0xFFFF);
myGLCD.drawLine(x, y, x2, y2,colour); myGLCD.drawLine(x, y, x2, y2, colour);
} }
delay(DELAY); delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK);
// This test has been modified as it takes more time to calculate the random numbers #define RANDOM
// than to draw the pixels (3 seconds to produce 30,000 randoms)!
//for (int i=0; i<10000; i++)
//{
// myGLCD.drawPixel(2+random(316), 16+random(209),random(0xFFFF));
//}
// Draw 10,000 pixels to fill a 100x100 pixel box #ifdef RANDOM
// Draw 10,000 pixels
// It takes 30ms to calculate the 30,000 random numbers so this is not a true drawPixel speed test
for (int i=0; i<10000; i++)
{
myGLCD.drawPixel(2+random(316), 16+random(209),random(0xFFFF));
}
#else
// Draw 10,000 pixels to fill a 100x100 pixel box, better drawPixel speed test
// use the coords as the colour to produce the banding // use the coords as the colour to produce the banding
byte i = 100; byte i = 100;
while (i--) { while (i--) {
byte j = 100; byte j = 100;
while (j--) myGLCD.drawPixel(i+TFT_W/2-50,j+TFT_H/2-50,i+j); while (j--) myGLCD.drawPixel(i + TFT_W / 2 - 50, j + TFT_H / 2 - 50, i + j);
} }
#endif
delay(DELAY); delay(DELAY);
myGLCD.fillScreen(TFT_BLUE); myGLCD.fillScreen(TFT_BLUE);
myGLCD.fillRoundRect(20, 20, TFT_W-40, TFT_H-60, 6,TFT_RED); myGLCD.fillRoundRect(20, 20, TFT_W - 40, TFT_H - 60, 6, TFT_RED);
myGLCD.setTextColor(TFT_WHITE,TFT_RED); myGLCD.setTextColor(TFT_WHITE, TFT_RED);
myGLCD.drawCentreString("That's it!", TFT_W/2-1, 23,2); myGLCD.drawCentreString("That's it!", TFT_W / 2 - 1, 23, 2);
myGLCD.drawCentreString("Restarting in a", TFT_W/2-1, 40,2); myGLCD.drawCentreString("Restarting in a", TFT_W / 2 - 1, 40, 2);
myGLCD.drawCentreString("few seconds...", TFT_W/2-1, 57,2); myGLCD.drawCentreString("few seconds...", TFT_W / 2 - 1, 57, 2);
runTime = millis()-runTime; runTime = millis() - runTime;
myGLCD.setTextColor(TFT_GREEN,TFT_BLUE); myGLCD.setTextColor(TFT_GREEN, TFT_BLUE);
myGLCD.drawCentreString("Draw time: (msecs)", TFT_W/2, TFT_H-34,2); myGLCD.drawCentreString("Draw time: (msecs)", TFT_W / 2, TFT_H - 34, 2);
myGLCD.drawNumber(runTime-11*DELAY, TFT_W/2-20, TFT_H-17,2); myGLCD.drawNumber(runTime - 11 * DELAY, TFT_W / 2 - 20, TFT_H - 17, 2);
delay (5000); delay (5000);
} }