diff --git a/examples/ST7735/Arduino_Life/Arduino_Life.ino b/examples/ST7735/Arduino_Life/Arduino_Life.ino index 11059e3..cdb0d31 100644 --- a/examples/ST7735/Arduino_Life/Arduino_Life.ino +++ b/examples/ST7735/Arduino_Life/Arduino_Life.ino @@ -2,20 +2,32 @@ //devised by the British mathematician John Horton Conway in 1970. // https://en.wikipedia.org/wiki/Conway's_Game_of_Life +// See license at end of file. +// Adapted by Bodmer #include // Hardware-specific library #include TFT_eSPI tft = TFT_eSPI(); // Invoke custom library -#define GRIDX 32 -#define GRIDY 24 -#define CELLXY 5 +// Maximum number of generations until the screen is refreshed +#define MAX_GEN_COUNT 500 -#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]; //The new grid for the next generation @@ -55,7 +67,7 @@ void loop() { initGrid(); - genCount = 300; + genCount = MAX_GEN_COUNT; drawGrid(); diff --git a/examples/ST7735/Flash_Bitmap2/Alert.h b/examples/ST7735/Flash_Bitmap2/Alert.h index 66d845e..54d013d 100644 --- a/examples/ST7735/Flash_Bitmap2/Alert.h +++ b/examples/ST7735/Flash_Bitmap2/Alert.h @@ -1,5 +1,5 @@ // We need this header file to use FLASH as storage with PROGMEM directive: -#include +#include // Icon width and height const uint16_t alertWidth = 32; diff --git a/examples/ST7735/Flash_Bitmap2/Close.h b/examples/ST7735/Flash_Bitmap2/Close.h index 817b4b6..c16d522 100644 --- a/examples/ST7735/Flash_Bitmap2/Close.h +++ b/examples/ST7735/Flash_Bitmap2/Close.h @@ -1,5 +1,5 @@ // We need this header file to use FLASH as storage with PROGMEM directive: -#include +#include // Icon width and height const uint16_t closeWidth = 32; diff --git a/examples/ST7735/Flash_Bitmap2/Flash_Bitmap2.ino b/examples/ST7735/Flash_Bitmap2/Flash_Bitmap2.ino index a5ce005..3cf517a 100644 --- a/examples/ST7735/Flash_Bitmap2/Flash_Bitmap2.ino +++ b/examples/ST7735/Flash_Bitmap2/Flash_Bitmap2.ino @@ -8,6 +8,7 @@ // Icons are stored in tabs, e.g. Alert.h etc // 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. @@ -42,7 +43,7 @@ void setup() tft.fillScreen(TFT_BLACK); // Draw the icons - drawIcon(info, (tft.width() - infoWidth)/2 - 50, (tft.height() - infoHeight)/2, infoWidth, infoHeight); + drawIcon(info, (tft.width() - infoWidth)/2 - 50, (tft.height() - infoHeight)/2, infoWidth, infoHeight); drawIcon(alert, (tft.width() - alertWidth)/2, (tft.height() - alertHeight)/2, alertWidth, alertHeight); drawIcon(close, (tft.width() - closeWidth)/2 + 50, (tft.height() - closeHeight)/2, closeWidth, closeHeight); @@ -54,7 +55,7 @@ void setup() void loop() { // Loop filling and clearing screen - drawIcon(info, random(tft.width() - infoWidth), random(tft.height() - infoHeight), infoWidth, infoHeight); + drawIcon(info, random(tft.width() - infoWidth), random(tft.height() - infoHeight), infoWidth, infoHeight); drawIcon(alert, random(tft.width() - alertWidth), random(tft.height() - alertHeight), alertWidth, alertHeight); drawIcon(close, random(tft.width() - closeWidth), random(tft.height() - closeHeight), alertWidth, closeHeight); diff --git a/examples/ST7735/Flash_Bitmap2/Info.h b/examples/ST7735/Flash_Bitmap2/Info.h index a7cd024..c4ee633 100644 --- a/examples/ST7735/Flash_Bitmap2/Info.h +++ b/examples/ST7735/Flash_Bitmap2/Info.h @@ -1,5 +1,5 @@ // We need this header file to use FLASH as storage with PROGMEM directive: -#include +#include // Icon width and height const uint16_t infoWidth = 32; diff --git a/examples/ST7735/Pong_v3/Pong_v3.ino b/examples/ST7735/Pong_v3/Pong_v3.ino index 16c9bcf..7c51299 100644 --- a/examples/ST7735/Pong_v3/Pong_v3.ino +++ b/examples/ST7735/Pong_v3/Pong_v3.ino @@ -16,7 +16,7 @@ TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h int16_t h = 128; int16_t w = 160; -int dly = 5; +int dly = 10; int16_t paddle_h = 25; int16_t paddle_w = 2; @@ -98,7 +98,7 @@ void initgame() { tft.fillRect(0,h-26,w,h-1,BLACK); tft.setTextDatum(TC_DATUM); - tft.setTextColor(WHITE,GREY); + tft.setTextColor(WHITE); tft.drawString("TFT_eSPI example", w/2, h-26 , 2); } diff --git a/examples/ST7735/RLE_Font_test/RLE_Font_test.ino b/examples/ST7735/RLE_Font_test/RLE_Font_test.ino index 8684efd..315d096 100644 --- a/examples/ST7735/RLE_Font_test/RLE_Font_test.ino +++ b/examples/ST7735/RLE_Font_test/RLE_Font_test.ino @@ -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 - Make sure all the required fonts are loaded by editting the - User_Setup.h file in the TFT_eSPI library folder. + Make sure all the display driver and pin comnenctions are correct by + 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 ###### - ###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ###### - ######################################################################### - */ + ######################################################################### + ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### + ######################################################################### +*/ // New background colour #define TFT_BROWN 0x38E0 diff --git a/examples/ST7735/TFT_7735_Meter_5/TFT_7735_Meter_5.ino b/examples/ST7735/TFT_7735_Meter_5/TFT_7735_Meter_5.ino index a1969ea..3de25f2 100644 --- a/examples/ST7735/TFT_7735_Meter_5/TFT_7735_Meter_5.ino +++ b/examples/ST7735/TFT_7735_Meter_5/TFT_7735_Meter_5.ino @@ -143,7 +143,7 @@ void analogMeter() } 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 plotNeedle(0, 0); // Put meter needle at 0 @@ -187,7 +187,7 @@ void plotNeedle(int value, byte ms_delay) // Re-plot text under needle 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 ltx = tx; diff --git a/examples/ST7735/TFT_Char_times/TFT_Char_times.ino b/examples/ST7735/TFT_Char_times/TFT_Char_times.ino index 944733d..5e4d3a8 100644 --- a/examples/ST7735/TFT_Char_times/TFT_Char_times.ino +++ b/examples/ST7735/TFT_Char_times/TFT_Char_times.ino @@ -6,40 +6,15 @@ Needs fonts 2, 4, 6, 7 and 8 - Make sure all the required fonts are loaded by editting the - User_Setup.h file in the TFT_eSPI library folder. + Make sure all the display driver and pin comnenctions are correct by + 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. + Note that yield() or delay(0) must be called in long duration for/while + loops to stop the ESP8266 watchdog triggering. - 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 ###### - ###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ###### - ######################################################################### + ######################################################################### + ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### + ######################################################################### */ @@ -108,7 +83,7 @@ void loop() { drawTime = millis(); for (int i = 0; i < 1000; i++) { - tft.drawNumber(i, 0, 0, 6); + yield(); tft.drawNumber(i, 0, 0, 6); } drawTime = millis() - drawTime; @@ -123,7 +98,7 @@ void loop() { drawTime = millis(); for (int i = 0; i < 1000; i++) { - tft.drawNumber(i, 0, 0, 7); + yield(); tft.drawNumber(i, 0, 0, 7); } drawTime = millis() - drawTime; @@ -138,7 +113,7 @@ void loop() { drawTime = millis(); for (int i = 0; i < 100; i++) { - tft.drawNumber(i, 0, 0, 8); + yield(); tft.drawNumber(i, 0, 0, 8); } drawTime = millis() - drawTime; diff --git a/examples/ST7735/TFT_Clock_Digital_ST7735/TFT_Clock_Digital_ST7735.ino b/examples/ST7735/TFT_Clock_Digital_ST7735/TFT_Clock_Digital_ST7735.ino index 4531b48..9d9e623 100644 --- a/examples/ST7735/TFT_Clock_Digital_ST7735/TFT_Clock_Digital_ST7735.ino +++ b/examples/ST7735/TFT_Clock_Digital_ST7735/TFT_Clock_Digital_ST7735.ino @@ -95,7 +95,7 @@ void loop() { 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 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 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 @@ -118,7 +118,7 @@ void loop() { else { tft.drawChar(':',xcolon,ypos,7); 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.setTextColor(colour); tft.drawRightString("Colour",75,64,4); // Right justified string drawing to x position 75 diff --git a/examples/ST7735/TFT_Clock_ST7735/TFT_Clock_ST7735.ino b/examples/ST7735/TFT_Clock_ST7735/TFT_Clock_ST7735.ino index 0a6b8eb..f9eeeb9 100644 --- a/examples/ST7735/TFT_Clock_ST7735/TFT_Clock_ST7735.ino +++ b/examples/ST7735/TFT_Clock_ST7735/TFT_Clock_ST7735.ino @@ -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. + For a more accurate clock, it would be better to use the RTClib library. But this is just a demo. - - This examples uses the hardware SPI only. Non-hardware SPI - is just too slow (~8 times slower!) + + Uses compile time to set the time so a reset will start with the compile time again Gilchrist 6/2/2014 1.0 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 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 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 static uint8_t conv2d(const char* p) { @@ -50,11 +50,11 @@ void setup(void) { sx = cos((i-90)*0.0174532925); sy = sin((i-90)*0.0174532925); x0 = sx*57+64; - y0 = sy*57+64; + yy0 = sy*57+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 @@ -62,13 +62,13 @@ void setup(void) { sx = cos((i-90)*0.0174532925); sy = sin((i-90)*0.0174532925); x0 = sx*53+64; - y0 = sy*53+64; + yy0 = sy*53+64; - tft.drawPixel(x0, y0, ST7735_BLUE); - if(i==0 || i==180) tft.fillCircle(x0, y0, 1, ST7735_CYAN); - if(i==0 || i==180) tft.fillCircle(x0+1, y0, 1, ST7735_CYAN); - if(i==90 || i==270) tft.fillCircle(x0, y0, 1, ST7735_CYAN); - if(i==90 || i==270) tft.fillCircle(x0+1, y0, 1, ST7735_CYAN); + tft.drawPixel(x0, yy0, ST7735_BLUE); + if(i==0 || i==180) tft.fillCircle(x0, yy0, 1, ST7735_CYAN); + if(i==0 || i==180) tft.fillCircle(x0+1, yy0, 1, ST7735_CYAN); + if(i==90 || i==270) tft.fillCircle(x0, yy0, 1, ST7735_CYAN); + if(i==90 || i==270) tft.fillCircle(x0+1, yy0, 1, ST7735_CYAN); } tft.fillCircle(65, 65, 3, ST7735_RED); diff --git a/examples/ST7735/TFT_Ellipse/TFT_Ellipse.ino b/examples/ST7735/TFT_Ellipse/TFT_Ellipse.ino index d3c3eb4..1e8b86c 100644 --- a/examples/ST7735/TFT_Ellipse/TFT_Ellipse.ino +++ b/examples/ST7735/TFT_Ellipse/TFT_Ellipse.ino @@ -1,6 +1,6 @@ /* Ellipse drawing example - + This sketch does not use any fonts. */ @@ -20,7 +20,7 @@ void loop() { tft.fillScreen(TFT_BLACK); - // Draw some random circles + // Draw some random filled elipses for (int i = 0; i < 20; i++) { int rx = random(40); @@ -33,6 +33,7 @@ void loop() { delay(2000); tft.fillScreen(TFT_BLACK); + // Draw some random outline elipses for (int i = 0; i < 20; i++) { int rx = random(40); diff --git a/examples/ST7735/TFT_Print_Test/TFT_Print_Test.ino b/examples/ST7735/TFT_Print_Test/TFT_Print_Test.ino index f8ca563..a89c349 100644 --- a/examples/ST7735/TFT_Print_Test/TFT_Print_Test.ino +++ b/examples/ST7735/TFT_Print_Test/TFT_Print_Test.ino @@ -3,36 +3,15 @@ This sketch used font 2, 4, 7 - Make sure all the required fonts are loaded by editting the - User_Setup.h file in the TFT_eSPI library folder. + Make sure all the display driver and pin comnenctions are correct by + editting 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 + Note that yield() or delay(0) must be called in long duration for/while + loops to stop the ESP8266 watchdog triggering. - 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 ###### - ###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ###### - ######################################################################### + ######################################################################### + ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### + ######################################################################### */ @@ -83,7 +62,8 @@ void loop() { 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("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. } diff --git a/examples/ST7735/TFT_Rainbow_ST7735/TFT_Rainbow_ST7735.ino b/examples/ST7735/TFT_Rainbow_ST7735/TFT_Rainbow_ST7735.ino index cb38926..c99d526 100644 --- a/examples/ST7735/TFT_Rainbow_ST7735/TFT_Rainbow_ST7735.ino +++ b/examples/ST7735/TFT_Rainbow_ST7735/TFT_Rainbow_ST7735.ino @@ -1,29 +1,17 @@ /* - An example showing rainbow colours on a 1.8" TFT LCD screen - and to show a basic example of font use. - - This examples uses the hardware SPI only. Non-hardware SPI - is just too slow (~8 times slower!) - - Updated by Bodmer - - Colours: - - 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 - - */ + An example showing rainbow colours on a 1.8" TFT LCD screen + and to show a basic example of font use. + + Make sure all the display driver and pin comnenctions are correct by + editting the User_Setup.h file in the TFT_eSPI library folder. + + Note that yield() or delay(0) must be called in long duration for/while + loops to stop the ESP8266 watchdog triggering. + + ######################################################################### + ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### + ######################################################################### +*/ #include // Graphics and font library for ST7735 driver chip #include @@ -42,85 +30,93 @@ void setup(void) { tft.setRotation(1); tft.fillScreen(ST7735_BLACK); - targetTime = millis() + 1000; + targetTime = millis() + 1000; } void loop() { if (targetTime < millis()) { - targetTime = millis()+10000; - for (int i = 0; i<160; i++) { + targetTime = millis() + 10000; + + // Colour changing state machine + for (int i = 0; i < 160; i++) { tft.drawFastVLine(i, 0, tft.height(), colour); switch (state) { - case 0: - green +=2; - if (green == 64) { - green=63; - state = 1; - } - break; - case 1: - red--; - if (red == 255) { - red = 0; - state = 2; - } - break; - case 2: - blue ++; - if (blue == 32) { - blue=31; - state = 3; - } - break; - case 3: - green -=2; - if (green ==255) { - green=0; - state = 4; - } - break; - case 4: - red ++; - if (red == 32) { - red = 31; - state = 5; - } - break; - case 5: - blue --; - if (blue == 255) { - blue = 0; - state = 0; - } - break; + case 0: + green += 2; + if (green == 64) { + green = 63; + state = 1; + } + break; + case 1: + red--; + if (red == 255) { + red = 0; + state = 2; + } + break; + case 2: + blue ++; + if (blue == 32) { + blue = 31; + state = 3; + } + break; + case 3: + green -= 2; + if (green == 255) { + green = 0; + state = 4; + } + break; + case 4: + red ++; + if (red == 32) { + red = 31; + state = 5; + } + break; + case 5: + blue --; + if (blue == 255) { + blue = 0; + state = 0; + } + break; } - colour = red<<11 | green<<5 | blue; + colour = red << 11 | green << 5 | blue; } - - // The standard ADAFruit font still works as berfore - tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Note these fonts do not plot the background colour + + // The standard ADAFruit font still works as before + tft.setTextColor(ST7735_BLACK); tft.setCursor (12, 5); tft.print("Original ADAfruit font!"); - + // 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 + // 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 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("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("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("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 float pi = 3.14159; // Value to print int precision = 3; // Number of digits after decimal point int xpos = 50; // x 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 - 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 + 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 } } diff --git a/examples/ST7735/TFT_graphicstest_PDQ3/TFT_graphicstest_PDQ3.ino b/examples/ST7735/TFT_graphicstest_PDQ3/TFT_graphicstest_PDQ3.ino index a295d2b..325b9a4 100644 --- a/examples/ST7735/TFT_graphicstest_PDQ3/TFT_graphicstest_PDQ3.ino +++ b/examples/ST7735/TFT_graphicstest_PDQ3/TFT_graphicstest_PDQ3.ino @@ -1,39 +1,17 @@ /* Adapted from the Adafruit and Xark's PDQ graphicstest sketch. - This sketch uses the GLCD font only. Disable other fonts to make - the sketch fit in an UNO! + This sketch uses the GLCD font only. - Make sure all the required fonts are loaded by editting the - User_Setup.h file in the TFT_eSPI library folder. + Make sure all the display driver and pin comnenctions are correct by + editting 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 + Note that yield() or delay(0) must be called in long duration for/while + loops to stop the ESP8266 watchdog triggering. - 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 ###### - ###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ###### - ######################################################################### + ######################################################################### + ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### + ######################################################################### */ @@ -61,10 +39,12 @@ void setup() void loop(void) { + Serial.print(F(__DATE__ " " __TIME__ " - Flash=0x")); - Serial.print((uint16_t)__data_load_end, HEX); - Serial.print(F(" RAM=0x")); - Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX); + // These are not compatible with the ESP8266 core library + //Serial.print((uint16_t)__data_load_end, HEX); + //Serial.print(F(" RAM=0x")); + //Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX); Serial.println(F("Benchmark Time (microseconds)")); uint32_t usecHaD = testHaD(); @@ -159,17 +139,16 @@ void loop(void) tft.setTextSize(1); tft.setTextColor(TFT_WHITE); - tft.print(F("SPI LCD on 328p")); - tft.setTextColor(TFT_YELLOW); - tft.print(F("@")); - tft.setTextColor(TFT_WHITE); - tft.print(F("16MHz")); + tft.println(F("SPI TFT on ESP8266")); + tft.println(F("")); tft.setTextSize(1); tft.setTextColor(tft.color565(0x80, 0x80, 0x80)); - tft.print(F("Flash=0x")); - tft.print((uint16_t)__data_load_end, HEX); - tft.print(F(" RAM=0x")); - tft.print((uint16_t)_end - (uint16_t)__data_start, HEX); + + // These are not compatible with the ESP8266 core library + //tft.print(F("Flash=0x")); + //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.print(F("Benchmark usec")); diff --git a/examples/ST7735/TFT_graphicstest_small/TFT_graphicstest_small.ino b/examples/ST7735/TFT_graphicstest_small/TFT_graphicstest_small.ino index 2735739..a6d70b7 100644 --- a/examples/ST7735/TFT_graphicstest_small/TFT_graphicstest_small.ino +++ b/examples/ST7735/TFT_graphicstest_small/TFT_graphicstest_small.ino @@ -4,40 +4,15 @@ This sketch uses the GLCD font (font 1) only. Disable other fonts to make the sketch fit in an UNO! - Make sure all the required fonts are loaded by editting the - User_Setup.h file in the TFT_eSPI library folder. + Make sure all the display driver and pin comnenctions are correct by + 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. + Note that yield() or delay(0) must be called in long duration for/while + loops to stop the ESP8266 watchdog triggering. - 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 ###### - ###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ###### - ######################################################################### + ######################################################################### + ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### + ######################################################################### */ diff --git a/examples/ST7735/UTFT_demo_fast/UTFT_demo_fast.ino b/examples/ST7735/UTFT_demo_fast/UTFT_demo_fast.ino index 1f786fa..1c8ec5a 100644 --- a/examples/ST7735/UTFT_demo_fast/UTFT_demo_fast.ino +++ b/examples/ST7735/UTFT_demo_fast/UTFT_demo_fast.ino @@ -4,40 +4,18 @@ // /* - This sketch uses the GLCD and font 2 only. Disable other fonts to make - the sketch fit in an UNO! + This sketch uses the GLCD and font 2 only. - Make sure all the required fonts are loaded by editting the - User_Setup.h file in the TFT_eSPI library folder. + Make sure all the display driver and pin comnenctions are correct by + editting 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 + Note that yield() or delay(0) must be called in long duration for/while + loops to stop the ESP8266 watchdog triggering. ######################################################################### ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ###### - ###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ###### ######################################################################### - */ +*/ #include // Graphics and font library for ST7735 driver chip #include @@ -54,99 +32,95 @@ unsigned long runTime = 0; void setup() { randomSeed(analogRead(A0)); - pinMode(7, OUTPUT); - digitalWrite(7, LOW); - delay(10); - digitalWrite(7, HIGH); -// Setup the LCD + // Setup the LCD myGLCD.init(); myGLCD.setRotation(1); } void loop() { - randomSeed(millis()); - //randomSeed(1234); // This ensure test is repeatable with exact same draws each loop - int buf[TFT_W-2]; + //randomSeed(millis()); + randomSeed(1234); // This ensure test is repeatable with exact same draws each loop + int buf[TFT_W - 2]; int x, x2; int y, y2; int r; runTime = millis(); -// Clear the screen and draw the frame + // Clear the screen and draw the frame 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.drawCentreString("* TFT_S6D02A1 *", TFT_W/2, 4, 1); - myGLCD.setTextColor(TFT_YELLOW,TFT_GREY); - myGLCD.drawCentreString("Adapted by Bodmer", TFT_W/2, TFT_H-12,1); + myGLCD.setTextColor(TFT_BLACK, TFT_RED); + myGLCD.drawCentreString("* TFT_S6D02A1 *", TFT_W / 2, 4, 1); + myGLCD.setTextColor(TFT_YELLOW, TFT_GREY); + 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 - 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); - for (int i=9; iTFT_W-2) + if (x == TFT_W - 2) + x = 1; + 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; 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))); - myGLCD.drawPixel(x,y,TFT_BLUE); - buf[x-1]=y; + y = TFT_H / 2 + (sin(((i * 2.2) * 3.14) / 180) * (49 - (i / 100))); + myGLCD.drawPixel(x, y, TFT_BLUE); + buf[x - 1] = y; } 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 - for (int i=1; i<6; i++) + // Draw some filled rectangles + for (int i = 1; i < 6; i++) { switch (i) { @@ -166,15 +140,15 @@ int col = 0; col = TFT_YELLOW; 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); - 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 - for (int i=1; i<6; i++) + // Draw some filled, rounded rectangles + for (int i = 1; i < 6; i++) { switch (i) { @@ -194,15 +168,15 @@ int col = 0; col = TFT_YELLOW; 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); - 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 - for (int i=1; i<6; i++) + // Draw some filled circles + for (int i = 1; i < 6; i++) { switch (i) { @@ -222,142 +196,147 @@ int col = 0; col = TFT_YELLOW; break; } - myGLCD.fillCircle(45+(i*10),30+(i*10), 15,col); - } - - delay(DELAY); - - myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK); - -// Draw some lines in a pattern - - for (int i=15; i15; i-=5) - { - myGLCD.drawLine(TFT_W-3, i, (i*1.44)-11, 15,TFT_RED); - } - - for (int i=TFT_H-17; i>15; i-=5) - { - myGLCD.drawLine(1, i, TFT_W+11-(i*1.44), 15,TFT_CYAN); - } - - for (int i=15; i 15; i -= 5) + { + myGLCD.drawLine(TFT_W - 3, i, (i * 1.44) - 11, 15, TFT_RED); + } + + for (int i = TFT_H - 17; i > 15; i -= 5) + { + myGLCD.drawLine(1, i, TFT_W + 11 - (i * 1.44), 15, TFT_CYAN); + } + + 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); + } + + delay(DELAY); + + + myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + + // Draw some random circles + for (int i = 0; i < 100; i++) + { + x = 32 + random(TFT_W - 2 - 32 - 30); + y = 45 + random(TFT_H - 19 - 45 - 30); + r = random(30); + myGLCD.drawCircle(x, y, r, random(0xFFFF)); + } + + delay(DELAY); + + myGLCD.fillRect(1, 15, TFT_W - 3, TFT_H - 31, TFT_BLACK); + + // Draw some random rectangles + for (int i = 0; i < 100; i++) + { + x = 2 + random(TFT_W - 4); + y = 16 + random(TFT_H - 33); + x2 = 2 + random(TFT_H - 4); + y2 = 16 + random(TFT_H - 33); + if (x2 < x) { + r = x; x = x2; x2 = r; } - if (y2