Add libraries, picocalc notes.
This commit is contained in:
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
Example for TFT_eSPI library
|
||||
|
||||
Created by Bodmer 31/12/16
|
||||
|
||||
This example draws all fonts (as used by the Adafruit_GFX library) onto the
|
||||
screen. These fonts are called the GFX Free Fonts (GFXFF) in this library.
|
||||
|
||||
The fonts are referenced by a short name, see the Free_Fonts.h file
|
||||
attached to this sketch.
|
||||
|
||||
Other True Type fonts could be converted using the utility within the
|
||||
"fontconvert" folder inside the library. This converted has also been
|
||||
copied from the Adafruit_GFX library.
|
||||
|
||||
Since these fonts are a recent addition Adafruit do not have a tutorial
|
||||
available yet on how to use the fontconvert utility. Linux users will
|
||||
no doubt figure it out! In the meantime there are 48 font files to use
|
||||
in sizes from 9 point to 24 point, and in normal, bold, and italic or
|
||||
oblique styles.
|
||||
|
||||
This example sketch uses both the print class and drawString() functions
|
||||
to plot text to the screen.
|
||||
|
||||
Make sure LOAD_GFXFF is defined in the User_Setup.h file within the
|
||||
library folder.
|
||||
|
||||
--------------------------- NOTE ----------------------------------------
|
||||
The free font encoding format does not lend itself easily to plotting
|
||||
the background without flicker. For values that changes on screen it is
|
||||
better to use Fonts 1- 8 which are encoded specifically for rapid
|
||||
drawing with background.
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
###### TO SELECT YOUR DISPLAY TYPE AND ENABLE FONTS ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
#define TEXT "aA MWyz~12" // Text that will be printed on screen in any font
|
||||
|
||||
#include "Free_Fonts.h" // Include the header file attached to this sketch
|
||||
|
||||
#include "SPI.h"
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
// Use hardware SPI
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
|
||||
unsigned long drawTime = 0;
|
||||
|
||||
void setup(void) {
|
||||
|
||||
tft.begin();
|
||||
|
||||
tft.setRotation(1);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Show all 48 fonts in centre of screen ( x,y coordinate 160,120)
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
// Where font sizes increase the screen is not cleared as the larger fonts overwrite
|
||||
// the smaller one with the background colour.
|
||||
|
||||
// Set text datum to middle centre
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
|
||||
// Set text colour to orange with black background
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
tft.fillScreen(TFT_BLACK); // Clear screen
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF1, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF1); // Select the font
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);// Print the string name of the font
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF2, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF2);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF3, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF3);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF4, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF4);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF5, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF5);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF6, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF6);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF7, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF7);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF8, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF8);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF9, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF9);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF10, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF10);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF11, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF11);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF12, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF12);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF13, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF13);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF14, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF14);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF15, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF15);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF16, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF16);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF17, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF17);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF18, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF18);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF19, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF19);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF20, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF20);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF21, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF21);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF22, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF22);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF23, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF23);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF24, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF24);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF25, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF25);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF26, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF26);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF27, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF27);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF28, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF28);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF29, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF29);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF30, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF30);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF31, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF31);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF32, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF32);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF33, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF33);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF34, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF34);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF35, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF35);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF36, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF36);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF37, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF37);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF38, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF38);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF39, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF39);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF40, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF40);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF41, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF41);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF42, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF42);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF43, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF43);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF44, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF44);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF45, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF45);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF46, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF46);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF47, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF47);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString(sFF48, 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(FF48);
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);
|
||||
delay(1000);
|
||||
|
||||
}
|
||||
|
||||
// There follows a crude way of flagging that this example sketch needs fonts which
|
||||
// have not been enbabled in the User_Setup.h file inside the TFT_HX8357 library.
|
||||
//
|
||||
// These lines produce errors during compile time if settings in User_Setup are not correct
|
||||
//
|
||||
// The error will be "does not name a type" but ignore this and read the text between ''
|
||||
// it will indicate which font or feature needs to be enabled
|
||||
//
|
||||
// Either delete all the following lines if you do not want warnings, or change the lines
|
||||
// to suit your sketch modifications.
|
||||
|
||||
#ifndef LOAD_GLCD
|
||||
//ERROR_Please_enable_LOAD_GLCD_in_User_Setup
|
||||
#endif
|
||||
|
||||
#ifndef LOAD_GFXFF
|
||||
ERROR_Please_enable_LOAD_GFXFF_in_User_Setup!
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,377 @@
|
||||
// Attach this header file to your sketch to use the GFX Free Fonts. You can write
|
||||
// sketches without it, but it makes referencing them easier.
|
||||
|
||||
// This calls up ALL the fonts but they only get loaded if you actually
|
||||
// use them in your sketch.
|
||||
//
|
||||
// No changes are needed to this header file unless new fonts are added to the
|
||||
// library "Fonts/GFXFF" folder.
|
||||
//
|
||||
// To save a lot of typing long names, each font can easily be referenced in the
|
||||
// sketch in three ways, either with:
|
||||
//
|
||||
// 1. Font file name with the & in front such as &FreeSansBoldOblique24pt7b
|
||||
// an example being:
|
||||
//
|
||||
// tft.setFreeFont(&FreeSansBoldOblique24pt7b);
|
||||
//
|
||||
// 2. FF# where # is a number determined by looking at the list below
|
||||
// an example being:
|
||||
//
|
||||
// tft.setFreeFont(FF32);
|
||||
//
|
||||
// 3. An abbreviation of the file name. Look at the list below to see
|
||||
// the abbreviations used, for example:
|
||||
//
|
||||
// tft.setFreeFont(FSSBO24)
|
||||
//
|
||||
// Where the letters mean:
|
||||
// F = Free font
|
||||
// M = Mono
|
||||
// SS = Sans Serif (double S to distinguish is form serif fonts)
|
||||
// S = Serif
|
||||
// B = Bold
|
||||
// O = Oblique (letter O not zero)
|
||||
// I = Italic
|
||||
// # = point size, either 9, 12, 18 or 24
|
||||
//
|
||||
// Setting the font to NULL will select the GLCD font:
|
||||
//
|
||||
// tft.setFreeFont(NULL); // Set font to GLCD
|
||||
|
||||
#define LOAD_GFXFF
|
||||
|
||||
#ifdef LOAD_GFXFF // Only include the fonts if LOAD_GFXFF is defined in User_Setup.h
|
||||
|
||||
// Use these when printing or drawing text in GLCD and high rendering speed fonts
|
||||
#define GFXFF 1
|
||||
#define GLCD 0
|
||||
#define FONT2 2
|
||||
#define FONT4 4
|
||||
#define FONT6 6
|
||||
#define FONT7 7
|
||||
#define FONT8 8
|
||||
|
||||
// Use the following when calling setFont()
|
||||
//
|
||||
// Reserved for GLCD font // FF0
|
||||
//
|
||||
|
||||
#define TT1 &TomThumb
|
||||
|
||||
#define FM9 &FreeMono9pt7b
|
||||
#define FM12 &FreeMono12pt7b
|
||||
#define FM18 &FreeMono18pt7b
|
||||
#define FM24 &FreeMono24pt7b
|
||||
|
||||
#define FMB9 &FreeMonoBold9pt7b
|
||||
#define FMB12 &FreeMonoBold12pt7b
|
||||
#define FMB18 &FreeMonoBold18pt7b
|
||||
#define FMB24 &FreeMonoBold24pt7b
|
||||
|
||||
#define FMO9 &FreeMonoOblique9pt7b
|
||||
#define FMO12 &FreeMonoOblique12pt7b
|
||||
#define FMO18 &FreeMonoOblique18pt7b
|
||||
#define FMO24 &FreeMonoOblique24pt7b
|
||||
|
||||
#define FMBO9 &FreeMonoBoldOblique9pt7b
|
||||
#define FMBO12 &FreeMonoBoldOblique12pt7b
|
||||
#define FMBO18 &FreeMonoBoldOblique18pt7b
|
||||
#define FMBO24 &FreeMonoBoldOblique24pt7b
|
||||
|
||||
#define FSS9 &FreeSans9pt7b
|
||||
#define FSS12 &FreeSans12pt7b
|
||||
#define FSS18 &FreeSans18pt7b
|
||||
#define FSS24 &FreeSans24pt7b
|
||||
|
||||
#define FSSB9 &FreeSansBold9pt7b
|
||||
#define FSSB12 &FreeSansBold12pt7b
|
||||
#define FSSB18 &FreeSansBold18pt7b
|
||||
#define FSSB24 &FreeSansBold24pt7b
|
||||
|
||||
#define FSSO9 &FreeSansOblique9pt7b
|
||||
#define FSSO12 &FreeSansOblique12pt7b
|
||||
#define FSSO18 &FreeSansOblique18pt7b
|
||||
#define FSSO24 &FreeSansOblique24pt7b
|
||||
|
||||
#define FSSBO9 &FreeSansBoldOblique9pt7b
|
||||
#define FSSBO12 &FreeSansBoldOblique12pt7b
|
||||
#define FSSBO18 &FreeSansBoldOblique18pt7b
|
||||
#define FSSBO24 &FreeSansBoldOblique24pt7b
|
||||
|
||||
#define FS9 &FreeSerif9pt7b
|
||||
#define FS12 &FreeSerif12pt7b
|
||||
#define FS18 &FreeSerif18pt7b
|
||||
#define FS24 &FreeSerif24pt7b
|
||||
|
||||
#define FSI9 &FreeSerifItalic9pt7b
|
||||
#define FSI12 &FreeSerifItalic12pt7b
|
||||
#define FSI19 &FreeSerifItalic18pt7b
|
||||
#define FSI24 &FreeSerifItalic24pt7b
|
||||
|
||||
#define FSB9 &FreeSerifBold9pt7b
|
||||
#define FSB12 &FreeSerifBold12pt7b
|
||||
#define FSB18 &FreeSerifBold18pt7b
|
||||
#define FSB24 &FreeSerifBold24pt7b
|
||||
|
||||
#define FSBI9 &FreeSerifBoldItalic9pt7b
|
||||
#define FSBI12 &FreeSerifBoldItalic12pt7b
|
||||
#define FSBI18 &FreeSerifBoldItalic18pt7b
|
||||
#define FSBI24 &FreeSerifBoldItalic24pt7b
|
||||
|
||||
#define FF0 NULL //ff0 reserved for GLCD
|
||||
#define FF1 &FreeMono9pt7b
|
||||
#define FF2 &FreeMono12pt7b
|
||||
#define FF3 &FreeMono18pt7b
|
||||
#define FF4 &FreeMono24pt7b
|
||||
|
||||
#define FF5 &FreeMonoBold9pt7b
|
||||
#define FF6 &FreeMonoBold12pt7b
|
||||
#define FF7 &FreeMonoBold18pt7b
|
||||
#define FF8 &FreeMonoBold24pt7b
|
||||
|
||||
#define FF9 &FreeMonoOblique9pt7b
|
||||
#define FF10 &FreeMonoOblique12pt7b
|
||||
#define FF11 &FreeMonoOblique18pt7b
|
||||
#define FF12 &FreeMonoOblique24pt7b
|
||||
|
||||
#define FF13 &FreeMonoBoldOblique9pt7b
|
||||
#define FF14 &FreeMonoBoldOblique12pt7b
|
||||
#define FF15 &FreeMonoBoldOblique18pt7b
|
||||
#define FF16 &FreeMonoBoldOblique24pt7b
|
||||
|
||||
#define FF17 &FreeSans9pt7b
|
||||
#define FF18 &FreeSans12pt7b
|
||||
#define FF19 &FreeSans18pt7b
|
||||
#define FF20 &FreeSans24pt7b
|
||||
|
||||
#define FF21 &FreeSansBold9pt7b
|
||||
#define FF22 &FreeSansBold12pt7b
|
||||
#define FF23 &FreeSansBold18pt7b
|
||||
#define FF24 &FreeSansBold24pt7b
|
||||
|
||||
#define FF25 &FreeSansOblique9pt7b
|
||||
#define FF26 &FreeSansOblique12pt7b
|
||||
#define FF27 &FreeSansOblique18pt7b
|
||||
#define FF28 &FreeSansOblique24pt7b
|
||||
|
||||
#define FF29 &FreeSansBoldOblique9pt7b
|
||||
#define FF30 &FreeSansBoldOblique12pt7b
|
||||
#define FF31 &FreeSansBoldOblique18pt7b
|
||||
#define FF32 &FreeSansBoldOblique24pt7b
|
||||
|
||||
#define FF33 &FreeSerif9pt7b
|
||||
#define FF34 &FreeSerif12pt7b
|
||||
#define FF35 &FreeSerif18pt7b
|
||||
#define FF36 &FreeSerif24pt7b
|
||||
|
||||
#define FF37 &FreeSerifItalic9pt7b
|
||||
#define FF38 &FreeSerifItalic12pt7b
|
||||
#define FF39 &FreeSerifItalic18pt7b
|
||||
#define FF40 &FreeSerifItalic24pt7b
|
||||
|
||||
#define FF41 &FreeSerifBold9pt7b
|
||||
#define FF42 &FreeSerifBold12pt7b
|
||||
#define FF43 &FreeSerifBold18pt7b
|
||||
#define FF44 &FreeSerifBold24pt7b
|
||||
|
||||
#define FF45 &FreeSerifBoldItalic9pt7b
|
||||
#define FF46 &FreeSerifBoldItalic12pt7b
|
||||
#define FF47 &FreeSerifBoldItalic18pt7b
|
||||
#define FF48 &FreeSerifBoldItalic24pt7b
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Now we define "s"tring versions for easy printing of the font name so:
|
||||
// tft.println(sFF5);
|
||||
// will print
|
||||
// Mono bold 9
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
#define sFF0 "GLCD"
|
||||
#define sTT1 "Tom Thumb"
|
||||
#define sFF1 "Mono 9"
|
||||
#define sFF2 "Mono 12"
|
||||
#define sFF3 "Mono 18"
|
||||
#define sFF4 "Mono 24"
|
||||
|
||||
#define sFF5 "Mono bold 9"
|
||||
#define sFF6 "Mono bold 12"
|
||||
#define sFF7 "Mono bold 18"
|
||||
#define sFF8 "Mono bold 24"
|
||||
|
||||
#define sFF9 "Mono oblique 9"
|
||||
#define sFF10 "Mono oblique 12"
|
||||
#define sFF11 "Mono oblique 18"
|
||||
#define sFF12 "Mono oblique 24"
|
||||
|
||||
#define sFF13 "Mono bold oblique 9"
|
||||
#define sFF14 "Mono bold oblique 12"
|
||||
#define sFF15 "Mono bold oblique 18"
|
||||
#define sFF16 "Mono bold oblique 24" // Full text line is too big for 480 pixel wide screen
|
||||
|
||||
#define sFF17 "Sans 9"
|
||||
#define sFF18 "Sans 12"
|
||||
#define sFF19 "Sans 18"
|
||||
#define sFF20 "Sans 24"
|
||||
|
||||
#define sFF21 "Sans bold 9"
|
||||
#define sFF22 "Sans bold 12"
|
||||
#define sFF23 "Sans bold 18"
|
||||
#define sFF24 "Sans bold 24"
|
||||
|
||||
#define sFF25 "Sans oblique 9"
|
||||
#define sFF26 "Sans oblique 12"
|
||||
#define sFF27 "Sans oblique 18"
|
||||
#define sFF28 "Sans oblique 24"
|
||||
|
||||
#define sFF29 "Sans bold oblique 9"
|
||||
#define sFF30 "Sans bold oblique 12"
|
||||
#define sFF31 "Sans bold oblique 18"
|
||||
#define sFF32 "Sans bold oblique 24"
|
||||
|
||||
#define sFF33 "Serif 9"
|
||||
#define sFF34 "Serif 12"
|
||||
#define sFF35 "Serif 18"
|
||||
#define sFF36 "Serif 24"
|
||||
|
||||
#define sFF37 "Serif italic 9"
|
||||
#define sFF38 "Serif italic 12"
|
||||
#define sFF39 "Serif italic 18"
|
||||
#define sFF40 "Serif italic 24"
|
||||
|
||||
#define sFF41 "Serif bold 9"
|
||||
#define sFF42 "Serif bold 12"
|
||||
#define sFF43 "Serif bold 18"
|
||||
#define sFF44 "Serif bold 24"
|
||||
|
||||
#define sFF45 "Serif bold italic 9"
|
||||
#define sFF46 "Serif bold italic 12"
|
||||
#define sFF47 "Serif bold italic 18"
|
||||
#define sFF48 "Serif bold italic 24"
|
||||
|
||||
#else // LOAD_GFXFF not defined so setup defaults to prevent error messages
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Free fonts are not loaded in User_Setup.h so we must define all as font 1
|
||||
// to prevent compile error messages
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
#define GFXFF 1
|
||||
#define GLCD 1
|
||||
#define FONT2 2
|
||||
#define FONT4 4
|
||||
#define FONT6 6
|
||||
#define FONT7 7
|
||||
#define FONT8 8
|
||||
|
||||
#define FF0 1
|
||||
#define FF1 1
|
||||
#define FF2 1
|
||||
#define FF3 1
|
||||
#define FF4 1
|
||||
#define FF5 1
|
||||
#define FF6 1
|
||||
#define FF7 1
|
||||
#define FF8 1
|
||||
#define FF9 1
|
||||
#define FF10 1
|
||||
#define FF11 1
|
||||
#define FF12 1
|
||||
#define FF13 1
|
||||
#define FF14 1
|
||||
#define FF15 1
|
||||
#define FF16 1
|
||||
#define FF17 1
|
||||
#define FF18 1
|
||||
#define FF19 1
|
||||
#define FF20 1
|
||||
#define FF21 1
|
||||
#define FF22 1
|
||||
#define FF23 1
|
||||
#define FF24 1
|
||||
#define FF25 1
|
||||
#define FF26 1
|
||||
#define FF27 1
|
||||
#define FF28 1
|
||||
#define FF29 1
|
||||
#define FF30 1
|
||||
#define FF31 1
|
||||
#define FF32 1
|
||||
#define FF33 1
|
||||
#define FF34 1
|
||||
#define FF35 1
|
||||
#define FF36 1
|
||||
#define FF37 1
|
||||
#define FF38 1
|
||||
#define FF39 1
|
||||
#define FF40 1
|
||||
#define FF41 1
|
||||
#define FF42 1
|
||||
#define FF43 1
|
||||
#define FF44 1
|
||||
#define FF45 1
|
||||
#define FF46 1
|
||||
#define FF47 1
|
||||
#define FF48 1
|
||||
|
||||
#define FM9 1
|
||||
#define FM12 1
|
||||
#define FM18 1
|
||||
#define FM24 1
|
||||
|
||||
#define FMB9 1
|
||||
#define FMB12 1
|
||||
#define FMB18 1
|
||||
#define FMB24 1
|
||||
|
||||
#define FMO9 1
|
||||
#define FMO12 1
|
||||
#define FMO18 1
|
||||
#define FMO24 1
|
||||
|
||||
#define FMBO9 1
|
||||
#define FMBO12 1
|
||||
#define FMBO18 1
|
||||
#define FMBO24 1
|
||||
|
||||
#define FSS9 1
|
||||
#define FSS12 1
|
||||
#define FSS18 1
|
||||
#define FSS24 1
|
||||
|
||||
#define FSSB9 1
|
||||
#define FSSB12 1
|
||||
#define FSSB18 1
|
||||
#define FSSB24 1
|
||||
|
||||
#define FSSO9 1
|
||||
#define FSSO12 1
|
||||
#define FSSO18 1
|
||||
#define FSSO24 1
|
||||
|
||||
#define FSSBO9 1
|
||||
#define FSSBO12 1
|
||||
#define FSSBO18 1
|
||||
#define FSSBO24 1
|
||||
|
||||
#define FS9 1
|
||||
#define FS12 1
|
||||
#define FS18 1
|
||||
#define FS24 1
|
||||
|
||||
#define FSI9 1
|
||||
#define FSI12 1
|
||||
#define FSI19 1
|
||||
#define FSI24 1
|
||||
|
||||
#define FSB9 1
|
||||
#define FSB12 1
|
||||
#define FSB18 1
|
||||
#define FSB24 1
|
||||
|
||||
#define FSBI9 1
|
||||
#define FSBI12 1
|
||||
#define FSBI18 1
|
||||
#define FSBI24 1
|
||||
|
||||
#endif // LOAD_GFXFF
|
||||
@@ -0,0 +1,165 @@
|
||||
//The Game of Life, also known simply as Life, is a cellular automaton
|
||||
//devised by the British mathematician John Horton Conway in 1970.
|
||||
// https://en.wikipedia.org/wiki/Conway's_Game_of_Life
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
//#define GRIDX 80
|
||||
//#define GRIDY 60
|
||||
//#define CELLXY 4
|
||||
|
||||
#define GRIDX 160
|
||||
#define GRIDY 120
|
||||
#define CELLXY 2
|
||||
|
||||
#define GEN_DELAY 0
|
||||
|
||||
//Current grid
|
||||
uint8_t grid[GRIDX][GRIDY];
|
||||
|
||||
//The new grid for the next generation
|
||||
uint8_t newgrid[GRIDX][GRIDY];
|
||||
|
||||
//Number of generations
|
||||
#define NUMGEN 600
|
||||
|
||||
uint16_t genCount = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
//Set up the display
|
||||
tft.init();
|
||||
tft.setRotation(3);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(TFT_WHITE);
|
||||
tft.setCursor(0, 0);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
//Display a simple splash screen
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextSize(2);
|
||||
tft.setTextColor(TFT_WHITE);
|
||||
tft.setCursor(40, 5);
|
||||
tft.println(F("Arduino"));
|
||||
tft.setCursor(35, 25);
|
||||
tft.println(F("Cellular"));
|
||||
tft.setCursor(35, 45);
|
||||
tft.println(F("Automata"));
|
||||
|
||||
delay(1000);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
initGrid();
|
||||
|
||||
genCount = NUMGEN;
|
||||
|
||||
drawGrid();
|
||||
|
||||
//Compute generations
|
||||
for (int gen = 0; gen < genCount; gen++)
|
||||
{
|
||||
computeCA();
|
||||
drawGrid();
|
||||
delay(GEN_DELAY);
|
||||
for (int16_t x = 1; x < GRIDX-1; x++) {
|
||||
for (int16_t y = 1; y < GRIDY-1; y++) {
|
||||
grid[x][y] = newgrid[x][y];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Draws the grid on the display
|
||||
void drawGrid(void) {
|
||||
|
||||
uint16_t color = TFT_WHITE;
|
||||
for (int16_t x = 1; x < GRIDX - 1; x++) {
|
||||
for (int16_t y = 1; y < GRIDY - 1; y++) {
|
||||
if ((grid[x][y]) != (newgrid[x][y])) {
|
||||
if (newgrid[x][y] == 1) color = 0xFFFF; //random(0xFFFF);
|
||||
else color = 0;
|
||||
tft.fillRect(CELLXY * x, CELLXY * y, CELLXY, CELLXY, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Initialise Grid
|
||||
void initGrid(void) {
|
||||
for (int16_t x = 0; x < GRIDX; x++) {
|
||||
for (int16_t y = 0; y < GRIDY; y++) {
|
||||
newgrid[x][y] = 0;
|
||||
|
||||
if (x == 0 || x == GRIDX - 1 || y == 0 || y == GRIDY - 1) {
|
||||
grid[x][y] = 0;
|
||||
}
|
||||
else {
|
||||
if (random(3) == 1)
|
||||
grid[x][y] = 1;
|
||||
else
|
||||
grid[x][y] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Compute the CA. Basically everything related to CA starts here
|
||||
void computeCA() {
|
||||
for (int16_t x = 1; x < GRIDX; x++) {
|
||||
for (int16_t y = 1; y < GRIDY; y++) {
|
||||
int neighbors = getNumberOfNeighbors(x, y);
|
||||
if (grid[x][y] == 1 && (neighbors == 2 || neighbors == 3 ))
|
||||
{
|
||||
newgrid[x][y] = 1;
|
||||
}
|
||||
else if (grid[x][y] == 1) newgrid[x][y] = 0;
|
||||
if (grid[x][y] == 0 && (neighbors == 3))
|
||||
{
|
||||
newgrid[x][y] = 1;
|
||||
}
|
||||
else if (grid[x][y] == 0) newgrid[x][y] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check the Moore neighbourhood
|
||||
int getNumberOfNeighbors(int x, int y) {
|
||||
return grid[x - 1][y] + grid[x - 1][y - 1] + grid[x][y - 1] + grid[x + 1][y - 1] + grid[x + 1][y] + grid[x + 1][y + 1] + grid[x][y + 1] + grid[x - 1][y + 1];
|
||||
}
|
||||
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 RuntimeProjects.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
This example draws fonts (as used by the Adafruit_GFX library) onto the
|
||||
screen. These fonts are called the GFX Free Fonts (GFXFF) in this library.
|
||||
|
||||
Other True Type fonts could be converted using the utility within the
|
||||
"fontconvert" folder inside the library. This converted has also been
|
||||
copied from the Adafruit_GFX library.
|
||||
|
||||
Since these fonts are a recent addition Adafruit do not have a tutorial
|
||||
available yet on how to use the utility. Linux users will no doubt
|
||||
figure it out! In the meantime there are 48 font files to use in sizes
|
||||
from 9 point to 24 point, and in normal, bold, and italic or oblique
|
||||
styles.
|
||||
|
||||
This example sketch uses both the print class and drawString() functions
|
||||
to plot text to the screen.
|
||||
|
||||
Make sure LOAD_GFXFF is defined in the User_Setup.h file within the
|
||||
TFT_eSPI library folder.
|
||||
|
||||
--------------------------- NOTE ----------------------------------------
|
||||
The free font encoding format does not lend itself easily to plotting
|
||||
the background without flicker. For values that changes on screen it is
|
||||
better to use Fonts 1- 8 which are encoded specifically for rapid
|
||||
drawing with background.
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
>>>>>>>>>>>>>>>>>>>>>>>>>>> WARNING <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
As supplied with the default settings the sketch has 11 fonts loaded,
|
||||
i.e. GLCD (Font 1), Font 2, Font 4, Font 6, Font 7, Font 8 and five Free Fonts,
|
||||
even though they are not all used in the sketch.
|
||||
|
||||
Disable fonts you do not need in User_Setup.h in the library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
#include "SPI.h"
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
#include "Free_Fonts.h" // Include the header file attached to this sketch
|
||||
|
||||
// Use hardware SPI
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
|
||||
unsigned long drawTime = 0;
|
||||
|
||||
void setup(void) {
|
||||
|
||||
tft.begin();
|
||||
|
||||
tft.setRotation(1);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
int xpos = 0;
|
||||
int ypos = 40;
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Select different fonts to draw on screen using the print class
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
header("Using print() method", TFT_NAVY);
|
||||
|
||||
// For comaptibility with Adafruit_GFX library the text background is not plotted when using the print class
|
||||
// even if we specify it.
|
||||
tft.setTextColor(TFT_YELLOW);
|
||||
tft.setCursor(xpos, ypos); // Set cursor near top left corner of screen
|
||||
|
||||
tft.setFreeFont(TT1); // Select the orginal small TomThumb font
|
||||
tft.println(); // Move cursor down a line
|
||||
tft.print("The really tiny TomThumb font"); // Print the font name onto the TFT screen
|
||||
tft.println();
|
||||
tft.println();
|
||||
|
||||
tft.setFreeFont(FSB9); // Select Free Serif 9 point font, could use:
|
||||
// tft.setFreeFont(&FreeSerif9pt7b);
|
||||
tft.println(); // Free fonts plot with the baseline (imaginary line the letter A would sit on)
|
||||
// as the datum, so we must move the cursor down a line from the 0,0 position
|
||||
tft.print("Serif Bold 9pt"); // Print the font name onto the TFT screen
|
||||
|
||||
tft.setFreeFont(FSB12); // Select Free Serif 12 point font
|
||||
tft.println(); // Move cursor down a line
|
||||
tft.print("Serif Bold 12pt"); // Print the font name onto the TFT screen
|
||||
|
||||
tft.setFreeFont(FSB18); // Select Free Serif 12 point font
|
||||
tft.println(); // Move cursor down a line
|
||||
tft.print("Serif Bold 18pt"); // Print the font name onto the TFT screen
|
||||
|
||||
tft.setFreeFont(FSB24); // Select Free Serif 24 point font
|
||||
tft.println(); // Move cursor down a line
|
||||
tft.print("Serif Bold 24pt"); // Print the font name onto the TFT screen
|
||||
|
||||
|
||||
delay(4000);
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Now use drawString() so we can set font background colours and the datum
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
header("Using drawString()", TFT_BLACK);
|
||||
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
tft.setTextDatum(TC_DATUM); // Centre text on x,y position
|
||||
|
||||
xpos = tft.width() / 2; // Half the screen width
|
||||
ypos = 50;
|
||||
|
||||
tft.setFreeFont(FSB9); // Select the font
|
||||
tft.drawString("Serif Bold 9pt", xpos, ypos, GFXFF); // Draw the text string in the selected GFX free font
|
||||
ypos += tft.fontHeight(GFXFF); // Get the font height and move ypos down
|
||||
|
||||
tft.setFreeFont(FSB12);
|
||||
tft.drawString("Serif Bold 12pt", xpos, ypos, GFXFF);
|
||||
ypos += tft.fontHeight(GFXFF);
|
||||
|
||||
tft.setFreeFont(FSB18);
|
||||
tft.drawString("Serif Bold 18pt", xpos, ypos, GFXFF);
|
||||
ypos += tft.fontHeight(GFXFF);
|
||||
|
||||
tft.setFreeFont(FSB24);
|
||||
tft.drawString("Serif Bold 24pt", xpos, ypos, GFXFF);
|
||||
ypos += tft.fontHeight(GFXFF);
|
||||
|
||||
// Set text padding to 100 pixels wide area to over-write old values on screen
|
||||
tft.setTextPadding(100);
|
||||
for (int i = 0; i <= 20; i++) {
|
||||
tft.drawFloat(i / 10.0, 1, xpos, ypos, GFXFF);
|
||||
delay (200);
|
||||
}
|
||||
|
||||
delay(4000);
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Same again but with colours that show bounding boxes
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
|
||||
header("With background", TFT_DARKGREY);
|
||||
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
|
||||
tft.setTextDatum(TC_DATUM); // Centre text on x,y position
|
||||
|
||||
xpos = tft.width() / 2; // Half the screen width
|
||||
ypos = 50;
|
||||
|
||||
tft.setFreeFont(FSB9); // Select the font
|
||||
tft.drawString("Serif Bold 9pt", xpos, ypos, GFXFF); // Draw the text string in the selected GFX free font
|
||||
ypos += tft.fontHeight(GFXFF); // Get the font height and move ypos down
|
||||
|
||||
tft.setFreeFont(FSB12);
|
||||
tft.drawString("Serif Bold 12pt", xpos, ypos, GFXFF);
|
||||
ypos += tft.fontHeight(GFXFF);
|
||||
|
||||
tft.setFreeFont(FSB18);
|
||||
tft.drawString("Serif Bold 18pt", xpos, ypos, GFXFF);
|
||||
ypos += tft.fontHeight(GFXFF);
|
||||
|
||||
tft.setFreeFont(FSBI24);
|
||||
tft.drawString("Bold Italic 24pt", xpos, ypos, GFXFF);
|
||||
ypos += tft.fontHeight(GFXFF);
|
||||
|
||||
// Set text padding to 100 pixels wide area to over-write old values on screen
|
||||
tft.setTextPadding(100);
|
||||
for (int i = 0; i <= 20; i++) {
|
||||
tft.drawFloat(i / 10.0, 1, xpos, ypos, GFXFF);
|
||||
delay (200);
|
||||
}
|
||||
|
||||
delay(4000);
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Now show setting the 12 datum positions works with free fonts
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
// Numbers, floats and strings can be drawn relative to a datum
|
||||
header("Text with a datum", TFT_BLACK);
|
||||
tft.setTextColor(TFT_DARKGREY, TFT_BLACK);
|
||||
tft.setFreeFont(FSS12);
|
||||
tft.setTextDatum(TL_DATUM);
|
||||
tft.drawString("[Top left]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(TC_DATUM);
|
||||
tft.drawString("[Top centre]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(TR_DATUM);
|
||||
tft.drawString("[Top right]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(ML_DATUM);
|
||||
tft.drawString("[Middle left]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
tft.drawString("[Middle centre]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(MR_DATUM);
|
||||
tft.drawString("[Middle right]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(BL_DATUM);
|
||||
tft.drawString("[Bottom left]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(BC_DATUM);
|
||||
tft.drawString("[Bottom centre]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(BR_DATUM);
|
||||
tft.drawString("[Bottom right]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(L_BASELINE);
|
||||
tft.drawString("[Left baseline]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(C_BASELINE);
|
||||
tft.drawString("[Centre baseline]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
tft.fillRect(0, 80, 320, 80, TFT_BLACK);
|
||||
tft.setTextDatum(R_BASELINE);
|
||||
tft.drawString("[Right baseline]", 160, 120, GFXFF);
|
||||
drawDatumMarker(160,120);
|
||||
delay(1000);
|
||||
|
||||
//while(1);
|
||||
delay(8000);
|
||||
|
||||
}
|
||||
|
||||
// Print the header for a display screen
|
||||
void header(const char *string, uint16_t color)
|
||||
{
|
||||
tft.fillScreen(color);
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(TFT_MAGENTA, TFT_BLUE);
|
||||
tft.fillRect(0, 0, 320, 30, TFT_BLUE);
|
||||
tft.setTextDatum(TC_DATUM);
|
||||
tft.drawString(string, 160, 2, 4); // Font 4 for fast drawing with background
|
||||
}
|
||||
|
||||
// Draw a + mark centred on x,y
|
||||
void drawDatumMarker(int x, int y)
|
||||
{
|
||||
tft.drawLine(x - 5, y, x + 5, y, TFT_GREEN);
|
||||
tft.drawLine(x, y - 5, x, y + 5, TFT_GREEN);
|
||||
}
|
||||
|
||||
|
||||
// There follows a crude way of flagging that this example sketch needs fonts which
|
||||
// have not been enbabled in the User_Setup.h file inside the TFT_HX8357 library.
|
||||
//
|
||||
// These lines produce errors during compile time if settings in User_Setup are not correct
|
||||
//
|
||||
// The error will be "does not name a type" but ignore this and read the text between ''
|
||||
// it will indicate which font or feature needs to be enabled
|
||||
//
|
||||
// Either delete all the following lines if you do not want warnings, or change the lines
|
||||
// to suit your sketch modifications.
|
||||
|
||||
#ifndef LOAD_GLCD
|
||||
//ERROR_Please_enable_LOAD_GLCD_in_User_Setup
|
||||
#endif
|
||||
|
||||
#ifndef LOAD_FONT2
|
||||
//ERROR_Please_enable_LOAD_FONT2_in_User_Setup!
|
||||
#endif
|
||||
|
||||
#ifndef LOAD_FONT4
|
||||
//ERROR_Please_enable_LOAD_FONT4_in_User_Setup!
|
||||
#endif
|
||||
|
||||
#ifndef LOAD_FONT6
|
||||
//ERROR_Please_enable_LOAD_FONT6_in_User_Setup!
|
||||
#endif
|
||||
|
||||
#ifndef LOAD_FONT7
|
||||
//ERROR_Please_enable_LOAD_FONT7_in_User_Setup!
|
||||
#endif
|
||||
|
||||
#ifndef LOAD_FONT8
|
||||
//ERROR_Please_enable_LOAD_FONT8_in_User_Setup!
|
||||
#endif
|
||||
|
||||
#ifndef LOAD_GFXFF
|
||||
ERROR_Please_enable_LOAD_GFXFF_in_User_Setup!
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,377 @@
|
||||
// Attach this header file to your sketch to use the GFX Free Fonts. You can write
|
||||
// sketches without it, but it makes referencing them easier.
|
||||
|
||||
// This calls up ALL the fonts but they only get loaded if you actually
|
||||
// use them in your sketch.
|
||||
//
|
||||
// No changes are needed to this header file unless new fonts are added to the
|
||||
// library "Fonts/GFXFF" folder.
|
||||
//
|
||||
// To save a lot of typing long names, each font can easily be referenced in the
|
||||
// sketch in three ways, either with:
|
||||
//
|
||||
// 1. Font file name with the & in front such as &FreeSansBoldOblique24pt7b
|
||||
// an example being:
|
||||
//
|
||||
// tft.setFreeFont(&FreeSansBoldOblique24pt7b);
|
||||
//
|
||||
// 2. FF# where # is a number determined by looking at the list below
|
||||
// an example being:
|
||||
//
|
||||
// tft.setFreeFont(FF32);
|
||||
//
|
||||
// 3. An abbreviation of the file name. Look at the list below to see
|
||||
// the abbreviations used, for example:
|
||||
//
|
||||
// tft.setFreeFont(FSSBO24)
|
||||
//
|
||||
// Where the letters mean:
|
||||
// F = Free font
|
||||
// M = Mono
|
||||
// SS = Sans Serif (double S to distinguish is form serif fonts)
|
||||
// S = Serif
|
||||
// B = Bold
|
||||
// O = Oblique (letter O not zero)
|
||||
// I = Italic
|
||||
// # = point size, either 9, 12, 18 or 24
|
||||
//
|
||||
// Setting the font to NULL will select the GLCD font:
|
||||
//
|
||||
// tft.setFreeFont(NULL); // Set font to GLCD
|
||||
|
||||
#ifdef LOAD_GFXFF // Only include the fonts if LOAD_GFXFF is defined in User_Setup.h
|
||||
|
||||
// Use these when printing or drawing text in GLCD and high rendering speed fonts
|
||||
#define GFXFF 1
|
||||
#define GLCD 0
|
||||
#define FONT2 2
|
||||
#define FONT4 4
|
||||
#define FONT6 6
|
||||
#define FONT7 7
|
||||
#define FONT8 8
|
||||
|
||||
// Use the following when calling setFont()
|
||||
//
|
||||
// Reserved for GLCD font // FF0
|
||||
//
|
||||
|
||||
#define TT1 &TomThumb
|
||||
|
||||
#define FM9 &FreeMono9pt7b
|
||||
#define FM12 &FreeMono12pt7b
|
||||
#define FM18 &FreeMono18pt7b
|
||||
#define FM24 &FreeMono24pt7b
|
||||
|
||||
#define FMB9 &FreeMonoBold9pt7b
|
||||
#define FMB12 &FreeMonoBold12pt7b
|
||||
#define FMB18 &FreeMonoBold18pt7b
|
||||
#define FMB24 &FreeMonoBold24pt7b
|
||||
|
||||
#define FMO9 &FreeMonoOblique9pt7b
|
||||
#define FMO12 &FreeMonoOblique12pt7b
|
||||
#define FMO18 &FreeMonoOblique18pt7b
|
||||
#define FMO24 &FreeMonoOblique24pt7b
|
||||
|
||||
#define FMBO9 &FreeMonoBoldOblique9pt7b
|
||||
#define FMBO12 &FreeMonoBoldOblique12pt7b
|
||||
#define FMBO18 &FreeMonoBoldOblique18pt7b
|
||||
#define FMBO24 &FreeMonoBoldOblique24pt7b
|
||||
|
||||
#define FSS9 &FreeSans9pt7b
|
||||
#define FSS12 &FreeSans12pt7b
|
||||
#define FSS18 &FreeSans18pt7b
|
||||
#define FSS24 &FreeSans24pt7b
|
||||
|
||||
#define FSSB9 &FreeSansBold9pt7b
|
||||
#define FSSB12 &FreeSansBold12pt7b
|
||||
#define FSSB18 &FreeSansBold18pt7b
|
||||
#define FSSB24 &FreeSansBold24pt7b
|
||||
|
||||
#define FSSO9 &FreeSansOblique9pt7b
|
||||
#define FSSO12 &FreeSansOblique12pt7b
|
||||
#define FSSO18 &FreeSansOblique18pt7b
|
||||
#define FSSO24 &FreeSansOblique24pt7b
|
||||
|
||||
#define FSSBO9 &FreeSansBoldOblique9pt7b
|
||||
#define FSSBO12 &FreeSansBoldOblique12pt7b
|
||||
#define FSSBO18 &FreeSansBoldOblique18pt7b
|
||||
#define FSSBO24 &FreeSansBoldOblique24pt7b
|
||||
|
||||
#define FS9 &FreeSerif9pt7b
|
||||
#define FS12 &FreeSerif12pt7b
|
||||
#define FS18 &FreeSerif18pt7b
|
||||
#define FS24 &FreeSerif24pt7b
|
||||
|
||||
#define FSI9 &FreeSerifItalic9pt7b
|
||||
#define FSI12 &FreeSerifItalic12pt7b
|
||||
#define FSI19 &FreeSerifItalic18pt7b
|
||||
#define FSI24 &FreeSerifItalic24pt7b
|
||||
|
||||
#define FSB9 &FreeSerifBold9pt7b
|
||||
#define FSB12 &FreeSerifBold12pt7b
|
||||
#define FSB18 &FreeSerifBold18pt7b
|
||||
#define FSB24 &FreeSerifBold24pt7b
|
||||
|
||||
#define FSBI9 &FreeSerifBoldItalic9pt7b
|
||||
#define FSBI12 &FreeSerifBoldItalic12pt7b
|
||||
#define FSBI18 &FreeSerifBoldItalic18pt7b
|
||||
#define FSBI24 &FreeSerifBoldItalic24pt7b
|
||||
|
||||
#define FF0 NULL //ff0 reserved for GLCD
|
||||
#define FF1 &FreeMono9pt7b
|
||||
#define FF2 &FreeMono12pt7b
|
||||
#define FF3 &FreeMono18pt7b
|
||||
#define FF4 &FreeMono24pt7b
|
||||
|
||||
#define FF5 &FreeMonoBold9pt7b
|
||||
#define FF6 &FreeMonoBold12pt7b
|
||||
#define FF7 &FreeMonoBold18pt7b
|
||||
#define FF8 &FreeMonoBold24pt7b
|
||||
|
||||
#define FF9 &FreeMonoOblique9pt7b
|
||||
#define FF10 &FreeMonoOblique12pt7b
|
||||
#define FF11 &FreeMonoOblique18pt7b
|
||||
#define FF12 &FreeMonoOblique24pt7b
|
||||
|
||||
#define FF13 &FreeMonoBoldOblique9pt7b
|
||||
#define FF14 &FreeMonoBoldOblique12pt7b
|
||||
#define FF15 &FreeMonoBoldOblique18pt7b
|
||||
#define FF16 &FreeMonoBoldOblique24pt7b
|
||||
|
||||
#define FF17 &FreeSans9pt7b
|
||||
#define FF18 &FreeSans12pt7b
|
||||
#define FF19 &FreeSans18pt7b
|
||||
#define FF20 &FreeSans24pt7b
|
||||
|
||||
#define FF21 &FreeSansBold9pt7b
|
||||
#define FF22 &FreeSansBold12pt7b
|
||||
#define FF23 &FreeSansBold18pt7b
|
||||
#define FF24 &FreeSansBold24pt7b
|
||||
|
||||
#define FF25 &FreeSansOblique9pt7b
|
||||
#define FF26 &FreeSansOblique12pt7b
|
||||
#define FF27 &FreeSansOblique18pt7b
|
||||
#define FF28 &FreeSansOblique24pt7b
|
||||
|
||||
#define FF29 &FreeSansBoldOblique9pt7b
|
||||
#define FF30 &FreeSansBoldOblique12pt7b
|
||||
#define FF31 &FreeSansBoldOblique18pt7b
|
||||
#define FF32 &FreeSansBoldOblique24pt7b
|
||||
|
||||
#define FF33 &FreeSerif9pt7b
|
||||
#define FF34 &FreeSerif12pt7b
|
||||
#define FF35 &FreeSerif18pt7b
|
||||
#define FF36 &FreeSerif24pt7b
|
||||
|
||||
#define FF37 &FreeSerifItalic9pt7b
|
||||
#define FF38 &FreeSerifItalic12pt7b
|
||||
#define FF39 &FreeSerifItalic18pt7b
|
||||
#define FF40 &FreeSerifItalic24pt7b
|
||||
|
||||
#define FF41 &FreeSerifBold9pt7b
|
||||
#define FF42 &FreeSerifBold12pt7b
|
||||
#define FF43 &FreeSerifBold18pt7b
|
||||
#define FF44 &FreeSerifBold24pt7b
|
||||
|
||||
#define FF45 &FreeSerifBoldItalic9pt7b
|
||||
#define FF46 &FreeSerifBoldItalic12pt7b
|
||||
#define FF47 &FreeSerifBoldItalic18pt7b
|
||||
#define FF48 &FreeSerifBoldItalic24pt7b
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Now we define "s"tring versions for easy printing of the font name so:
|
||||
// tft.println(sFF5);
|
||||
// will print
|
||||
// Mono bold 9
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
#define sFF0 "GLCD"
|
||||
#define sTT1 "Tom Thumb"
|
||||
#define sFF1 "Mono 9"
|
||||
#define sFF2 "Mono 12"
|
||||
#define sFF3 "Mono 18"
|
||||
#define sFF4 "Mono 24"
|
||||
|
||||
#define sFF5 "Mono bold 9"
|
||||
#define sFF6 "Mono bold 12"
|
||||
#define sFF7 "Mono bold 18"
|
||||
#define sFF8 "Mono bold 24"
|
||||
|
||||
#define sFF9 "Mono oblique 9"
|
||||
#define sFF10 "Mono oblique 12"
|
||||
#define sFF11 "Mono oblique 18"
|
||||
#define sFF12 "Mono oblique 24"
|
||||
|
||||
#define sFF13 "Mono bold oblique 9"
|
||||
#define sFF14 "Mono bold oblique 12"
|
||||
#define sFF15 "Mono bold oblique 18"
|
||||
#define sFF16 "Mono bold obl. 24" // Full text line is too big for 480 pixel wide screen
|
||||
|
||||
#define sFF17 "Sans 9"
|
||||
#define sFF18 "Sans 12"
|
||||
#define sFF19 "Sans 18"
|
||||
#define sFF20 "Sans 24"
|
||||
|
||||
#define sFF21 "Sans bold 9"
|
||||
#define sFF22 "Sans bold 12"
|
||||
#define sFF23 "Sans bold 18"
|
||||
#define sFF24 "Sans bold 24"
|
||||
|
||||
#define sFF25 "Sans oblique 9"
|
||||
#define sFF26 "Sans oblique 12"
|
||||
#define sFF27 "Sans oblique 18"
|
||||
#define sFF28 "Sans oblique 24"
|
||||
|
||||
#define sFF29 "Sans bold oblique 9"
|
||||
#define sFF30 "Sans bold oblique 12"
|
||||
#define sFF31 "Sans bold oblique 18"
|
||||
#define sFF32 "Sans bold oblique 24"
|
||||
|
||||
#define sFF33 "Serif 9"
|
||||
#define sFF34 "Serif 12"
|
||||
#define sFF35 "Serif 18"
|
||||
#define sFF36 "Serif 24"
|
||||
|
||||
#define sFF37 "Serif italic 9"
|
||||
#define sFF38 "Serif italic 12"
|
||||
#define sFF39 "Serif italic 18"
|
||||
#define sFF40 "Serif italic 24"
|
||||
|
||||
#define sFF41 "Serif bold 9"
|
||||
#define sFF42 "Serif bold 12"
|
||||
#define sFF43 "Serif bold 18"
|
||||
#define sFF44 "Serif bold 24"
|
||||
|
||||
#define sFF45 "Serif bold italic 9"
|
||||
#define sFF46 "Serif bold italic 12"
|
||||
#define sFF47 "Serif bold italic 18"
|
||||
#define sFF48 "Serif bold italic 24"
|
||||
|
||||
#else // LOAD_GFXFF not defined so setup defaults to prevent error messages
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Free fonts are not loaded in User_Setup.h so we must define all as font 1
|
||||
// to prevent compile error messages
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
#define GFXFF 1
|
||||
#define GLCD 1
|
||||
#define FONT2 2
|
||||
#define FONT4 4
|
||||
#define FONT6 6
|
||||
#define FONT7 7
|
||||
#define FONT8 8
|
||||
|
||||
#define TT1 1
|
||||
|
||||
#define FF0 1
|
||||
#define FF1 1
|
||||
#define FF2 1
|
||||
#define FF3 1
|
||||
#define FF4 1
|
||||
#define FF5 1
|
||||
#define FF6 1
|
||||
#define FF7 1
|
||||
#define FF8 1
|
||||
#define FF9 1
|
||||
#define FF10 1
|
||||
#define FF11 1
|
||||
#define FF12 1
|
||||
#define FF13 1
|
||||
#define FF14 1
|
||||
#define FF15 1
|
||||
#define FF16 1
|
||||
#define FF17 1
|
||||
#define FF18 1
|
||||
#define FF19 1
|
||||
#define FF20 1
|
||||
#define FF21 1
|
||||
#define FF22 1
|
||||
#define FF23 1
|
||||
#define FF24 1
|
||||
#define FF25 1
|
||||
#define FF26 1
|
||||
#define FF27 1
|
||||
#define FF28 1
|
||||
#define FF29 1
|
||||
#define FF30 1
|
||||
#define FF31 1
|
||||
#define FF32 1
|
||||
#define FF33 1
|
||||
#define FF34 1
|
||||
#define FF35 1
|
||||
#define FF36 1
|
||||
#define FF37 1
|
||||
#define FF38 1
|
||||
#define FF39 1
|
||||
#define FF40 1
|
||||
#define FF41 1
|
||||
#define FF42 1
|
||||
#define FF43 1
|
||||
#define FF44 1
|
||||
#define FF45 1
|
||||
#define FF46 1
|
||||
#define FF47 1
|
||||
#define FF48 1
|
||||
|
||||
#define FM9 1
|
||||
#define FM12 1
|
||||
#define FM18 1
|
||||
#define FM24 1
|
||||
|
||||
#define FMB9 1
|
||||
#define FMB12 1
|
||||
#define FMB18 1
|
||||
#define FMB24 1
|
||||
|
||||
#define FMO9 1
|
||||
#define FMO12 1
|
||||
#define FMO18 1
|
||||
#define FMO24 1
|
||||
|
||||
#define FMBO9 1
|
||||
#define FMBO12 1
|
||||
#define FMBO18 1
|
||||
#define FMBO24 1
|
||||
|
||||
#define FSS9 1
|
||||
#define FSS12 1
|
||||
#define FSS18 1
|
||||
#define FSS24 1
|
||||
|
||||
#define FSSB9 1
|
||||
#define FSSB12 1
|
||||
#define FSSB18 1
|
||||
#define FSSB24 1
|
||||
|
||||
#define FSSO9 1
|
||||
#define FSSO12 1
|
||||
#define FSSO18 1
|
||||
#define FSSO24 1
|
||||
|
||||
#define FSSBO9 1
|
||||
#define FSSBO12 1
|
||||
#define FSSBO18 1
|
||||
#define FSSBO24 1
|
||||
|
||||
#define FS9 1
|
||||
#define FS12 1
|
||||
#define FS18 1
|
||||
#define FS24 1
|
||||
|
||||
#define FSI9 1
|
||||
#define FSI12 1
|
||||
#define FSI19 1
|
||||
#define FSI24 1
|
||||
|
||||
#define FSB9 1
|
||||
#define FSB12 1
|
||||
#define FSB18 1
|
||||
#define FSB24 1
|
||||
|
||||
#define FSBI9 1
|
||||
#define FSBI12 1
|
||||
#define FSBI18 1
|
||||
#define FSBI24 1
|
||||
|
||||
#endif // LOAD_GFXFF
|
||||
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
The TFT_eSPI library incorporates an Adafruit_GFX compatible
|
||||
button handling class, this sketch is based on the Arduin-o-phone
|
||||
example.
|
||||
|
||||
This example diplays a keypad where numbers can be entered and
|
||||
send to the Serial Monitor window.
|
||||
|
||||
The sketch has been tested on the ESP8266 (which supports SPIFFS)
|
||||
|
||||
The minimum screen size is 320 x 240 as that is the keypad size.
|
||||
*/
|
||||
|
||||
// The SPIFFS (FLASH filing system) is used to hold touch screen
|
||||
// calibration data
|
||||
|
||||
#include "FS.h"
|
||||
|
||||
#include <SPI.h>
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
// This is the file name used to store the calibration data
|
||||
// You can change this to create new calibration files.
|
||||
// The SPIFFS file name must start with "/".
|
||||
#define CALIBRATION_FILE "/TouchCalData1"
|
||||
|
||||
// Set REPEAT_CAL to true instead of false to run calibration
|
||||
// again, otherwise it will only be done once.
|
||||
// Repeat calibration if you change the screen rotation.
|
||||
#define REPEAT_CAL false
|
||||
|
||||
// Keypad start position, key sizes and spacing
|
||||
#define KEY_X 40 // Centre of key
|
||||
#define KEY_Y 96
|
||||
#define KEY_W 62 // Width and height
|
||||
#define KEY_H 30
|
||||
#define KEY_SPACING_X 18 // X and Y gap
|
||||
#define KEY_SPACING_Y 20
|
||||
#define KEY_TEXTSIZE 1 // Font size multiplier
|
||||
|
||||
// Using two fonts since numbers are nice when bold
|
||||
#define LABEL1_FONT &FreeSansOblique12pt7b // Key label font 1
|
||||
#define LABEL2_FONT &FreeSansBold12pt7b // Key label font 2
|
||||
|
||||
// Numeric display box size and location
|
||||
#define DISP_X 1
|
||||
#define DISP_Y 10
|
||||
#define DISP_W 238
|
||||
#define DISP_H 50
|
||||
#define DISP_TSIZE 3
|
||||
#define DISP_TCOLOR TFT_CYAN
|
||||
|
||||
// Number length, buffer for storing it and character index
|
||||
#define NUM_LEN 12
|
||||
char numberBuffer[NUM_LEN + 1] = "";
|
||||
uint8_t numberIndex = 0;
|
||||
|
||||
// We have a status line for messages
|
||||
#define STATUS_X 120 // Centred on this
|
||||
#define STATUS_Y 65
|
||||
|
||||
// Create 15 keys for the keypad
|
||||
char keyLabel[15][5] = {"New", "Del", "Send", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "0", "#" };
|
||||
uint16_t keyColor[15] = {TFT_RED, TFT_DARKGREY, TFT_DARKGREEN,
|
||||
TFT_BLUE, TFT_BLUE, TFT_BLUE,
|
||||
TFT_BLUE, TFT_BLUE, TFT_BLUE,
|
||||
TFT_BLUE, TFT_BLUE, TFT_BLUE,
|
||||
TFT_BLUE, TFT_BLUE, TFT_BLUE
|
||||
};
|
||||
|
||||
// Invoke the TFT_eSPI button class and create all the button objects
|
||||
TFT_eSPI_Button key[15];
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
void setup() {
|
||||
// Use serial port
|
||||
Serial.begin(9600);
|
||||
|
||||
// Initialise the TFT screen
|
||||
tft.init();
|
||||
|
||||
// Set the rotation before we calibrate
|
||||
tft.setRotation(0);
|
||||
|
||||
// Calibrate the touch screen and retrieve the scaling factors
|
||||
touch_calibrate();
|
||||
|
||||
// Clear the screen
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
// Draw keypad background
|
||||
tft.fillRect(0, 0, 240, 320, TFT_DARKGREY);
|
||||
|
||||
// Draw number display area and frame
|
||||
tft.fillRect(DISP_X, DISP_Y, DISP_W, DISP_H, TFT_BLACK);
|
||||
tft.drawRect(DISP_X, DISP_Y, DISP_W, DISP_H, TFT_WHITE);
|
||||
|
||||
// Draw keypad
|
||||
drawKeypad();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
void loop(void) {
|
||||
uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
|
||||
|
||||
// Pressed will be set true is there is a valid touch on the screen
|
||||
bool pressed = tft.getTouch(&t_x, &t_y);
|
||||
|
||||
// / Check if any key coordinate boxes contain the touch coordinates
|
||||
for (uint8_t b = 0; b < 15; b++) {
|
||||
if (pressed && key[b].contains(t_x, t_y)) {
|
||||
key[b].press(true); // tell the button it is pressed
|
||||
} else {
|
||||
key[b].press(false); // tell the button it is NOT pressed
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any key has changed state
|
||||
for (uint8_t b = 0; b < 15; b++) {
|
||||
|
||||
if (b < 3) tft.setFreeFont(LABEL1_FONT);
|
||||
else tft.setFreeFont(LABEL2_FONT);
|
||||
|
||||
if (key[b].justReleased()) key[b].drawButton(); // draw normal
|
||||
|
||||
if (key[b].justPressed()) {
|
||||
key[b].drawButton(true); // draw invert
|
||||
|
||||
// if a numberpad button, append the relevant # to the numberBuffer
|
||||
if (b >= 3) {
|
||||
if (numberIndex < NUM_LEN) {
|
||||
numberBuffer[numberIndex] = keyLabel[b][0];
|
||||
numberIndex++;
|
||||
numberBuffer[numberIndex] = 0; // zero terminate
|
||||
}
|
||||
status(""); // Clear the old status
|
||||
}
|
||||
|
||||
// Del button, so delete last char
|
||||
if (b == 1) {
|
||||
numberBuffer[numberIndex] = 0;
|
||||
if (numberIndex > 0) {
|
||||
numberIndex--;
|
||||
numberBuffer[numberIndex] = 0;//' ';
|
||||
}
|
||||
status(""); // Clear the old status
|
||||
}
|
||||
|
||||
if (b == 2) {
|
||||
status("Sent value to serial port");
|
||||
Serial.println(numberBuffer);
|
||||
}
|
||||
// we dont really check that the text field makes sense
|
||||
// just try to call
|
||||
if (b == 0) {
|
||||
status("Value cleared");
|
||||
numberIndex = 0; // Reset index to 0
|
||||
numberBuffer[numberIndex] = 0; // Place null in buffer
|
||||
}
|
||||
|
||||
// Update the number display field
|
||||
tft.setTextDatum(TL_DATUM); // Use top left corner as text coord datum
|
||||
tft.setFreeFont(&FreeSans18pt7b); // Choose a nicefont that fits box
|
||||
tft.setTextColor(DISP_TCOLOR); // Set the font colour
|
||||
|
||||
// Draw the string, the value returned is the width in pixels
|
||||
int xwidth = tft.drawString(numberBuffer, DISP_X + 4, DISP_Y + 12);
|
||||
|
||||
// Now cover up the rest of the line up by drawing a black rectangle. No flicker this way
|
||||
// but it will not work with italic or oblique fonts due to character overlap.
|
||||
tft.fillRect(DISP_X + 4 + xwidth, DISP_Y + 1, DISP_W - xwidth - 5, DISP_H - 2, TFT_BLACK);
|
||||
|
||||
delay(10); // UI debouncing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
void drawKeypad()
|
||||
{
|
||||
// Draw the keys
|
||||
for (uint8_t row = 0; row < 5; row++) {
|
||||
for (uint8_t col = 0; col < 3; col++) {
|
||||
uint8_t b = col + row * 3;
|
||||
|
||||
if (b < 3) tft.setFreeFont(LABEL1_FONT);
|
||||
else tft.setFreeFont(LABEL2_FONT);
|
||||
|
||||
key[b].initButton(&tft, KEY_X + col * (KEY_W + KEY_SPACING_X),
|
||||
KEY_Y + row * (KEY_H + KEY_SPACING_Y), // x, y, w, h, outline, fill, text
|
||||
KEY_W, KEY_H, TFT_WHITE, keyColor[b], TFT_WHITE,
|
||||
keyLabel[b], KEY_TEXTSIZE);
|
||||
key[b].drawButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
void touch_calibrate()
|
||||
{
|
||||
uint16_t calData[5];
|
||||
uint8_t calDataOK = 0;
|
||||
|
||||
// check file system exists
|
||||
if (!SPIFFS.begin()) {
|
||||
Serial.println("Formating file system");
|
||||
SPIFFS.format();
|
||||
SPIFFS.begin();
|
||||
}
|
||||
|
||||
// check if calibration file exists and size is correct
|
||||
if (SPIFFS.exists(CALIBRATION_FILE)) {
|
||||
if (REPEAT_CAL)
|
||||
{
|
||||
// Delete if we want to re-calibrate
|
||||
SPIFFS.remove(CALIBRATION_FILE);
|
||||
}
|
||||
else
|
||||
{
|
||||
File f = SPIFFS.open(CALIBRATION_FILE, "r");
|
||||
if (f) {
|
||||
if (f.readBytes((char *)calData, 14) == 14)
|
||||
calDataOK = 1;
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (calDataOK && !REPEAT_CAL) {
|
||||
// calibration data valid
|
||||
tft.setTouch(calData);
|
||||
} else {
|
||||
// data not valid so recalibrate
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setCursor(20, 0);
|
||||
tft.setTextFont(2);
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
tft.println("Touch corners as indicated");
|
||||
|
||||
tft.setTextFont(1);
|
||||
tft.println();
|
||||
|
||||
if (REPEAT_CAL) {
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
tft.println("Set REPEAT_CAL to false to stop this running again!");
|
||||
}
|
||||
|
||||
tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
|
||||
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
tft.println("Calibration complete!");
|
||||
|
||||
// store data
|
||||
File f = SPIFFS.open(CALIBRATION_FILE, "w");
|
||||
if (f) {
|
||||
f.write((const unsigned char *)calData, 14);
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
// Print something in the mini status bar
|
||||
void status(const char *msg) {
|
||||
tft.setTextPadding(240);
|
||||
//tft.setCursor(STATUS_X, STATUS_Y);
|
||||
tft.setTextColor(TFT_WHITE, TFT_DARKGREY);
|
||||
tft.setTextFont(0);
|
||||
tft.setTextDatum(TC_DATUM);
|
||||
tft.setTextSize(1);
|
||||
tft.drawString(msg, STATUS_X, STATUS_Y);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
Display all the fonts.
|
||||
|
||||
This sketch uses the GLCD (font 1) and fonts 2, 4, 6, 7, 8
|
||||
|
||||
#########################################################################
|
||||
###### 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
|
||||
#define TFT_BROWN 0x38E0
|
||||
|
||||
// Pause in milliseconds between screens, change to 0 to time font rendering
|
||||
#define WAIT 1000
|
||||
|
||||
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
||||
|
||||
unsigned long targetTime = 0; // Used for testing draw times
|
||||
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
targetTime = millis();
|
||||
|
||||
// First we test them with a background colour set
|
||||
tft.setTextSize(1);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
|
||||
tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
|
||||
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2);
|
||||
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2);
|
||||
tft.drawString("abcdefghijklmnopqrstuvw", 0, 48, 2);
|
||||
int xpos = 0;
|
||||
xpos += tft.drawString("xyz{|}~", 0, 64, 2);
|
||||
tft.drawChar(127, xpos, 64, 2);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
|
||||
tft.drawString(" !\"#$%&'()*+,-.", 0, 0, 4);
|
||||
tft.drawString("/0123456789:;", 0, 26, 4);
|
||||
tft.drawString("<=>?@ABCDE", 0, 52, 4);
|
||||
tft.drawString("FGHIJKLMNO", 0, 78, 4);
|
||||
tft.drawString("PQRSTUVWX", 0, 104, 4);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.drawString("YZ[\\]^_`abc", 0, 0, 4);
|
||||
tft.drawString("defghijklmno", 0, 26, 4);
|
||||
tft.drawString("pqrstuvwxyz", 0, 52, 4);
|
||||
xpos = 0;
|
||||
xpos += tft.drawString("{|}~", 0, 78, 4);
|
||||
tft.drawChar(127, xpos, 78, 4);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
|
||||
tft.drawString("012345", 0, 0, 6);
|
||||
tft.drawString("6789", 0, 40, 6);
|
||||
tft.drawString("apm-:.", 0, 80, 6);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
|
||||
tft.drawString("0123", 0, 0, 7);
|
||||
tft.drawString("4567", 0, 60, 7);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.drawString("890:.", 0, 0, 7);
|
||||
tft.drawString("", 0, 60, 7);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
|
||||
tft.drawString("0123", 0, 0, 8);
|
||||
tft.drawString("4567", 0, 72, 8);
|
||||
delay(WAIT);;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.drawString("890:.", 0, 0, 8);
|
||||
tft.drawString("", 0, 72, 8);
|
||||
delay(WAIT);;
|
||||
|
||||
tft.setTextSize(2);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
|
||||
tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
|
||||
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 32, 2);
|
||||
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 64, 2);
|
||||
tft.drawString("abcdefghijklmnopqrstuvw", 0, 96, 2);
|
||||
xpos = 0;
|
||||
xpos += tft.drawString("xyz{|}~", 0, 128, 2);
|
||||
tft.drawChar(127, xpos, 128, 2);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
|
||||
tft.drawString(" !\"#$%&'()*+,-.", 0, 0, 4);
|
||||
tft.drawString("/0123456789:;", 0, 52, 4);
|
||||
tft.drawString("<=>?@ABCDE", 0, 104, 4);
|
||||
tft.drawString("FGHIJKLMNO", 0, 156, 4);
|
||||
tft.drawString("PQRSTUVWX", 0, 208, 4);
|
||||
delay(WAIT);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.drawString("YZ[\\]^_`abc", 0, 0, 4);
|
||||
tft.drawString("defghijklmno", 0, 52, 4);
|
||||
tft.drawString("pqrstuvwxyz", 0, 104, 4);
|
||||
xpos = 0;
|
||||
xpos += tft.drawString("{|}~", 0, 156, 4);
|
||||
tft.drawChar(127, xpos, 156, 4);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
|
||||
tft.drawString("01234", 0, 0, 6);
|
||||
tft.drawString("56789", 0, 80, 6);
|
||||
tft.drawString("apm-:.", 0, 160, 6);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
|
||||
tft.drawString("0123", 0, 0, 7);
|
||||
tft.drawString("4567", 0, 120, 7);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.drawString("890:.", 0, 0, 7);
|
||||
tft.drawString("", 0, 120, 7);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
|
||||
tft.drawString("0123", 0, 0, 8);
|
||||
tft.drawString("4567", 0, 144, 8);
|
||||
delay(WAIT);;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.drawString("890:.", 0, 0, 8);
|
||||
tft.drawString("", 0, 144, 8);
|
||||
delay(WAIT);;
|
||||
|
||||
tft.setTextColor(TFT_MAGENTA, TFT_BROWN);
|
||||
|
||||
tft.drawNumber(millis() - targetTime, 0, 180, 4);
|
||||
delay(4000);;
|
||||
|
||||
// Now test them with transparent background
|
||||
targetTime = millis();
|
||||
|
||||
tft.setTextSize(1);
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
|
||||
tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
|
||||
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 16, 2);
|
||||
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 32, 2);
|
||||
tft.drawString("abcdefghijklmnopqrstuvw", 0, 48, 2);
|
||||
xpos = 0;
|
||||
xpos += tft.drawString("xyz{|}~", 0, 64, 2);
|
||||
tft.drawChar(127, xpos, 64, 2);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
|
||||
tft.drawString(" !\"#$%&'()*+,-.", 0, 0, 4);
|
||||
tft.drawString("/0123456789:;", 0, 26, 4);
|
||||
tft.drawString("<=>?@ABCDE", 0, 52, 4);
|
||||
tft.drawString("FGHIJKLMNO", 0, 78, 4);
|
||||
tft.drawString("PQRSTUVWX", 0, 104, 4);
|
||||
|
||||
delay(WAIT);
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.drawString("YZ[\\]^_`abc", 0, 0, 4);
|
||||
tft.drawString("defghijklmno", 0, 26, 4);
|
||||
tft.drawString("pqrstuvwxyz", 0, 52, 4);
|
||||
xpos = 0;
|
||||
xpos += tft.drawString("{|}~", 0, 78, 4);
|
||||
tft.drawChar(127, xpos, 78, 4);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_BLUE);
|
||||
|
||||
tft.drawString("012345", 0, 0, 6);
|
||||
tft.drawString("6789", 0, 40, 6);
|
||||
tft.drawString("apm-:.", 0, 80, 6);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_RED);
|
||||
|
||||
tft.drawString("0123", 0, 0, 7);
|
||||
tft.drawString("4567", 0, 60, 7);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.drawString("890:.", 0, 0, 7);
|
||||
tft.drawString("", 0, 60, 7);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_YELLOW);
|
||||
|
||||
tft.drawString("0123", 0, 0, 8);
|
||||
tft.drawString("4567", 0, 72, 8);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.drawString("890:.", 0, 0, 8);
|
||||
tft.drawString("", 0, 72, 8);
|
||||
delay(WAIT);
|
||||
|
||||
tft.setTextSize(2);
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
|
||||
tft.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2);
|
||||
tft.drawString("789:;<=>?@ABCDEFGHIJKL", 0, 32, 2);
|
||||
tft.drawString("MNOPQRSTUVWXYZ[\\]^_`", 0, 64, 2);
|
||||
tft.drawString("abcdefghijklmnopqrstuvw", 0, 96, 2);
|
||||
xpos = 0;
|
||||
xpos += tft.drawString("xyz{|}~", 0, 128, 2);
|
||||
tft.drawChar(127, xpos, 128, 2);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
|
||||
tft.drawString(" !\"#$%&'()*+,-.", 0, 0, 4);
|
||||
tft.drawString("/0123456789:;", 0, 52, 4);
|
||||
tft.drawString("<=>?@ABCDE", 0, 104, 4);
|
||||
tft.drawString("FGHIJKLMNO", 0, 156, 4);
|
||||
tft.drawString("PQRSTUVWX", 0, 208, 4);
|
||||
delay(WAIT);
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.drawString("YZ[\\]^_`abc", 0, 0, 4);
|
||||
tft.drawString("defghijklmno", 0, 52, 4);
|
||||
tft.drawString("pqrstuvwxyz", 0, 104, 4);
|
||||
xpos = 0;
|
||||
xpos += tft.drawString("{|}~", 0, 156, 4);
|
||||
tft.drawChar(127, xpos, 156, 4);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_BLUE);
|
||||
|
||||
tft.drawString("01234", 0, 0, 6);
|
||||
tft.drawString("56789", 0, 80, 6);
|
||||
tft.drawString("apm-:.", 0, 160, 6);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_RED);
|
||||
|
||||
tft.drawString("0123", 0, 0, 7);
|
||||
tft.drawString("4567", 0, 120, 7);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.drawString("890:.", 0, 0, 7);
|
||||
tft.drawString("", 0, 120, 7);
|
||||
delay(WAIT);
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.setTextColor(TFT_YELLOW);
|
||||
|
||||
tft.drawString("0123", 0, 0, 8);
|
||||
tft.drawString("4567", 0, 144, 8);
|
||||
delay(WAIT);;
|
||||
|
||||
tft.fillScreen(TFT_BROWN);
|
||||
tft.drawString("890:.", 0, 0, 8);
|
||||
tft.drawString("", 0, 144, 8);
|
||||
delay(WAIT);;
|
||||
|
||||
tft.setTextColor(TFT_MAGENTA);
|
||||
|
||||
tft.drawNumber(millis() - targetTime, 0, 180, 4);
|
||||
delay(4000);;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
// Read the ID from the TFT controller
|
||||
// The sketch only supports displays with a bi-directional SPI data line (often labelled SDA)
|
||||
|
||||
// Bit bashes SPI so it does NOT assume hardware SPI wired up
|
||||
// No other libraries are needed
|
||||
|
||||
// NOTE: This sketch does not work with parallel displays!
|
||||
|
||||
// Original author unknown
|
||||
// Adapted by Bodmer 22/5/16, updated 16/9/16
|
||||
|
||||
// Change the pin settings to suit your hardware
|
||||
|
||||
// UNO etc
|
||||
//#define TFT_MOSI 11
|
||||
//#define TFT_SCK 13
|
||||
//#define TFT_CS 9
|
||||
//#define TFT_DC 8
|
||||
//#define TFT_RESET 7
|
||||
|
||||
//Mega
|
||||
//#define TFT_MOSI 51
|
||||
//#define TFT_SCK 52
|
||||
//#define TFT_CS 47
|
||||
//#define TFT_DC 48
|
||||
//#define TFT_RESET 44
|
||||
|
||||
//Micro
|
||||
//#define TFT_MOSI MOSI
|
||||
//#define TFT_SCK SCK
|
||||
//#define TFT_CS 10
|
||||
//#define TFT_DC 9
|
||||
//#define TFT_RESET 8
|
||||
|
||||
//NodeMCU
|
||||
#define TFT_MOSI D7
|
||||
#define TFT_SCK D5
|
||||
#define TFT_CS D8
|
||||
#define TFT_DC D3
|
||||
#define TFT_RESET D4
|
||||
|
||||
/* Example Serial Monitor output:
|
||||
|
||||
TFT driver register values:
|
||||
===========================
|
||||
Register 0x01: 0x00
|
||||
Register 0x04: 0x548066
|
||||
Register 0x09: 0x610000
|
||||
Register 0x0A: 0x08
|
||||
Register 0x0B: 0x00
|
||||
Register 0x0C: 0x06
|
||||
Register 0x0D: 0x00
|
||||
Register 0x0E: 0x00
|
||||
Register 0x0F: 0x00
|
||||
Register 0x2E: 0x1834B4
|
||||
Register 0xDA: 0x54
|
||||
Register 0xDB: 0x80
|
||||
Register 0xDC: 0x66
|
||||
===========================
|
||||
|
||||
Looks like driver chip is: ILI9163 (based on datasheet ID)
|
||||
|
||||
*/
|
||||
|
||||
char *chip = "Unknown ";
|
||||
|
||||
uint32_t readwrite8(uint8_t cmd, uint8_t bits, uint8_t dummy)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
uint8_t val = cmd;
|
||||
int cnt = 8;
|
||||
digitalWrite(TFT_CS, LOW);
|
||||
digitalWrite(TFT_DC, LOW);
|
||||
pinMode(TFT_MOSI, OUTPUT);
|
||||
for (int i = 0; i < 8; i++) { //send command
|
||||
digitalWrite(TFT_MOSI, (val & 0x80) != 0);
|
||||
digitalWrite(TFT_SCK, HIGH);
|
||||
digitalWrite(TFT_SCK, LOW);
|
||||
val <<= 1;
|
||||
}
|
||||
if (bits == 0) {
|
||||
digitalWrite(TFT_CS, HIGH);
|
||||
return 0;
|
||||
}
|
||||
pinMode(TFT_MOSI, INPUT_PULLUP);
|
||||
digitalWrite(TFT_DC, HIGH);
|
||||
for (int i = 0; i < dummy; i++) { //any dummy clocks
|
||||
digitalWrite(TFT_SCK, HIGH);
|
||||
digitalWrite(TFT_SCK, LOW);
|
||||
}
|
||||
for (int i = 0; i < bits; i++) { // read results
|
||||
ret <<= 1;
|
||||
if (digitalRead(TFT_MOSI)) ret |= 1;;
|
||||
digitalWrite(TFT_SCK, HIGH);
|
||||
digitalWrite(TFT_SCK, LOW);
|
||||
}
|
||||
digitalWrite(TFT_CS, HIGH);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void showreg(uint8_t reg, uint8_t bits, uint8_t dummy)
|
||||
{
|
||||
uint32_t val;
|
||||
val = readwrite8(reg, bits, dummy);
|
||||
|
||||
Serial.print("Register 0x");
|
||||
if (reg < 0x10) Serial.print("0");
|
||||
Serial.print(reg , HEX);
|
||||
Serial.print(": 0x");
|
||||
if (val < 0x10) Serial.print("0");
|
||||
Serial.println(val, HEX);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
uint32_t ID = 0;
|
||||
Serial.begin(115200);
|
||||
|
||||
delay(4000); // Delay to allow USB to connect to a Leonardo etc
|
||||
|
||||
Serial.println("TFT driver register values:");
|
||||
Serial.println("===========================");
|
||||
digitalWrite(TFT_CS, HIGH);
|
||||
// digitalWrite(TFT_SCK, HIGH);
|
||||
pinMode(TFT_CS, OUTPUT);
|
||||
pinMode(TFT_SCK, OUTPUT);
|
||||
pinMode(TFT_MOSI, OUTPUT);
|
||||
pinMode(MISO, INPUT_PULLUP);
|
||||
pinMode(TFT_DC, OUTPUT);
|
||||
pinMode(TFT_RESET, OUTPUT);
|
||||
digitalWrite(TFT_RESET, HIGH);
|
||||
digitalWrite(TFT_RESET, LOW); //Hardware Reset
|
||||
delay(50);
|
||||
digitalWrite(TFT_RESET, HIGH);
|
||||
showreg(0x01, 0, 0); //Software Reset
|
||||
delay(100);
|
||||
ID = readwrite8(0x04, 24, 1);
|
||||
|
||||
if ((ID & 0xFF8000) == 0x5C8000uL) chip = "ST7735 (based on datasheet ID)";
|
||||
if (ID == 0x7C89F0uL) chip = "ST7735S (empirical value)";
|
||||
if (ID == 0x548066uL) chip = "ILI9163C (based on datasheet ID)";
|
||||
if (ID == 0x5C0000uL) chip = "S6D02A1 (based on datasheet ID)";
|
||||
|
||||
showreg(0x04, 24, 1); //RDDID
|
||||
showreg(0x09, 32, 1); //RDSTATUS
|
||||
showreg(0x0A, 8, 0);
|
||||
showreg(0x0B, 8, 0);
|
||||
showreg(0x0C, 8, 0);
|
||||
showreg(0x0D, 8, 0);
|
||||
showreg(0x0E, 8, 0);
|
||||
showreg(0x0F, 8, 0);
|
||||
showreg(0x2E, 24, 8); //readGRAM
|
||||
showreg(0x3F, 32, 1); //readGRAM
|
||||
showreg(0xDA, 8, 0);
|
||||
showreg(0xDB, 8, 0);
|
||||
showreg(0xDC, 8, 0);
|
||||
|
||||
Serial.println("===========================");
|
||||
Serial.println();
|
||||
Serial.print("Looks like driver chip is: " );Serial.println(chip);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
// Demo using arcFill to draw ellipses and a segmented elipse
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define DEG2RAD 0.0174532925
|
||||
|
||||
#define LOOP_DELAY 10 // Loop delay to slow things down
|
||||
|
||||
byte inc = 0;
|
||||
unsigned int col = 0;
|
||||
|
||||
byte red = 31; // Red is the top 5 bits of a 16 bit colour value
|
||||
byte green = 0;// Green is the middle 6 bits
|
||||
byte blue = 0; // Blue is the bottom 5 bits
|
||||
byte state = 0;
|
||||
|
||||
void setup(void) {
|
||||
tft.begin();
|
||||
|
||||
tft.setRotation(1);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
// Continuous elliptical arc drawing
|
||||
fillArc(160, 120, inc * 6, 1, 140, 100, 10, rainbow(col));
|
||||
|
||||
// Continuous segmented (inc*2) elliptical arc drawing
|
||||
fillArc(160, 120, ((inc * 2) % 60) * 6, 1, 120, 80, 30, rainbow(col));
|
||||
|
||||
// Circle drawing using arc with arc width = radius
|
||||
fillArc(160, 120, inc * 6, 1, 42, 42, 42, rainbow(col));
|
||||
|
||||
inc++;
|
||||
col += 1;
|
||||
if (col > 191) col = 0;
|
||||
if (inc > 59) inc = 0;
|
||||
|
||||
delay(LOOP_DELAY);
|
||||
}
|
||||
|
||||
|
||||
// #########################################################################
|
||||
// Draw a circular or elliptical arc with a defined thickness
|
||||
// #########################################################################
|
||||
|
||||
// x,y == coords of centre of arc
|
||||
// start_angle = 0 - 359
|
||||
// seg_count = number of 6 degree segments to draw (60 => 360 degree arc)
|
||||
// rx = x axis outer radius
|
||||
// ry = y axis outer radius
|
||||
// w = width (thickness) of arc in pixels
|
||||
// colour = 16 bit colour value
|
||||
// Note if rx and ry are the same then an arc of a circle is drawn
|
||||
|
||||
void fillArc(int x, int y, int start_angle, int seg_count, int rx, int ry, int w, unsigned int colour)
|
||||
{
|
||||
|
||||
byte seg = 6; // Segments are 3 degrees wide = 120 segments for 360 degrees
|
||||
byte inc = 6; // Draw segments every 3 degrees, increase to 6 for segmented ring
|
||||
|
||||
// Calculate first pair of coordinates for segment start
|
||||
float sx = cos((start_angle - 90) * DEG2RAD);
|
||||
float sy = sin((start_angle - 90) * DEG2RAD);
|
||||
uint16_t x0 = sx * (rx - w) + x;
|
||||
uint16_t y0 = sy * (ry - w) + y;
|
||||
uint16_t x1 = sx * rx + x;
|
||||
uint16_t y1 = sy * ry + y;
|
||||
|
||||
// Draw colour blocks every inc degrees
|
||||
for (int i = start_angle; i < start_angle + seg * seg_count; i += inc) {
|
||||
|
||||
// Calculate pair of coordinates for segment end
|
||||
float sx2 = cos((i + seg - 90) * DEG2RAD);
|
||||
float sy2 = sin((i + seg - 90) * DEG2RAD);
|
||||
int x2 = sx2 * (rx - w) + x;
|
||||
int y2 = sy2 * (ry - w) + y;
|
||||
int x3 = sx2 * rx + x;
|
||||
int y3 = sy2 * ry + y;
|
||||
|
||||
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
|
||||
|
||||
// Copy segment end to sgement start for next segment
|
||||
x0 = x2;
|
||||
y0 = y2;
|
||||
x1 = x3;
|
||||
y1 = y3;
|
||||
}
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Return the 16 bit colour with brightness 0-100%
|
||||
// #########################################################################
|
||||
unsigned int brightness(unsigned int colour, int brightness)
|
||||
{
|
||||
byte red = colour >> 11;
|
||||
byte green = (colour & 0x7E0) >> 5;
|
||||
byte blue = colour & 0x1F;
|
||||
|
||||
blue = (blue * brightness) / 100;
|
||||
green = (green * brightness) / 100;
|
||||
red = (red * brightness) / 100;
|
||||
|
||||
return (red << 11) + (green << 5) + blue;
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Return a 16 bit rainbow colour
|
||||
// #########################################################################
|
||||
unsigned int rainbow(byte value)
|
||||
{
|
||||
// Value is expected to be in range 0-127
|
||||
// The value is converted to a spectrum colour from 0 = blue through to 127 = red
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
green ++;
|
||||
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 --;
|
||||
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;
|
||||
}
|
||||
return red << 11 | green << 5 | blue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
Font draw speed and flicker test, draws all numbers 0-999 in each font
|
||||
Average time in milliseconds to draw is shown in red
|
||||
A total of 2890 characters are drawn in each font
|
||||
|
||||
Needs fonts 2, 4, 6, 7 and 8
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
unsigned long drawTime = 0;
|
||||
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
drawTime = millis();
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
yield();tft.drawNumber(i, 100, 80, 1);
|
||||
}
|
||||
|
||||
drawTime = millis() - drawTime;
|
||||
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
int xpos = 20;
|
||||
xpos += tft.drawFloat(drawTime / 2890.0, 3, xpos, 180, 4);
|
||||
tft.drawString(" ms per character", xpos, 180, 4);
|
||||
if (drawTime < 100) tft.drawString("Font 1 not loaded!", 50, 210, 4);
|
||||
|
||||
delay(4000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
drawTime = millis();
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
yield();tft.drawNumber(i, 100, 80, 2);
|
||||
}
|
||||
|
||||
drawTime = millis() - drawTime;
|
||||
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
xpos = 20;
|
||||
xpos += tft.drawFloat(drawTime / 2890.0, 3, xpos, 180, 4);
|
||||
tft.drawString(" ms per character", xpos, 180, 4);
|
||||
if (drawTime < 200) tft.drawString("Font 2 not loaded!", 50, 210, 4);
|
||||
|
||||
delay(4000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
drawTime = millis();
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
yield();tft.drawNumber(i, 100, 80, 4);
|
||||
}
|
||||
|
||||
drawTime = millis() - drawTime;
|
||||
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
xpos = 20;
|
||||
xpos += tft.drawFloat(drawTime / 2890.0, 3, xpos, 180, 4);
|
||||
tft.drawString(" ms per character", xpos, 180, 4);
|
||||
if (drawTime < 200) tft.drawString("Font 4 not loaded!", 50, 210, 4);
|
||||
|
||||
delay(4000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
drawTime = millis();
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
yield();tft.drawNumber(i, 100, 80, 6);
|
||||
}
|
||||
|
||||
drawTime = millis() - drawTime;
|
||||
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
xpos = 20;
|
||||
xpos += tft.drawFloat(drawTime / 2890.0, 3, xpos, 180, 4);
|
||||
tft.drawString(" ms per character", xpos, 180, 4);
|
||||
if (drawTime < 200) tft.drawString("Font 6 not loaded!", 50, 210, 4);
|
||||
|
||||
delay(4000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
drawTime = millis();
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
yield();tft.drawNumber(i, 100, 80, 7);
|
||||
}
|
||||
|
||||
drawTime = millis() - drawTime;
|
||||
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
xpos = 20;
|
||||
xpos += tft.drawFloat(drawTime / 2890.0, 3, xpos, 180, 4);
|
||||
tft.drawString(" ms per character", xpos, 180, 4);
|
||||
if (drawTime < 200) tft.drawString("Font 7 not loaded!", 50, 210, 4);
|
||||
|
||||
delay(4000);
|
||||
tft.fillScreen(TFT_YELLOW);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
drawTime = millis();
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
yield();tft.drawNumber(i, 100, 80, 8);
|
||||
}
|
||||
|
||||
drawTime = millis() - drawTime;
|
||||
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
xpos = 20;
|
||||
xpos += tft.drawFloat(drawTime / 2890.0, 3, xpos, 180, 4);
|
||||
tft.drawString(" ms per character", xpos, 180, 4);
|
||||
if (drawTime < 200) tft.drawString("Font 8 not loaded!", 50, 210, 4);
|
||||
|
||||
delay(4000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
148
libraries/TFT_eSPI/examples/320 x 240/TFT_Clock/TFT_Clock.ino
Normal file
148
libraries/TFT_eSPI/examples/320 x 240/TFT_Clock/TFT_Clock.ino
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
An example analogue clock using a TFT LCD screen to show the time
|
||||
use of some of the drawing commands with the library.
|
||||
|
||||
For a more accurate clock, it would be better to use the RTClib library.
|
||||
But this is just a demo.
|
||||
|
||||
This sketch uses font 4 only.
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
|
||||
Based on a sketch by Gilchrist 6/2/2014 1.0
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
|
||||
#define TFT_GREY 0x5AEB
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
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=120, osy=120, omx=120, omy=120, ohx=120, ohy=120; // Saved H, M, S x & y coords
|
||||
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); // Forward declaration needed for IDE 1.6.x
|
||||
uint8_t hh=conv2d(__TIME__), mm=conv2d(__TIME__+3), ss=conv2d(__TIME__+6); // Get H, M, S from compile time
|
||||
|
||||
bool initial = 1;
|
||||
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(0);
|
||||
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
//tft.fillScreen(TFT_RED);
|
||||
//tft.fillScreen(TFT_GREEN);
|
||||
//tft.fillScreen(TFT_BLUE);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.fillScreen(TFT_GREY);
|
||||
|
||||
tft.setTextColor(TFT_WHITE, TFT_GREY); // Adding a background colour erases previous text automatically
|
||||
|
||||
// Draw clock face
|
||||
tft.fillCircle(120, 120, 118, TFT_GREEN);
|
||||
tft.fillCircle(120, 120, 110, TFT_BLACK);
|
||||
|
||||
// Draw 12 lines
|
||||
for(int i = 0; i<360; i+= 30) {
|
||||
sx = cos((i-90)*0.0174532925);
|
||||
sy = sin((i-90)*0.0174532925);
|
||||
x0 = sx*114+120;
|
||||
yy0 = sy*114+120;
|
||||
x1 = sx*100+120;
|
||||
yy1 = sy*100+120;
|
||||
|
||||
tft.drawLine(x0, yy0, x1, yy1, TFT_GREEN);
|
||||
}
|
||||
|
||||
// Draw 60 dots
|
||||
for(int i = 0; i<360; i+= 6) {
|
||||
sx = cos((i-90)*0.0174532925);
|
||||
sy = sin((i-90)*0.0174532925);
|
||||
x0 = sx*102+120;
|
||||
yy0 = sy*102+120;
|
||||
// Draw minute markers
|
||||
tft.drawPixel(x0, yy0, TFT_WHITE);
|
||||
|
||||
// Draw main quadrant dots
|
||||
if(i==0 || i==180) tft.fillCircle(x0, yy0, 2, TFT_WHITE);
|
||||
if(i==90 || i==270) tft.fillCircle(x0, yy0, 2, TFT_WHITE);
|
||||
}
|
||||
|
||||
tft.fillCircle(120, 121, 3, TFT_WHITE);
|
||||
|
||||
// Draw text at position 120,260 using fonts 4
|
||||
// Only font numbers 2,4,6,7 are valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : . - a p m
|
||||
// Font 7 is a 7 segment font and only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : .
|
||||
tft.drawCentreString("Time flies",120,260,4);
|
||||
|
||||
targetTime = millis() + 1000;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (targetTime < millis()) {
|
||||
targetTime += 1000;
|
||||
ss++; // Advance second
|
||||
if (ss==60) {
|
||||
ss=0;
|
||||
mm++; // Advance minute
|
||||
if(mm>59) {
|
||||
mm=0;
|
||||
hh++; // Advance hour
|
||||
if (hh>23) {
|
||||
hh=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pre-compute hand degrees, x & y coords for a fast screen update
|
||||
sdeg = ss*6; // 0-59 -> 0-354
|
||||
mdeg = mm*6+sdeg*0.01666667; // 0-59 -> 0-360 - includes seconds
|
||||
hdeg = hh*30+mdeg*0.0833333; // 0-11 -> 0-360 - includes minutes and seconds
|
||||
hx = cos((hdeg-90)*0.0174532925);
|
||||
hy = sin((hdeg-90)*0.0174532925);
|
||||
mx = cos((mdeg-90)*0.0174532925);
|
||||
my = sin((mdeg-90)*0.0174532925);
|
||||
sx = cos((sdeg-90)*0.0174532925);
|
||||
sy = sin((sdeg-90)*0.0174532925);
|
||||
|
||||
if (ss==0 || initial) {
|
||||
initial = 0;
|
||||
// Erase hour and minute hand positions every minute
|
||||
tft.drawLine(ohx, ohy, 120, 121, TFT_BLACK);
|
||||
ohx = hx*62+121;
|
||||
ohy = hy*62+121;
|
||||
tft.drawLine(omx, omy, 120, 121, TFT_BLACK);
|
||||
omx = mx*84+120;
|
||||
omy = my*84+121;
|
||||
}
|
||||
|
||||
// Redraw new hand positions, hour and minute hands not erased here to avoid flicker
|
||||
tft.drawLine(osx, osy, 120, 121, TFT_BLACK);
|
||||
osx = sx*90+121;
|
||||
osy = sy*90+121;
|
||||
tft.drawLine(osx, osy, 120, 121, TFT_RED);
|
||||
tft.drawLine(ohx, ohy, 120, 121, TFT_WHITE);
|
||||
tft.drawLine(omx, omy, 120, 121, TFT_WHITE);
|
||||
tft.drawLine(osx, osy, 120, 121, TFT_RED);
|
||||
|
||||
tft.fillCircle(120, 121, 3, TFT_RED);
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t conv2d(const char* p) {
|
||||
uint8_t v = 0;
|
||||
if ('0' <= *p && *p <= '9')
|
||||
v = *p - '0';
|
||||
return 10 * v + *++p - '0';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
An example digital clock using a TFT LCD screen to show the time.
|
||||
Demonstrates use of the font printing routines. (Time updates but date does not.)
|
||||
|
||||
It uses the time of compile/upload to set the time
|
||||
For a more accurate clock, it would be better to use the RTClib library.
|
||||
But this is just a demo...
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
|
||||
Based on clock sketch by Gilchrist 6/2/2014 1.0
|
||||
|
||||
A few colour codes:
|
||||
|
||||
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> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
#define TFT_GREY 0x5AEB
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
uint32_t targetTime = 0; // for next 1 second timeout
|
||||
|
||||
static uint8_t conv2d(const char* p); // Forward declaration needed for IDE 1.6.x
|
||||
|
||||
uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time
|
||||
|
||||
byte omm = 99, oss = 99;
|
||||
byte xcolon = 0, xsecs = 0;
|
||||
unsigned int colour = 0;
|
||||
|
||||
void setup(void) {
|
||||
//Serial.begin(115200);
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
|
||||
targetTime = millis() + 1000;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (targetTime < millis()) {
|
||||
// Set next update for 1 second later
|
||||
targetTime = millis() + 1000;
|
||||
|
||||
// Adjust the time values by adding 1 second
|
||||
ss++; // Advance second
|
||||
if (ss == 60) { // Check for roll-over
|
||||
ss = 0; // Reset seconds to zero
|
||||
omm = mm; // Save last minute time for display update
|
||||
mm++; // Advance minute
|
||||
if (mm > 59) { // Check for roll-over
|
||||
mm = 0;
|
||||
hh++; // Advance hour
|
||||
if (hh > 23) { // Check for 24hr roll-over (could roll-over on 13)
|
||||
hh = 0; // 0 for 24 hour clock, set to 1 for 12 hour clock
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update digital time
|
||||
int xpos = 0;
|
||||
int ypos = 85; // Top left corner ot clock text, about half way down
|
||||
int ysecs = ypos + 24;
|
||||
|
||||
if (omm != mm) { // Redraw hours and minutes time every minute
|
||||
omm = mm;
|
||||
// Draw hours and minutes
|
||||
if (hh < 10) xpos += tft.drawChar('0', xpos, ypos, 8); // Add hours leading zero for 24 hr clock
|
||||
xpos += tft.drawNumber(hh, xpos, ypos, 8); // Draw hours
|
||||
xcolon = xpos; // Save colon coord for later to flash on/off later
|
||||
xpos += tft.drawChar(':', xpos, ypos - 8, 8);
|
||||
if (mm < 10) xpos += tft.drawChar('0', xpos, ypos, 8); // Add minutes leading zero
|
||||
xpos += tft.drawNumber(mm, xpos, ypos, 8); // Draw minutes
|
||||
xsecs = xpos; // Sae seconds 'x' position for later display updates
|
||||
}
|
||||
if (oss != ss) { // Redraw seconds time every second
|
||||
oss = ss;
|
||||
xpos = xsecs;
|
||||
|
||||
if (ss % 2) { // Flash the colons on/off
|
||||
tft.setTextColor(0x39C4, TFT_BLACK); // Set colour to grey to dim colon
|
||||
tft.drawChar(':', xcolon, ypos - 8, 8); // Hour:minute colon
|
||||
xpos += tft.drawChar(':', xsecs, ysecs, 6); // Seconds colon
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK); // Set colour back to yellow
|
||||
}
|
||||
else {
|
||||
tft.drawChar(':', xcolon, ypos - 8, 8); // Hour:minute colon
|
||||
xpos += tft.drawChar(':', xsecs, ysecs, 6); // Seconds colon
|
||||
}
|
||||
|
||||
//Draw seconds
|
||||
if (ss < 10) xpos += tft.drawChar('0', xpos, ysecs, 6); // Add leading zero
|
||||
tft.drawNumber(ss, xpos, ysecs, 6); // Draw seconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Function to extract numbers from compile time string
|
||||
static uint8_t conv2d(const char* p) {
|
||||
uint8_t v = 0;
|
||||
if ('0' <= *p && *p <= '9')
|
||||
v = *p - '0';
|
||||
return 10 * v + *++p - '0';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
Example for TFT_eSPI library
|
||||
|
||||
Created by Bodmer 11/03/17
|
||||
|
||||
Make sure LOAD_GFXFF is defined in the used User_Setup file
|
||||
within the library folder.
|
||||
|
||||
--------------------------- NOTE ----------------------------------------
|
||||
The free font encoding format does not lend itself easily to plotting
|
||||
the background without flicker. For values that changes on screen it is
|
||||
better to use Fonts 1- 8 which are encoded specifically for rapid
|
||||
drawing with background.
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
###### TO SELECT YOUR DISPLAY TYPE, PINS USED AND ENABLE FONTS ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
// Note the the tilda symbol ~ does not exist in some fonts at the moment
|
||||
#define TEXT "abc MWy 123 |" // Text that will be printed on screen in any font
|
||||
|
||||
#include "SPI.h"
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
// Stock font and GFXFF reference handle
|
||||
#define GFXFF 1
|
||||
#define FF18 &FreeSans12pt7b
|
||||
|
||||
// Custom are fonts added to library "TFT_eSPI\Fonts\Custom" folder
|
||||
// a #include must also be added to the "User_Custom_Fonts.h" file
|
||||
// in the "TFT_eSPI\User_Setups" folder. See example entries.
|
||||
#define CF_OL24 &Orbitron_Light_24
|
||||
#define CF_OL32 &Orbitron_Light_32
|
||||
#define CF_RT24 &Roboto_Thin_24
|
||||
#define CF_S24 &Satisfy_24
|
||||
#define CF_Y32 &Yellowtail_32
|
||||
|
||||
|
||||
// Use hardware SPI
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
|
||||
void setup(void) {
|
||||
|
||||
Serial.begin(250000);
|
||||
|
||||
tft.begin();
|
||||
|
||||
tft.setRotation(1);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
// Show custom fonts
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
// Where font sizes increase the screen is not cleared as the larger fonts overwrite
|
||||
// the smaller one with the background colour.
|
||||
|
||||
// We can set the text datum to be Top, Middle, Bottom vertically and Left, Centre
|
||||
// and Right horizontally. These are the text datums that can be used:
|
||||
// TL_DATUM = Top left (default)
|
||||
// TC_DATUM = Top centre
|
||||
// TR_DATUM = Top right
|
||||
// ML_DATUM = Middle left
|
||||
// MC_DATUM = Middle centre <<< This is used below
|
||||
// MR_DATUM = Middle right
|
||||
// BL_DATUM = Bottom left
|
||||
// BC_DATUM = Bottom centre
|
||||
// BR_DATUM = Bottom right
|
||||
// L_BASELINE = Left character baseline (Line the 'A' character would sit on)
|
||||
// C_BASELINE = Centre character baseline
|
||||
// R_BASELINE = Right character baseline
|
||||
|
||||
//Serial.println();
|
||||
|
||||
// Set text datum to middle centre (MC_DATUM)
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
|
||||
// Set text colour to white with black background
|
||||
// Unlike the stock Adafruit_GFX library, the TFT_eSPI library DOES draw the background
|
||||
// for the custom and Free Fonts
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
tft.fillScreen(TFT_MAGENTA); // Clear screen
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString("Yellowtail 32", 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(CF_Y32); // Select the font
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);// Print the string name of the font
|
||||
delay(2000);
|
||||
|
||||
tft.fillScreen(TFT_BLUE); // Clear screen
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString("Satisfy 24", 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(CF_S24); // Select the font
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font
|
||||
delay(2000);
|
||||
|
||||
tft.fillScreen(TFT_RED); // Clear screen
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString("Roboto 24", 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(CF_RT24); // Select the font
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font
|
||||
delay(2000);
|
||||
|
||||
tft.fillScreen(TFT_DARKGREY); // Clear screen
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString("Orbitron 24", 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(CF_OL24); // Select the font
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font
|
||||
delay(2000);
|
||||
|
||||
// Here we do not clear the screen and rely on the new text over-writing the old
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString("Orbitron 32", 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(CF_OL32); // Select the font
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font
|
||||
delay(2000);
|
||||
|
||||
// Here we use text background padding to over-write the old text
|
||||
tft.fillScreen(TFT_YELLOW); // Clear screen
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
// Here we use text background padding to over-write the old text
|
||||
tft.setTextPadding(tft.width() - 20); // Blanked area will be width of screen minus 20 pixels
|
||||
tft.setFreeFont(FF18); // Select the font
|
||||
tft.drawString("Orbitron 32 with padding", 160, 60, GFXFF);// Print the string name of the font
|
||||
tft.setFreeFont(CF_OL32); // Select the font
|
||||
tft.drawString(TEXT, 160, 120, GFXFF);// Print the test text in the custom font
|
||||
delay(2000);
|
||||
|
||||
// Use 80 pixel wide padding so old numbers over-write old ones
|
||||
// One of the problrms with proportionally spaced numbers is that they jiggle position
|
||||
tft.setTextPadding(80);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
tft.setFreeFont(CF_OL32);
|
||||
for( int i = 100; i > 0; i--)
|
||||
{
|
||||
tft.drawNumber( i, 160, 200);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// Reset text padding to zero (default)
|
||||
tft.setTextPadding(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Ellipse drawing example
|
||||
|
||||
This sketch does not use any fonts.
|
||||
*/
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
|
||||
tft.setRotation(1);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
// Draw some random ellipses
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
int rx = random(60);
|
||||
int ry = random(60);
|
||||
int x = rx + random(320 - rx - rx);
|
||||
int y = ry + random(240 - ry - ry);
|
||||
tft.fillEllipse(x, y, rx, ry, random(0xFFFF));
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
int rx = random(60);
|
||||
int ry = random(60);
|
||||
int x = rx + random(320 - rx - rx);
|
||||
int y = ry + random(240 - ry - ry);
|
||||
tft.drawEllipse(x, y, rx, ry, random(0xFFFF));
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
// This sketch tests a fillArc function that has been adapted to permit the drawing of spirals
|
||||
|
||||
// Sketch also includes (but does not use) a function to change the brightness of a colour
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define DEG2RAD 0.0174532925
|
||||
|
||||
int segment = 0;
|
||||
unsigned int col = 0;
|
||||
int delta = -1;
|
||||
|
||||
byte red = 31; // Red is the top 5 bits of a 16 bit colour value
|
||||
byte green = 0;// Green is the middle 6 bits
|
||||
byte blue = 0; // Blue is the bottom 5 bits
|
||||
byte state = 0;
|
||||
|
||||
void setup(void) {
|
||||
tft.begin();
|
||||
|
||||
tft.setRotation(1);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
fillArc(160, 120, segment*6, 1, 120-segment/4, 120-segment/4, 3, rainbow(col));
|
||||
|
||||
segment+=delta;
|
||||
col+=1;
|
||||
if (col>191) col = 0;
|
||||
if (segment <0) delta = 1;
|
||||
if (segment >298) delta = -1; // ~5 turns in the spiral (300*6 degrees)
|
||||
//delay(5); // Slow drawing down
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Draw an arc with a defined thickness (modified to aid drawing spirals)
|
||||
// #########################################################################
|
||||
|
||||
// x,y == coords of centre of arc
|
||||
// start_angle = 0 - 359
|
||||
// seg_count = number of 3 degree segments to draw (120 => 360 degree arc)
|
||||
// rx = x axis radius
|
||||
// yx = y axis radius
|
||||
// w = width (thickness) of arc in pixels
|
||||
// colour = 16 bit colour value
|
||||
// Note if rx and ry are the same an arc of a circle is drawn
|
||||
|
||||
void fillArc(int x, int y, int start_angle, int seg_count, int rx, int ry, int w, unsigned int colour)
|
||||
{
|
||||
|
||||
// Make the segment size 7 degrees to prevent gaps when drawing spirals
|
||||
byte seg = 7; // Angle a single segment subtends (made more than 6 deg. for spiral drawing)
|
||||
byte inc = 6; // Draw segments every 6 degrees
|
||||
|
||||
// Draw colour blocks every inc degrees
|
||||
for (int i = start_angle; i < start_angle + seg * seg_count; i += inc) {
|
||||
// Calculate pair of coordinates for segment start
|
||||
float sx = cos((i - 90) * DEG2RAD);
|
||||
float sy = sin((i - 90) * DEG2RAD);
|
||||
uint16_t x0 = sx * (rx - w) + x;
|
||||
uint16_t y0 = sy * (ry - w) + y;
|
||||
uint16_t x1 = sx * rx + x;
|
||||
uint16_t y1 = sy * ry + y;
|
||||
|
||||
// Calculate pair of coordinates for segment end
|
||||
float sx2 = cos((i + seg - 90) * DEG2RAD);
|
||||
float sy2 = sin((i + seg - 90) * DEG2RAD);
|
||||
int x2 = sx2 * (rx - w) + x;
|
||||
int y2 = sy2 * (ry - w) + y;
|
||||
int x3 = sx2 * rx + x;
|
||||
int y3 = sy2 * ry + y;
|
||||
|
||||
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
|
||||
}
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Return a 16 bit colour with brightness 0 - 100%
|
||||
// #########################################################################
|
||||
unsigned int brightness(unsigned int colour, int brightness)
|
||||
{
|
||||
byte red = colour >> 11;
|
||||
byte green = (colour & 0x7E0) >> 5;
|
||||
byte blue = colour & 0x1F;
|
||||
|
||||
blue = (blue * brightness)/100;
|
||||
green = (green * brightness)/100;
|
||||
red = (red * brightness)/100;
|
||||
|
||||
return (red << 11) + (green << 5) + blue;
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Return a 16 bit rainbow colour
|
||||
// #########################################################################
|
||||
unsigned int rainbow(byte value)
|
||||
{
|
||||
// Value is expected to be in range 0-127
|
||||
// The value is converted to a spectrum colour from 0 = blue through to 127 = red
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
green ++;
|
||||
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 --;
|
||||
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;
|
||||
}
|
||||
return red << 11 | green << 5 | blue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
Tests the updated floating point plot function
|
||||
The datum is set to the centre of the 320 x 240 screen
|
||||
so numbers are printed the middle.
|
||||
|
||||
The last test shows the datum point as a red dot.
|
||||
|
||||
Normally strings are printed relative to the top left corner but this can be
|
||||
changed with the setTextDatum() function. The library has #defines for:
|
||||
|
||||
TL_DATUM 0 //Top left
|
||||
TC_DATUM 1 //Top centre
|
||||
TR_DATUM 2 //Top right
|
||||
ML_DATUM 3 //Middle left
|
||||
MC_DATUM 4 //Middle centre
|
||||
MR_DATUM 5 //Middle right
|
||||
BL_DATUM 6 //Bottom left
|
||||
BC_DATUM 7 //Bottom centre
|
||||
BR_DATUM 8 //Bottom right
|
||||
|
||||
|
||||
Needs fonts 2 and 6
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
unsigned long drawTime = 0;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
char tmp[12];
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
// Datum is middle centre
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
|
||||
// Test floating point drawing function:
|
||||
// drawFloat(value, precision, x, y, font);
|
||||
|
||||
float test = 67.125;
|
||||
tft.drawFloat(test, 4, 160, 120, 6);
|
||||
tft.drawString(dtostrf(test,4,4,tmp), 100, 200, 6);
|
||||
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
test = -0.555555;
|
||||
tft.drawFloat(test, 3, 160, 120, 6);
|
||||
tft.drawString(dtostrf(test,2,2,tmp), 100, 200, 6);
|
||||
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
test = 0.123;
|
||||
tft.drawFloat(test, 4, 160, 120, 6);
|
||||
|
||||
tft.drawString(dtostrf(test,4,4,tmp), 100, 200, 6);
|
||||
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
// This does not work at the moment....
|
||||
test = 9999999;
|
||||
tft.drawFloat(test, 0, 160, 120, 6);
|
||||
tft.drawString(dtostrf(test,4,4,tmp), 100, 200, 6);
|
||||
delay(1000);
|
||||
|
||||
//Plot the datum for the last number
|
||||
tft.fillCircle(160,120,5,TFT_RED);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawString("X", 160, 120, 2);
|
||||
|
||||
delay(4000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// Mandlebrot
|
||||
|
||||
// This will run quite slowly due to the large number of floating point calculations per pixel
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define TFT_GREY 0x7BEF
|
||||
|
||||
unsigned long runTime = 0;
|
||||
|
||||
float sx = 0, sy = 0;
|
||||
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(250000);
|
||||
//randomSeed(analogRead(A0));
|
||||
Serial.println();
|
||||
// Setup the LCD
|
||||
tft.init();
|
||||
tft.setRotation(3);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
runTime = millis();
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.startWrite();
|
||||
for (int px = 1; px < 320; px++)
|
||||
{
|
||||
for (int py = 0; py < 240; py++)
|
||||
{
|
||||
float x0 = (map(px, 0, 320, -250000/2, -242500/2)) / 100000.0; //scaled x coordinate of pixel (scaled to lie in the Mandelbrot X scale (-2.5, 1))
|
||||
float yy0 = (map(py, 0, 240, -75000/4, -61000/4)) / 100000.0; //scaled y coordinate of pixel (scaled to lie in the Mandelbrot Y scale (-1, 1))
|
||||
float xx = 0.0;
|
||||
float yy = 0.0;
|
||||
int iteration = 0;
|
||||
int max_iteration = 128;
|
||||
while ( ((xx * xx + yy * yy) < 4) && (iteration < max_iteration) )
|
||||
{
|
||||
float xtemp = xx * xx - yy * yy + x0;
|
||||
yy = 2 * xx * yy + yy0;
|
||||
xx = xtemp;
|
||||
iteration++;
|
||||
}
|
||||
int color = rainbow((3*iteration+64)%128);
|
||||
yield();tft.drawPixel(px, py, color);
|
||||
}
|
||||
}
|
||||
tft.endWrite();
|
||||
|
||||
Serial.println(millis()-runTime);
|
||||
while(1) yield();
|
||||
}
|
||||
|
||||
unsigned int rainbow(int value)
|
||||
{
|
||||
// Value is expected to be in range 0-127
|
||||
// The value is converted to a spectrum colour from 0 = blue through to red = blue
|
||||
|
||||
byte red = 0; // Red is the top 5 bits of a 16 bit colour value
|
||||
byte green = 0;// Green is the middle 6 bits
|
||||
byte blue = 0; // Blue is the bottom 5 bits
|
||||
|
||||
byte quadrant = value / 32;
|
||||
|
||||
if (quadrant == 0) {
|
||||
blue = 31;
|
||||
green = 2 * (value % 32);
|
||||
red = 0;
|
||||
}
|
||||
if (quadrant == 1) {
|
||||
blue = 31 - (value % 32);
|
||||
green = 63;
|
||||
red = 0;
|
||||
}
|
||||
if (quadrant == 2) {
|
||||
blue = 0;
|
||||
green = 63;
|
||||
red = value % 32;
|
||||
}
|
||||
if (quadrant == 3) {
|
||||
blue = 0;
|
||||
green = 63 - 2 * (value % 32);
|
||||
red = 31;
|
||||
}
|
||||
return (red << 11) + (green << 5) + blue;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
// A fun MATRIX-like screen demo of scrolling
|
||||
// Screen will flicker initially until fully drawn
|
||||
// then scroll smoothly
|
||||
|
||||
// Needs GLCD font
|
||||
|
||||
/*
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define TEXT_HEIGHT 8 // Height of text to be printed and scrolled
|
||||
#define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen)
|
||||
#define TOP_FIXED_AREA 0 // Number of lines in top fixed area (lines counted from top of screen)
|
||||
|
||||
uint16_t yStart = TOP_FIXED_AREA;
|
||||
uint16_t yArea = 320 - TOP_FIXED_AREA - BOT_FIXED_AREA;
|
||||
uint16_t yDraw = 320 - BOT_FIXED_AREA - TEXT_HEIGHT;
|
||||
byte pos[42];
|
||||
uint16_t xPos = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
randomSeed(analogRead(A0));
|
||||
tft.init();
|
||||
tft.setRotation(0);
|
||||
tft.fillScreen(ILI9341_BLACK);
|
||||
setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
// First fill the screen with random streaks of characters
|
||||
for (int j = 0; j < 600; j += TEXT_HEIGHT) {
|
||||
for (int i = 0; i < 40; i++) {
|
||||
if (pos[i] > 20) pos[i] -= 3; // Rapid fade initially brightness values
|
||||
if (pos[i] > 0) pos[i] -= 1; // Slow fade later
|
||||
if ((random(20) == 1) && (j<400)) pos[i] = 63; // ~1 in 20 probability of a new character
|
||||
tft.setTextColor(pos[i] << 5, ILI9341_BLACK); // Set the green character brightness
|
||||
if (pos[i] == 63) tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK); // Draw white character
|
||||
xPos += tft.drawChar(random(32, 128), xPos, yDraw, 1); // Draw the character
|
||||
}
|
||||
yDraw = scroll_slow(TEXT_HEIGHT, 14); // Scroll, 14ms per pixel line
|
||||
xPos = 0;
|
||||
}
|
||||
|
||||
//tft.setRotation(2);
|
||||
//tft.setTextColor(63 << 5, ILI9341_BLACK);
|
||||
//tft.drawCentreString("MATRIX",120,60,4);
|
||||
//tft.setRotation(0);
|
||||
|
||||
// Now scroll smoothly forever
|
||||
while (1) {yield(); yDraw = scroll_slow(320,5); }// Scroll 320 lines, 5ms per line
|
||||
|
||||
}
|
||||
|
||||
void setupScrollArea(uint16_t TFA, uint16_t BFA) {
|
||||
tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition
|
||||
tft.writedata(TFA >> 8);
|
||||
tft.writedata(TFA);
|
||||
tft.writedata((320 - TFA - BFA) >> 8);
|
||||
tft.writedata(320 - TFA - BFA);
|
||||
tft.writedata(BFA >> 8);
|
||||
tft.writedata(BFA);
|
||||
}
|
||||
|
||||
int scroll_slow(int lines, int wait) {
|
||||
int yTemp = yStart;
|
||||
for (int i = 0; i < lines; i++) {
|
||||
yStart++;
|
||||
if (yStart == 320 - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA;
|
||||
scrollAddress(yStart);
|
||||
delay(wait);
|
||||
}
|
||||
return yTemp;
|
||||
}
|
||||
|
||||
void scrollAddress(uint16_t VSP) {
|
||||
tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling start address
|
||||
tft.writedata(VSP >> 8);
|
||||
tft.writedata(VSP);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
An example analogue meter using a ILI9341 TFT LCD screen
|
||||
|
||||
Needs Font 2 (also Font 4 if using large scale label)
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
|
||||
Updated by Bodmer for variable meter size
|
||||
*/
|
||||
|
||||
// Define meter size as 1 for tft.rotation(0) or 1.3333 for tft.rotation(1)
|
||||
#define M_SIZE 1.3333
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define TFT_GREY 0x5AEB
|
||||
|
||||
float ltx = 0; // Saved x coord of bottom of needle
|
||||
uint16_t osx = M_SIZE*120, osy = M_SIZE*120; // Saved x & y coords
|
||||
uint32_t updateTime = 0; // time for next update
|
||||
|
||||
int old_analog = -999; // Value last displayed
|
||||
|
||||
int value[6] = {0, 0, 0, 0, 0, 0};
|
||||
int old_value[6] = { -1, -1, -1, -1, -1, -1};
|
||||
int d = 0;
|
||||
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
Serial.begin(57600); // For debug
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
analogMeter(); // Draw analogue meter
|
||||
|
||||
updateTime = millis(); // Next update time
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (updateTime <= millis()) {
|
||||
updateTime = millis() + 35; // Update emter every 35 milliseconds
|
||||
|
||||
// Create a Sine wave for testing
|
||||
d += 4; if (d >= 360) d = 0;
|
||||
value[0] = 50 + 50 * sin((d + 0) * 0.0174532925);
|
||||
|
||||
plotNeedle(value[0], 0); // It takes between 2 and 12ms to replot the needle with zero delay
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #########################################################################
|
||||
// Draw the analogue meter on the screen
|
||||
// #########################################################################
|
||||
void analogMeter()
|
||||
{
|
||||
|
||||
// Meter outline
|
||||
tft.fillRect(0, 0, M_SIZE*239, M_SIZE*126, TFT_GREY);
|
||||
tft.fillRect(5, 3, M_SIZE*230, M_SIZE*119, TFT_WHITE);
|
||||
|
||||
tft.setTextColor(TFT_BLACK); // Text colour
|
||||
|
||||
// Draw ticks every 5 degrees from -50 to +50 degrees (100 deg. FSD swing)
|
||||
for (int i = -50; i < 51; i += 5) {
|
||||
// Long scale tick length
|
||||
int tl = 15;
|
||||
|
||||
// Coodinates of tick to draw
|
||||
float sx = cos((i - 90) * 0.0174532925);
|
||||
float sy = sin((i - 90) * 0.0174532925);
|
||||
uint16_t x0 = sx * (M_SIZE*100 + tl) + M_SIZE*120;
|
||||
uint16_t y0 = sy * (M_SIZE*100 + tl) + M_SIZE*140;
|
||||
uint16_t x1 = sx * M_SIZE*100 + M_SIZE*120;
|
||||
uint16_t y1 = sy * M_SIZE*100 + M_SIZE*140;
|
||||
|
||||
// Coordinates of next tick for zone fill
|
||||
float sx2 = cos((i + 5 - 90) * 0.0174532925);
|
||||
float sy2 = sin((i + 5 - 90) * 0.0174532925);
|
||||
int x2 = sx2 * (M_SIZE*100 + tl) + M_SIZE*120;
|
||||
int y2 = sy2 * (M_SIZE*100 + tl) + M_SIZE*140;
|
||||
int x3 = sx2 * M_SIZE*100 + M_SIZE*120;
|
||||
int y3 = sy2 * M_SIZE*100 + M_SIZE*140;
|
||||
|
||||
// Yellow zone limits
|
||||
//if (i >= -50 && i < 0) {
|
||||
// tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW);
|
||||
// tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW);
|
||||
//}
|
||||
|
||||
// Green zone limits
|
||||
if (i >= 0 && i < 25) {
|
||||
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_GREEN);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_GREEN);
|
||||
}
|
||||
|
||||
// Orange zone limits
|
||||
if (i >= 25 && i < 50) {
|
||||
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_ORANGE);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_ORANGE);
|
||||
}
|
||||
|
||||
// Short scale tick length
|
||||
if (i % 25 != 0) tl = 8;
|
||||
|
||||
// Recalculate coords incase tick lenght changed
|
||||
x0 = sx * (M_SIZE*100 + tl) + M_SIZE*120;
|
||||
y0 = sy * (M_SIZE*100 + tl) + M_SIZE*140;
|
||||
x1 = sx * M_SIZE*100 + M_SIZE*120;
|
||||
y1 = sy * M_SIZE*100 + M_SIZE*140;
|
||||
|
||||
// Draw tick
|
||||
tft.drawLine(x0, y0, x1, y1, TFT_BLACK);
|
||||
|
||||
// Check if labels should be drawn, with position tweaks
|
||||
if (i % 25 == 0) {
|
||||
// Calculate label positions
|
||||
x0 = sx * (M_SIZE*100 + tl + 10) + M_SIZE*120;
|
||||
y0 = sy * (M_SIZE*100 + tl + 10) + M_SIZE*140;
|
||||
switch (i / 25) {
|
||||
case -2: tft.drawCentreString("0", x0, y0 - 12, 2); break;
|
||||
case -1: tft.drawCentreString("25", x0, y0 - 9, 2); break;
|
||||
case 0: tft.drawCentreString("50", x0, y0 - 7, 2); break;
|
||||
case 1: tft.drawCentreString("75", x0, y0 - 9, 2); break;
|
||||
case 2: tft.drawCentreString("100", x0, y0 - 12, 2); break;
|
||||
}
|
||||
}
|
||||
|
||||
// Now draw the arc of the scale
|
||||
sx = cos((i + 5 - 90) * 0.0174532925);
|
||||
sy = sin((i + 5 - 90) * 0.0174532925);
|
||||
x0 = sx * M_SIZE*100 + M_SIZE*120;
|
||||
y0 = sy * M_SIZE*100 + M_SIZE*140;
|
||||
// Draw scale arc, don't draw the last part
|
||||
if (i < 50) tft.drawLine(x0, y0, x1, y1, TFT_BLACK);
|
||||
}
|
||||
|
||||
tft.drawString("%RH", M_SIZE*(5 + 230 - 40), M_SIZE*(119 - 20), 2); // Units at bottom right
|
||||
tft.drawCentreString("%RH", M_SIZE*120, M_SIZE*70, 4); // Comment out to avoid font 4
|
||||
tft.drawRect(5, 3, M_SIZE*230, M_SIZE*119, TFT_BLACK); // Draw bezel line
|
||||
|
||||
plotNeedle(0, 0); // Put meter needle at 0
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Update needle position
|
||||
// This function is blocking while needle moves, time depends on ms_delay
|
||||
// 10ms minimises needle flicker if text is drawn within needle sweep area
|
||||
// Smaller values OK if text not in sweep area, zero for instant movement but
|
||||
// does not look realistic... (note: 100 increments for full scale deflection)
|
||||
// #########################################################################
|
||||
void plotNeedle(int value, byte ms_delay)
|
||||
{
|
||||
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
||||
char buf[8]; dtostrf(value, 4, 0, buf);
|
||||
tft.drawRightString(buf, M_SIZE*40, M_SIZE*(119 - 20), 2);
|
||||
|
||||
if (value < -10) value = -10; // Limit value to emulate needle end stops
|
||||
if (value > 110) value = 110;
|
||||
|
||||
// Move the needle until new value reached
|
||||
while (!(value == old_analog)) {
|
||||
if (old_analog < value) old_analog++;
|
||||
else old_analog--;
|
||||
|
||||
if (ms_delay == 0) old_analog = value; // Update immediately if delay is 0
|
||||
|
||||
float sdeg = map(old_analog, -10, 110, -150, -30); // Map value to angle
|
||||
// Calcualte tip of needle coords
|
||||
float sx = cos(sdeg * 0.0174532925);
|
||||
float sy = sin(sdeg * 0.0174532925);
|
||||
|
||||
// Calculate x delta of needle start (does not start at pivot point)
|
||||
float tx = tan((sdeg + 90) * 0.0174532925);
|
||||
|
||||
// Erase old needle image
|
||||
tft.drawLine(M_SIZE*(120 + 20 * ltx - 1), M_SIZE*(140 - 20), osx - 1, osy, TFT_WHITE);
|
||||
tft.drawLine(M_SIZE*(120 + 20 * ltx), M_SIZE*(140 - 20), osx, osy, TFT_WHITE);
|
||||
tft.drawLine(M_SIZE*(120 + 20 * ltx + 1), M_SIZE*(140 - 20), osx + 1, osy, TFT_WHITE);
|
||||
|
||||
// Re-plot text under needle
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawCentreString("%RH", M_SIZE*120, M_SIZE*70, 4); // // Comment out to avoid font 4
|
||||
|
||||
// Store new needle end coords for next erase
|
||||
ltx = tx;
|
||||
osx = M_SIZE*(sx * 98 + 120);
|
||||
osy = M_SIZE*(sy * 98 + 140);
|
||||
|
||||
// Draw the needle in the new postion, magenta makes needle a bit bolder
|
||||
// draws 3 lines to thicken needle
|
||||
tft.drawLine(M_SIZE*(120 + 20 * ltx - 1), M_SIZE*(140 - 20), osx - 1, osy, TFT_RED);
|
||||
tft.drawLine(M_SIZE*(120 + 20 * ltx), M_SIZE*(140 - 20), osx, osy, TFT_MAGENTA);
|
||||
tft.drawLine(M_SIZE*(120 + 20 * ltx + 1), M_SIZE*(140 - 20), osx + 1, osy, TFT_RED);
|
||||
|
||||
// Slow needle down slightly as it approaches new postion
|
||||
if (abs(old_analog - value) < 10) ms_delay += ms_delay / 5;
|
||||
|
||||
// Wait before next update
|
||||
delay(ms_delay);
|
||||
}
|
||||
}
|
||||
|
||||
297
libraries/TFT_eSPI/examples/320 x 240/TFT_Meters/TFT_Meters.ino
Normal file
297
libraries/TFT_eSPI/examples/320 x 240/TFT_Meters/TFT_Meters.ino
Normal file
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
Example animated analogue meters using a ILI9341 TFT LCD screen
|
||||
|
||||
Needs Font 2 (also Font 4 if using large scale label)
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define TFT_GREY 0x5AEB
|
||||
|
||||
#define LOOP_PERIOD 35 // Display updates every 35 ms
|
||||
|
||||
float ltx = 0; // Saved x coord of bottom of needle
|
||||
uint16_t osx = 120, osy = 120; // Saved x & y coords
|
||||
uint32_t updateTime = 0; // time for next update
|
||||
|
||||
int old_analog = -999; // Value last displayed
|
||||
int old_digital = -999; // Value last displayed
|
||||
|
||||
int value[6] = {0, 0, 0, 0, 0, 0};
|
||||
int old_value[6] = { -1, -1, -1, -1, -1, -1};
|
||||
int d = 0;
|
||||
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(0);
|
||||
Serial.begin(57600); // For debug
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
analogMeter(); // Draw analogue meter
|
||||
|
||||
// Draw 6 linear meters
|
||||
byte d = 40;
|
||||
plotLinear("A0", 0, 160);
|
||||
plotLinear("A1", 1 * d, 160);
|
||||
plotLinear("A2", 2 * d, 160);
|
||||
plotLinear("A3", 3 * d, 160);
|
||||
plotLinear("A4", 4 * d, 160);
|
||||
plotLinear("A5", 5 * d, 160);
|
||||
|
||||
updateTime = millis(); // Next update time
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
if (updateTime <= millis()) {
|
||||
updateTime = millis() + LOOP_PERIOD;
|
||||
|
||||
d += 4; if (d >= 360) d = 0;
|
||||
|
||||
//value[0] = map(analogRead(A0), 0, 1023, 0, 100); // Test with value form Analogue 0
|
||||
|
||||
// Create a Sine wave for testing
|
||||
value[0] = 50 + 50 * sin((d + 0) * 0.0174532925);
|
||||
value[1] = 50 + 50 * sin((d + 60) * 0.0174532925);
|
||||
value[2] = 50 + 50 * sin((d + 120) * 0.0174532925);
|
||||
value[3] = 50 + 50 * sin((d + 180) * 0.0174532925);
|
||||
value[4] = 50 + 50 * sin((d + 240) * 0.0174532925);
|
||||
value[5] = 50 + 50 * sin((d + 300) * 0.0174532925);
|
||||
|
||||
//unsigned long t = millis();
|
||||
|
||||
plotPointer();
|
||||
|
||||
plotNeedle(value[0], 0);
|
||||
|
||||
//Serial.println(millis()-t); // Print time taken for meter update
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #########################################################################
|
||||
// Draw the analogue meter on the screen
|
||||
// #########################################################################
|
||||
void analogMeter()
|
||||
{
|
||||
// Meter outline
|
||||
tft.fillRect(0, 0, 239, 126, TFT_GREY);
|
||||
tft.fillRect(5, 3, 230, 119, TFT_WHITE);
|
||||
|
||||
tft.setTextColor(TFT_BLACK); // Text colour
|
||||
|
||||
// Draw ticks every 5 degrees from -50 to +50 degrees (100 deg. FSD swing)
|
||||
for (int i = -50; i < 51; i += 5) {
|
||||
// Long scale tick length
|
||||
int tl = 15;
|
||||
|
||||
// Coodinates of tick to draw
|
||||
float sx = cos((i - 90) * 0.0174532925);
|
||||
float sy = sin((i - 90) * 0.0174532925);
|
||||
uint16_t x0 = sx * (100 + tl) + 120;
|
||||
uint16_t y0 = sy * (100 + tl) + 140;
|
||||
uint16_t x1 = sx * 100 + 120;
|
||||
uint16_t y1 = sy * 100 + 140;
|
||||
|
||||
// Coordinates of next tick for zone fill
|
||||
float sx2 = cos((i + 5 - 90) * 0.0174532925);
|
||||
float sy2 = sin((i + 5 - 90) * 0.0174532925);
|
||||
int x2 = sx2 * (100 + tl) + 120;
|
||||
int y2 = sy2 * (100 + tl) + 140;
|
||||
int x3 = sx2 * 100 + 120;
|
||||
int y3 = sy2 * 100 + 140;
|
||||
|
||||
// Yellow zone limits
|
||||
//if (i >= -50 && i < 0) {
|
||||
// tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_YELLOW);
|
||||
// tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_YELLOW);
|
||||
//}
|
||||
|
||||
// Green zone limits
|
||||
if (i >= 0 && i < 25) {
|
||||
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_GREEN);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_GREEN);
|
||||
}
|
||||
|
||||
// Orange zone limits
|
||||
if (i >= 25 && i < 50) {
|
||||
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_ORANGE);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_ORANGE);
|
||||
}
|
||||
|
||||
// Short scale tick length
|
||||
if (i % 25 != 0) tl = 8;
|
||||
|
||||
// Recalculate coords incase tick lenght changed
|
||||
x0 = sx * (100 + tl) + 120;
|
||||
y0 = sy * (100 + tl) + 140;
|
||||
x1 = sx * 100 + 120;
|
||||
y1 = sy * 100 + 140;
|
||||
|
||||
// Draw tick
|
||||
tft.drawLine(x0, y0, x1, y1, TFT_BLACK);
|
||||
|
||||
// Check if labels should be drawn, with position tweaks
|
||||
if (i % 25 == 0) {
|
||||
// Calculate label positions
|
||||
x0 = sx * (100 + tl + 10) + 120;
|
||||
y0 = sy * (100 + tl + 10) + 140;
|
||||
switch (i / 25) {
|
||||
case -2: tft.drawCentreString("0", x0, y0 - 12, 2); break;
|
||||
case -1: tft.drawCentreString("25", x0, y0 - 9, 2); break;
|
||||
case 0: tft.drawCentreString("50", x0, y0 - 6, 2); break;
|
||||
case 1: tft.drawCentreString("75", x0, y0 - 9, 2); break;
|
||||
case 2: tft.drawCentreString("100", x0, y0 - 12, 2); break;
|
||||
}
|
||||
}
|
||||
|
||||
// Now draw the arc of the scale
|
||||
sx = cos((i + 5 - 90) * 0.0174532925);
|
||||
sy = sin((i + 5 - 90) * 0.0174532925);
|
||||
x0 = sx * 100 + 120;
|
||||
y0 = sy * 100 + 140;
|
||||
// Draw scale arc, don't draw the last part
|
||||
if (i < 50) tft.drawLine(x0, y0, x1, y1, TFT_BLACK);
|
||||
}
|
||||
|
||||
tft.drawString("%RH", 5 + 230 - 40, 119 - 20, 2); // Units at bottom right
|
||||
tft.drawCentreString("%RH", 120, 70, 4); // Comment out to avoid font 4
|
||||
tft.drawRect(5, 3, 230, 119, TFT_BLACK); // Draw bezel line
|
||||
|
||||
plotNeedle(0, 0); // Put meter needle at 0
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Update needle position
|
||||
// This function is blocking while needle moves, time depends on ms_delay
|
||||
// 10ms minimises needle flicker if text is drawn within needle sweep area
|
||||
// Smaller values OK if text not in sweep area, zero for instant movement but
|
||||
// does not look realistic... (note: 100 increments for full scale deflection)
|
||||
// #########################################################################
|
||||
void plotNeedle(int value, byte ms_delay)
|
||||
{
|
||||
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
||||
char buf[8]; dtostrf(value, 4, 0, buf);
|
||||
tft.drawRightString(buf, 40, 119 - 20, 2);
|
||||
|
||||
if (value < -10) value = -10; // Limit value to emulate needle end stops
|
||||
if (value > 110) value = 110;
|
||||
|
||||
// Move the needle util new value reached
|
||||
while (!(value == old_analog)) {
|
||||
if (old_analog < value) old_analog++;
|
||||
else old_analog--;
|
||||
|
||||
if (ms_delay == 0) old_analog = value; // Update immediately id delay is 0
|
||||
|
||||
float sdeg = map(old_analog, -10, 110, -150, -30); // Map value to angle
|
||||
// Calcualte tip of needle coords
|
||||
float sx = cos(sdeg * 0.0174532925);
|
||||
float sy = sin(sdeg * 0.0174532925);
|
||||
|
||||
// Calculate x delta of needle start (does not start at pivot point)
|
||||
float tx = tan((sdeg + 90) * 0.0174532925);
|
||||
|
||||
// Erase old needle image
|
||||
tft.drawLine(120 + 20 * ltx - 1, 140 - 20, osx - 1, osy, TFT_WHITE);
|
||||
tft.drawLine(120 + 20 * ltx, 140 - 20, osx, osy, TFT_WHITE);
|
||||
tft.drawLine(120 + 20 * ltx + 1, 140 - 20, osx + 1, osy, TFT_WHITE);
|
||||
|
||||
// Re-plot text under needle
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawCentreString("%RH", 120, 70, 4); // // Comment out to avoid font 4
|
||||
|
||||
// Store new needle end coords for next erase
|
||||
ltx = tx;
|
||||
osx = sx * 98 + 120;
|
||||
osy = sy * 98 + 140;
|
||||
|
||||
// Draw the needle in the new postion, magenta makes needle a bit bolder
|
||||
// draws 3 lines to thicken needle
|
||||
tft.drawLine(120 + 20 * ltx - 1, 140 - 20, osx - 1, osy, TFT_RED);
|
||||
tft.drawLine(120 + 20 * ltx, 140 - 20, osx, osy, TFT_MAGENTA);
|
||||
tft.drawLine(120 + 20 * ltx + 1, 140 - 20, osx + 1, osy, TFT_RED);
|
||||
|
||||
// Slow needle down slightly as it approaches new postion
|
||||
if (abs(old_analog - value) < 10) ms_delay += ms_delay / 5;
|
||||
|
||||
// Wait before next update
|
||||
delay(ms_delay);
|
||||
}
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Draw a linear meter on the screen
|
||||
// #########################################################################
|
||||
void plotLinear(char *label, int x, int y)
|
||||
{
|
||||
int w = 36;
|
||||
tft.drawRect(x, y, w, 155, TFT_GREY);
|
||||
tft.fillRect(x + 2, y + 19, w - 3, 155 - 38, TFT_WHITE);
|
||||
tft.setTextColor(TFT_CYAN, TFT_BLACK);
|
||||
tft.drawCentreString(label, x + w / 2, y + 2, 2);
|
||||
|
||||
for (int i = 0; i < 110; i += 10)
|
||||
{
|
||||
tft.drawFastHLine(x + 20, y + 27 + i, 6, TFT_BLACK);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 110; i += 50)
|
||||
{
|
||||
tft.drawFastHLine(x + 20, y + 27 + i, 9, TFT_BLACK);
|
||||
}
|
||||
|
||||
tft.fillTriangle(x + 3, y + 127, x + 3 + 16, y + 127, x + 3, y + 127 - 5, TFT_RED);
|
||||
tft.fillTriangle(x + 3, y + 127, x + 3 + 16, y + 127, x + 3, y + 127 + 5, TFT_RED);
|
||||
|
||||
tft.drawCentreString("---", x + w / 2, y + 155 - 18, 2);
|
||||
}
|
||||
|
||||
// #########################################################################
|
||||
// Adjust 6 linear meter pointer positions
|
||||
// #########################################################################
|
||||
void plotPointer(void)
|
||||
{
|
||||
int dy = 187;
|
||||
byte pw = 16;
|
||||
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
|
||||
// Move the 6 pointers one pixel towards new value
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
char buf[8]; dtostrf(value[i], 4, 0, buf);
|
||||
tft.drawRightString(buf, i * 40 + 36 - 5, 187 - 27 + 155 - 18, 2);
|
||||
|
||||
int dx = 3 + 40 * i;
|
||||
if (value[i] < 0) value[i] = 0; // Limit value to emulate needle end stops
|
||||
if (value[i] > 100) value[i] = 100;
|
||||
|
||||
while (!(value[i] == old_value[i])) {
|
||||
dy = 187 + 100 - old_value[i];
|
||||
if (old_value[i] > value[i])
|
||||
{
|
||||
tft.drawLine(dx, dy - 5, dx + pw, dy, TFT_WHITE);
|
||||
old_value[i]--;
|
||||
tft.drawLine(dx, dy + 6, dx + pw, dy + 1, TFT_RED);
|
||||
}
|
||||
else
|
||||
{
|
||||
tft.drawLine(dx, dy + 5, dx + pw, dy, TFT_WHITE);
|
||||
old_value[i]++;
|
||||
tft.drawLine(dx, dy - 6, dx + pw, dy - 1, TFT_RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// This sketch includes a function to draw circle segments
|
||||
// for pie charts in 1 degree increments
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define DEG2RAD 0.0174532925
|
||||
|
||||
byte inc = 0;
|
||||
unsigned int col = 0;
|
||||
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
tft.begin();
|
||||
|
||||
tft.setRotation(1);
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Draw 4 pie chart segments
|
||||
fillSegment(160, 120, 0, 60, 100, TFT_RED);
|
||||
fillSegment(160, 120, 60, 30, 100, TFT_GREEN);
|
||||
fillSegment(160, 120, 60 + 30, 120, 100, TFT_BLUE);
|
||||
fillSegment(160, 120, 60 + 30 + 120, 150, 100, TFT_YELLOW);
|
||||
|
||||
delay(4000);
|
||||
|
||||
// Erase old chart with 360 degree black plot
|
||||
fillSegment(160, 120, 0, 360, 100, TFT_BLACK);
|
||||
}
|
||||
|
||||
|
||||
// #########################################################################
|
||||
// Draw circle segments
|
||||
// #########################################################################
|
||||
|
||||
// x,y == coords of centre of circle
|
||||
// start_angle = 0 - 359
|
||||
// sub_angle = 0 - 360 = subtended angle
|
||||
// r = radius
|
||||
// colour = 16 bit colour value
|
||||
|
||||
int fillSegment(int x, int y, int start_angle, int sub_angle, int r, unsigned int colour)
|
||||
{
|
||||
// Calculate first pair of coordinates for segment start
|
||||
float sx = cos((start_angle - 90) * DEG2RAD);
|
||||
float sy = sin((start_angle - 90) * DEG2RAD);
|
||||
uint16_t x1 = sx * r + x;
|
||||
uint16_t y1 = sy * r + y;
|
||||
|
||||
// Draw colour blocks every inc degrees
|
||||
for (int i = start_angle; i < start_angle + sub_angle; i++) {
|
||||
|
||||
// Calculate pair of coordinates for segment end
|
||||
int x2 = cos((i + 1 - 90) * DEG2RAD) * r + x;
|
||||
int y2 = sin((i + 1 - 90) * DEG2RAD) * r + y;
|
||||
|
||||
tft.fillTriangle(x1, y1, x2, y2, x, y, colour);
|
||||
|
||||
// Copy segment end to sgement start for next segment
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #########################################################################
|
||||
// Return the 16 bit colour with brightness 0-100%
|
||||
// #########################################################################
|
||||
unsigned int brightness(unsigned int colour, int brightness)
|
||||
{
|
||||
byte red = colour >> 11;
|
||||
byte green = (colour & 0x7E0) >> 5;
|
||||
byte blue = colour & 0x1F;
|
||||
|
||||
blue = (blue * brightness)/100;
|
||||
green = (green * brightness)/100;
|
||||
red = (red * brightness)/100;
|
||||
|
||||
return (red << 11) + (green << 5) + blue;
|
||||
}
|
||||
|
||||
223
libraries/TFT_eSPI/examples/320 x 240/TFT_Pong/TFT_Pong.ino
Normal file
223
libraries/TFT_eSPI/examples/320 x 240/TFT_Pong/TFT_Pong.ino
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Pong
|
||||
* Original Code from https://github.com/rparrett/pongclock
|
||||
*
|
||||
*/
|
||||
|
||||
// Demo only - not playable
|
||||
|
||||
#define BLACK 0x0000
|
||||
#define WHITE 0xFFFF
|
||||
#define GREY 0x5AEB
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
int16_t h = 240;
|
||||
int16_t w = 320;
|
||||
|
||||
int dly = 5;
|
||||
|
||||
int16_t paddle_h = 30;
|
||||
int16_t paddle_w = 4;
|
||||
|
||||
int16_t lpaddle_x = 0;
|
||||
int16_t rpaddle_x = w - paddle_w;
|
||||
|
||||
int16_t lpaddle_y = 0;
|
||||
int16_t rpaddle_y = h - paddle_h;
|
||||
|
||||
int16_t lpaddle_d = 1;
|
||||
int16_t rpaddle_d = -1;
|
||||
|
||||
int16_t lpaddle_ball_t = w - w / 4;
|
||||
int16_t rpaddle_ball_t = w / 4;
|
||||
|
||||
int16_t target_y = 0;
|
||||
|
||||
int16_t ball_x = 2;
|
||||
int16_t ball_y = 2;
|
||||
int16_t oldball_x = 2;
|
||||
int16_t oldball_y = 2;
|
||||
|
||||
int16_t ball_dx = 1;
|
||||
int16_t ball_dy = 1;
|
||||
|
||||
int16_t ball_w = 6;
|
||||
int16_t ball_h = 6;
|
||||
|
||||
int16_t dashline_h = 4;
|
||||
int16_t dashline_w = 2;
|
||||
int16_t dashline_n = h / dashline_h;
|
||||
int16_t dashline_x = w / 2 - 1;
|
||||
int16_t dashline_y = dashline_h / 2;
|
||||
|
||||
int16_t lscore = 12;
|
||||
int16_t rscore = 4;
|
||||
|
||||
void setup(void) {
|
||||
|
||||
//randomSeed(analogRead(0)*analogRead(1));
|
||||
|
||||
tft.init();
|
||||
|
||||
tft.setRotation(1);
|
||||
|
||||
tft.fillScreen(BLACK);
|
||||
//tft.fillScreen(GREY);
|
||||
|
||||
initgame();
|
||||
|
||||
tft.setTextColor(WHITE, BLACK);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(dly);
|
||||
|
||||
lpaddle();
|
||||
rpaddle();
|
||||
|
||||
midline();
|
||||
|
||||
ball();
|
||||
}
|
||||
|
||||
void initgame() {
|
||||
lpaddle_y = random(0, h - paddle_h);
|
||||
rpaddle_y = random(0, h - paddle_h);
|
||||
|
||||
// ball is placed on the center of the left paddle
|
||||
ball_y = lpaddle_y + (paddle_h / 2);
|
||||
|
||||
calc_target_y();
|
||||
|
||||
midline();
|
||||
|
||||
tft.fillRect(0,h-26,w,239,GREY);
|
||||
|
||||
tft.setTextDatum(TC_DATUM);
|
||||
tft.setTextColor(WHITE,GREY);
|
||||
tft.drawString("TFT_eSPI example", w/2, h-26 , 4);
|
||||
}
|
||||
|
||||
void midline() {
|
||||
|
||||
// If the ball is not on the line then don't redraw the line
|
||||
if ((ball_x<dashline_x-ball_w) && (ball_x > dashline_x+dashline_w)) return;
|
||||
|
||||
tft.startWrite();
|
||||
|
||||
// Quick way to draw a dashed line
|
||||
tft.setAddrWindow(dashline_x, 0, dashline_w, h);
|
||||
|
||||
for(int16_t i = 0; i < dashline_n; i+=2) {
|
||||
tft.pushColor(WHITE, dashline_w*dashline_h); // push dash pixels
|
||||
tft.pushColor(BLACK, dashline_w*dashline_h); // push gap pixels
|
||||
}
|
||||
|
||||
tft.endWrite();
|
||||
}
|
||||
|
||||
void lpaddle() {
|
||||
|
||||
if (lpaddle_d == 1) {
|
||||
tft.fillRect(lpaddle_x, lpaddle_y, paddle_w, 1, BLACK);
|
||||
}
|
||||
else if (lpaddle_d == -1) {
|
||||
tft.fillRect(lpaddle_x, lpaddle_y + paddle_h - 1, paddle_w, 1, BLACK);
|
||||
}
|
||||
|
||||
lpaddle_y = lpaddle_y + lpaddle_d;
|
||||
|
||||
if (ball_dx == 1) lpaddle_d = 0;
|
||||
else {
|
||||
if (lpaddle_y + paddle_h / 2 == target_y) lpaddle_d = 0;
|
||||
else if (lpaddle_y + paddle_h / 2 > target_y) lpaddle_d = -1;
|
||||
else lpaddle_d = 1;
|
||||
}
|
||||
|
||||
if (lpaddle_y + paddle_h >= h && lpaddle_d == 1) lpaddle_d = 0;
|
||||
else if (lpaddle_y <= 0 && lpaddle_d == -1) lpaddle_d = 0;
|
||||
|
||||
tft.fillRect(lpaddle_x, lpaddle_y, paddle_w, paddle_h, WHITE);
|
||||
}
|
||||
|
||||
void rpaddle() {
|
||||
|
||||
if (rpaddle_d == 1) {
|
||||
tft.fillRect(rpaddle_x, rpaddle_y, paddle_w, 1, BLACK);
|
||||
}
|
||||
else if (rpaddle_d == -1) {
|
||||
tft.fillRect(rpaddle_x, rpaddle_y + paddle_h - 1, paddle_w, 1, BLACK);
|
||||
}
|
||||
|
||||
rpaddle_y = rpaddle_y + rpaddle_d;
|
||||
|
||||
if (ball_dx == -1) rpaddle_d = 0;
|
||||
else {
|
||||
if (rpaddle_y + paddle_h / 2 == target_y) rpaddle_d = 0;
|
||||
else if (rpaddle_y + paddle_h / 2 > target_y) rpaddle_d = -1;
|
||||
else rpaddle_d = 1;
|
||||
}
|
||||
|
||||
if (rpaddle_y + paddle_h >= h && rpaddle_d == 1) rpaddle_d = 0;
|
||||
else if (rpaddle_y <= 0 && rpaddle_d == -1) rpaddle_d = 0;
|
||||
|
||||
tft.fillRect(rpaddle_x, rpaddle_y, paddle_w, paddle_h, WHITE);
|
||||
}
|
||||
|
||||
void calc_target_y() {
|
||||
int16_t target_x;
|
||||
int16_t reflections;
|
||||
int16_t y;
|
||||
|
||||
if (ball_dx == 1) {
|
||||
target_x = w - ball_w;
|
||||
}
|
||||
else {
|
||||
target_x = -1 * (w - ball_w);
|
||||
}
|
||||
|
||||
y = abs(target_x * (ball_dy / ball_dx) + ball_y);
|
||||
|
||||
reflections = floor(y / h);
|
||||
|
||||
if (reflections % 2 == 0) {
|
||||
target_y = y % h;
|
||||
}
|
||||
else {
|
||||
target_y = h - (y % h);
|
||||
}
|
||||
}
|
||||
|
||||
void ball() {
|
||||
ball_x = ball_x + ball_dx;
|
||||
ball_y = ball_y + ball_dy;
|
||||
|
||||
if (ball_dx == -1 && ball_x == paddle_w && ball_y + ball_h >= lpaddle_y && ball_y <= lpaddle_y + paddle_h) {
|
||||
ball_dx = ball_dx * -1;
|
||||
dly = random(5); // change speed of ball after paddle contact
|
||||
calc_target_y();
|
||||
} else if (ball_dx == 1 && ball_x + ball_w == w - paddle_w && ball_y + ball_h >= rpaddle_y && ball_y <= rpaddle_y + paddle_h) {
|
||||
ball_dx = ball_dx * -1;
|
||||
dly = random(5); // change speed of ball after paddle contact
|
||||
calc_target_y();
|
||||
} else if ((ball_dx == 1 && ball_x >= w) || (ball_dx == -1 && ball_x + ball_w < 0)) {
|
||||
dly = 5;
|
||||
}
|
||||
|
||||
if (ball_y > h - ball_w || ball_y < 0) {
|
||||
ball_dy = ball_dy * -1;
|
||||
ball_y += ball_dy; // Keep in bounds
|
||||
}
|
||||
|
||||
//tft.fillRect(oldball_x, oldball_y, ball_w, ball_h, BLACK);
|
||||
tft.drawRect(oldball_x, oldball_y, ball_w, ball_h, BLACK); // Less TFT refresh aliasing than line above for large balls
|
||||
tft.fillRect( ball_x, ball_y, ball_w, ball_h, WHITE);
|
||||
oldball_x = ball_x;
|
||||
oldball_y = ball_y;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Test the tft.print() viz embedded tft.write() function
|
||||
|
||||
This sketch used font 2, 4, 7
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
|
||||
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
|
||||
#include <SPI.h>
|
||||
|
||||
#define TFT_GREY 0x5AEB // New colour
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke library
|
||||
|
||||
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(2);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Fill screen with grey so we can see the effect of printing with and without
|
||||
// a background colour defined
|
||||
tft.fillScreen(TFT_GREY);
|
||||
|
||||
// Set "cursor" at top left corner of display (0,0) and select font 2
|
||||
// (cursor will move to next line automatically during printing with 'tft.println'
|
||||
// or stay on the line is there is room for the text with tft.print)
|
||||
tft.setCursor(0, 0, 2);
|
||||
// Set the font colour to be white with a black background, set text size multiplier to 1
|
||||
tft.setTextColor(TFT_WHITE,TFT_BLACK); tft.setTextSize(1);
|
||||
// We can now plot text on screen using the "print" class
|
||||
tft.println("Hello World!");
|
||||
|
||||
// Set the font colour to be yellow with no background, set to font 7
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextFont(7);
|
||||
tft.println(1234.56);
|
||||
|
||||
// Set the font colour to be red with black background, set to font 4
|
||||
tft.setTextColor(TFT_RED,TFT_BLACK); tft.setTextFont(4);
|
||||
//tft.println(3735928559L, HEX); // Should print DEADBEEF
|
||||
|
||||
// Set the font colour to be green with black background, set to font 4
|
||||
tft.setTextColor(TFT_GREEN,TFT_BLACK);
|
||||
tft.setTextFont(4);
|
||||
tft.println("Groop");
|
||||
tft.println("I implore thee,");
|
||||
|
||||
// Change to font 2
|
||||
tft.setTextFont(2);
|
||||
tft.println("my foonting turlingdromes.");
|
||||
tft.println("And hooptiously drangle me");
|
||||
tft.println("with crinkly bindlewurdles,");
|
||||
// This next line is deliberately made too long for the display width to test
|
||||
// automatic text wrapping onto the next line
|
||||
tft.println("Or I will rend thee in the gobberwarts with my blurglecruncheon, see if I don't!");
|
||||
|
||||
// Test some print formatting functions
|
||||
float fnumber = 123.45;
|
||||
// Set the font colour to be blue with no background, set to font 4
|
||||
tft.setTextColor(TFT_BLUE); tft.setTextFont(4);
|
||||
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
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
An example showing rainbow colours on a 2.2" TFT LCD screen
|
||||
and to show basic examples of font use.
|
||||
|
||||
This sketch uses the GLCD, 2, 4, 6 fonts only.
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library with default width and height
|
||||
|
||||
//TFT_eSPI tft = TFT_eSPI(240, 320); // Could invoke custom library declaring width and height
|
||||
|
||||
unsigned long targetTime = 0;
|
||||
byte red = 31;
|
||||
byte green = 0;
|
||||
byte blue = 0;
|
||||
byte state = 0;
|
||||
unsigned int colour = red << 11; // Colour order is RGB 5+6+5 bits each
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
tft.init();
|
||||
tft.setRotation(2);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
targetTime = millis() + 1000;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
if (targetTime < millis()) {
|
||||
targetTime = millis() + 10000;
|
||||
|
||||
rainbow_fill(); // Fill the screen with rainbow colours
|
||||
|
||||
// The standard AdaFruit font still works as before
|
||||
tft.setTextColor(TFT_BLACK); // Background is not defined so it is transparent
|
||||
|
||||
tft.setCursor (60, 5);
|
||||
tft.setTextFont(0); // Select font 0 which is the Adafruit font
|
||||
tft.print("Original Adafruit font!");
|
||||
|
||||
//tft.drawString("Original Adafruit font!",60,5,1);
|
||||
|
||||
// The new larger fonts do not need to use the .setCursor call, coords are embedded
|
||||
tft.setTextColor(TFT_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", 120, 14, 2); // Draw text centre at position 120, 14 using font 2
|
||||
tft.drawCentreString("Font size 4", 120, 30, 4); // Draw text centre at position 120, 30 using font 4
|
||||
tft.drawCentreString("12.34", 120, 54, 6); // Draw text centre at position 120, 54 using font 6
|
||||
|
||||
tft.drawCentreString("12.34 is in font size 6", 120, 92, 2); // Draw text centre at position 120, 92 using font 2
|
||||
// Note the x position is the top 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 = 90; // x position
|
||||
int ypos = 110; // y position
|
||||
int font = 2; // font number 2
|
||||
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.setTextSize(1); // We are using a size multiplier of 1
|
||||
|
||||
tft.setTextColor(TFT_BLACK); // Set text colour to black, no background (so transparent)
|
||||
|
||||
tft.setCursor(36, 150, 4); // Set cursor to x = 36, y = 150 and use font 4
|
||||
tft.println("Transparent..."); // As we use println, the cursor moves to the next line
|
||||
|
||||
tft.setCursor(30, 175); // Set cursor to x = 30, y = 175
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set text colour to white and background to black
|
||||
tft.println("White on black");
|
||||
|
||||
tft.setTextFont(4); // Select font 4 without moving cursor
|
||||
tft.setCursor(50, 210); // Set cursor to x = 50, y = 210 without changing the font
|
||||
tft.setTextColor(TFT_WHITE);
|
||||
// By using #TFT print we can use all the formatting features like printing HEX
|
||||
tft.print(57005, HEX); // Cursor does no move to next line
|
||||
tft.println(48879, HEX); // print and move cursor to next line
|
||||
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK); // This time we will use green text on a black background
|
||||
tft.setTextFont(2); // Select font 2
|
||||
//Text will wrap to the next line if needed, by luck it breaks the lines at spaces!
|
||||
tft.println(" Ode to a Small Lump of Green Putty I Found in My Armpit One Midsummer Morning ");
|
||||
}
|
||||
}
|
||||
|
||||
// Fill screen with a rainbow pattern
|
||||
void rainbow_fill()
|
||||
{
|
||||
// The colours and state are not initialised so the start colour changes each time the funtion is called
|
||||
|
||||
for (int i = 319; i > 0; i--) {
|
||||
// Draw a vertical line 1 pixel wide in the selected colour
|
||||
tft.drawFastHLine(0, i, tft.width(), colour); // in this example tft.width() returns the pixel width of the display
|
||||
// This is a "state machine" that ramps up/down the colour brightnesses in sequence
|
||||
switch (state) {
|
||||
case 0:
|
||||
green ++;
|
||||
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 --;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
Test the library readcommand8 member function
|
||||
|
||||
This sketch reports via the Serial Monitor window
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
|
||||
#########################################################################
|
||||
|
||||
Created by Bodmer 14/1/17
|
||||
*/
|
||||
|
||||
//====================================================================================
|
||||
// Libraries
|
||||
//====================================================================================
|
||||
|
||||
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke library
|
||||
|
||||
//====================================================================================
|
||||
// Setup
|
||||
//====================================================================================
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
|
||||
tft.init();
|
||||
tft.setRotation(2);
|
||||
}
|
||||
|
||||
//====================================================================================
|
||||
// Loop
|
||||
//====================================================================================
|
||||
|
||||
void loop() {
|
||||
|
||||
tft.fillScreen(TFT_BLUE);
|
||||
tft.setCursor(0, 0, 2);
|
||||
// Set the font colour to be white with a black background
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
// We can now plot text on screen using the "print" class
|
||||
tft.println("Hello World!");
|
||||
|
||||
delay(2000);
|
||||
|
||||
// OK, now it has been shown that the display is working reset it to defaults
|
||||
// This will make the screen go "white" but we can still read registers
|
||||
|
||||
digitalWrite(TFT_RST, LOW);
|
||||
delay(10);
|
||||
digitalWrite(TFT_RST, HIGH);
|
||||
delay(10);
|
||||
|
||||
printSubset(); // Print a useful subset of the readable registers
|
||||
|
||||
readTest(); // Test 8, 16 and 32 bit reads and index on the ID register
|
||||
|
||||
//printRange32(0x00, 0xFF); // Print a range of registers (32 bits, index = 0)
|
||||
|
||||
delay(2000);
|
||||
while (1) yield();
|
||||
}
|
||||
|
||||
//====================================================================================
|
||||
// Supporting functions
|
||||
//====================================================================================
|
||||
|
||||
void readTest(void)
|
||||
{
|
||||
Serial.println(); Serial.println("Test 8, 16 and 32 bit reads and the index...");
|
||||
// Test 8, 16 and 32 bit reads and index
|
||||
// Note at index 0 the register values are typically undefined (Bxxxxxxxx)
|
||||
Serial.println(tft.readcommand8(ILI9341_RDID4, 2), HEX);
|
||||
Serial.println(tft.readcommand16(ILI9341_RDID4, 2), HEX);
|
||||
Serial.println(tft.readcommand32(ILI9341_RDID4, 0), HEX);
|
||||
}
|
||||
|
||||
//====================================================================================
|
||||
|
||||
void printRange32(uint8_t readStart, uint8_t readEnd)
|
||||
{
|
||||
Serial.print("Registers from "); Serial.print(readStart, HEX);
|
||||
Serial.print(" to "); Serial.println(readEnd, HEX);
|
||||
|
||||
for (uint8_t cmd_reg = readStart; cmd_reg < readEnd; cmd_reg++) {
|
||||
readRegister(cmd_reg, 4, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//====================================================================================
|
||||
|
||||
void printSubset(void)
|
||||
{
|
||||
Serial.println(); Serial.println();
|
||||
readRegister(ILI9341_RDDID, 3, 1);
|
||||
readRegister(ILI9341_RDDST, 4, 1);
|
||||
readRegister(ILI9341_RDMODE, 1, 1);
|
||||
readRegister(ILI9341_RDMADCTL, 1, 1);
|
||||
readRegister(ILI9341_RDPIXFMT, 1, 1);
|
||||
readRegister(ILI9341_RDSELFDIAG, 1, 1);
|
||||
readRegister(ILI9341_RAMRD, 3, 1);
|
||||
|
||||
readRegister(ILI9341_RDID1, 1, 1);
|
||||
readRegister(ILI9341_RDID2, 1, 1);
|
||||
readRegister(ILI9341_RDID3, 1, 1);
|
||||
readRegister(ILI9341_RDIDX, 1, 1); // ?
|
||||
readRegister(ILI9341_RDID4, 3, 1); // ID
|
||||
}
|
||||
|
||||
//====================================================================================
|
||||
|
||||
uint32_t readRegister(uint8_t reg, int16_t bytes, uint8_t index)
|
||||
{
|
||||
uint32_t data = 0;
|
||||
|
||||
while (bytes > 0) {
|
||||
bytes--;
|
||||
data = (data << 8) | tft.readcommand8(reg, index);
|
||||
index++;
|
||||
}
|
||||
|
||||
Serial.print("Register 0x");
|
||||
if (reg < 0x10) Serial.print("0");
|
||||
Serial.print(reg , HEX);
|
||||
|
||||
Serial.print(": 0x");
|
||||
|
||||
// Add leading zeros as needed
|
||||
uint32_t mask = 0x1 << 28;
|
||||
while (data < mask && mask > 0x1) {
|
||||
Serial.print("0");
|
||||
mask = mask >> 4;
|
||||
}
|
||||
|
||||
Serial.println(data, HEX);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
//====================================================================================
|
||||
@@ -0,0 +1,99 @@
|
||||
// Spiro
|
||||
// Rainbow patern generator
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define DEG2RAD 0.0174532925 // Convert angles in degrees to radians
|
||||
|
||||
unsigned long runTime = 0;
|
||||
|
||||
float sx = 0, sy = 0;
|
||||
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
//randomSeed(analogRead(A0));
|
||||
|
||||
// Setup the LCD
|
||||
tft.init();
|
||||
tft.setRotation(3);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
runTime = millis();
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
int n = random(2, 23), r = random(20, 100), colour = 0; //rainbow();
|
||||
|
||||
for (long i = 0; i < (360 * n); i++) {
|
||||
sx = cos((i / n - 90) * DEG2RAD);
|
||||
sy = sin((i / n - 90) * DEG2RAD);
|
||||
x0 = sx * (120 - r) + 159;
|
||||
yy0 = sy * (120 - r) + 119;
|
||||
|
||||
|
||||
sy = cos(((i % 360) - 90) * DEG2RAD);
|
||||
sx = sin(((i % 360) - 90) * DEG2RAD);
|
||||
x1 = sx * r + x0;
|
||||
yy1 = sy * r + yy0;
|
||||
tft.drawPixel(x1, yy1, rainbow(map(i%360,0,360,0,127))); //colour);
|
||||
}
|
||||
|
||||
r = random(20, 100);//r = r / random(2,4);
|
||||
for (long i = 0; i < (360 * n); i++) {
|
||||
sx = cos((i / n - 90) * DEG2RAD);
|
||||
sy = sin((i / n - 90) * DEG2RAD);
|
||||
x0 = sx * (120 - r) + 159;
|
||||
yy0 = sy * (120 - r) + 119;
|
||||
|
||||
|
||||
sy = cos(((i % 360) - 90) * DEG2RAD);
|
||||
sx = sin(((i % 360) - 90) * DEG2RAD);
|
||||
x1 = sx * r + x0;
|
||||
yy1 = sy * r + yy0;
|
||||
tft.drawPixel(x1, yy1, rainbow(map(i%360,0,360,0,127))); //colour);
|
||||
}
|
||||
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
unsigned int rainbow(int value)
|
||||
{
|
||||
// Value is expected to be in range 0-127
|
||||
// The value is converted to a spectrum colour from 0 = blue through to red = blue
|
||||
//int value = random (128);
|
||||
byte red = 0; // Red is the top 5 bits of a 16 bit colour value
|
||||
byte green = 0;// Green is the middle 6 bits
|
||||
byte blue = 0; // Blue is the bottom 5 bits
|
||||
|
||||
byte quadrant = value / 32;
|
||||
|
||||
if (quadrant == 0) {
|
||||
blue = 31;
|
||||
green = 2 * (value % 32);
|
||||
red = 0;
|
||||
}
|
||||
if (quadrant == 1) {
|
||||
blue = 31 - (value % 32);
|
||||
green = 63;
|
||||
red = 0;
|
||||
}
|
||||
if (quadrant == 2) {
|
||||
blue = 0;
|
||||
green = 63;
|
||||
red = value % 32;
|
||||
}
|
||||
if (quadrant == 3) {
|
||||
blue = 0;
|
||||
green = 63 - 2 * (value % 32);
|
||||
red = 31;
|
||||
}
|
||||
return (red << 11) + (green << 5) + blue;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// Animates white pixels to simulate flying through a star field
|
||||
|
||||
#include <SPI.h>
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
// Use hardware SPI
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
|
||||
// With 1024 stars the update rate is ~65 frames per second
|
||||
#define NSTARS 1024
|
||||
uint8_t sx[NSTARS] = {};
|
||||
uint8_t sy[NSTARS] = {};
|
||||
uint8_t sz[NSTARS] = {};
|
||||
|
||||
uint8_t za, zb, zc, zx;
|
||||
|
||||
// Fast 0-255 random number generator from http://eternityforest.com/Projects/rng.php:
|
||||
uint8_t __attribute__((always_inline)) rng()
|
||||
{
|
||||
zx++;
|
||||
za = (za^zc^zx);
|
||||
zb = (zb+za);
|
||||
zc = ((zc+(zb>>1))^za);
|
||||
return zc;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
za = random(256);
|
||||
zb = random(256);
|
||||
zc = random(256);
|
||||
zx = random(256);
|
||||
|
||||
Serial.begin(115200);
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
// fastSetup() must be used immediately before fastPixel() to prepare screen
|
||||
// It must be called after any other graphics drawing function call if fastPixel()
|
||||
// is to be called again
|
||||
//tft.fastSetup(); // Prepare plot window range for fast pixel plotting
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
unsigned long t0 = micros();
|
||||
uint8_t spawnDepthVariation = 255;
|
||||
|
||||
for(int i = 0; i < NSTARS; ++i)
|
||||
{
|
||||
if (sz[i] <= 1)
|
||||
{
|
||||
sx[i] = 160 - 120 + rng();
|
||||
sy[i] = rng();
|
||||
sz[i] = spawnDepthVariation--;
|
||||
}
|
||||
else
|
||||
{
|
||||
int old_screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160;
|
||||
int old_screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120;
|
||||
|
||||
// This is a faster pixel drawing function for occassions where many single pixels must be drawn
|
||||
tft.drawPixel(old_screen_x, old_screen_y,TFT_BLACK);
|
||||
|
||||
sz[i] -= 2;
|
||||
if (sz[i] > 1)
|
||||
{
|
||||
int screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160;
|
||||
int screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120;
|
||||
|
||||
if (screen_x >= 0 && screen_y >= 0 && screen_x < 320 && screen_y < 240)
|
||||
{
|
||||
uint8_t r, g, b;
|
||||
r = g = b = 255 - sz[i];
|
||||
tft.drawPixel(screen_x, screen_y, tft.color565(r,g,b));
|
||||
}
|
||||
else
|
||||
sz[i] = 0; // Out of screen, die.
|
||||
}
|
||||
}
|
||||
}
|
||||
unsigned long t1 = micros();
|
||||
//static char timeMicros[8] = {};
|
||||
|
||||
// Calcualte frames per second
|
||||
Serial.println(1.0/((t1 - t0)/1000000.0));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Tests string alignment
|
||||
|
||||
Normally strings are printed relative to the top left corner but this can be
|
||||
changed with the setTextDatum() function. The library has #defines for:
|
||||
|
||||
TL_DATUM = Top left
|
||||
TC_DATUM = Top centre
|
||||
TR_DATUM = Top right
|
||||
ML_DATUM = Middle left
|
||||
MC_DATUM = Middle centre
|
||||
MR_DATUM = Middle right
|
||||
BL_DATUM = Bottom left
|
||||
BC_DATUM = Bottom centre
|
||||
BR_DATUM = Bottom right
|
||||
|
||||
|
||||
Needs fonts 2, 4, 6, 7 and 8
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
unsigned long drawTime = 0;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
for(byte datum = 0; datum < 9; datum++) {
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
tft.setTextDatum(datum);
|
||||
|
||||
tft.drawNumber(88,160,120,8);
|
||||
tft.fillCircle(160,120,5,TFT_RED);
|
||||
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawString("X",160,120,2);
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
}
|
||||
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
tft.drawCentreString("69",160,120,8);
|
||||
tft.fillCircle(160,120,5,TFT_YELLOW);
|
||||
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawString("X",160,120,2);
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
tft.drawRightString("88",160,120,8);
|
||||
tft.fillCircle(160,120,5,TFT_YELLOW);
|
||||
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawString("X",160,120,2);
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLUE);
|
||||
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
|
||||
//Test floating point drawing function
|
||||
float test = 67.125;
|
||||
tft.drawFloat(test, 4, 160, 180, 4);
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
test = -0.555555;
|
||||
tft.drawFloat(test, 3, 160, 180, 4);
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
test = 0.1;
|
||||
tft.drawFloat(test, 4, 160, 180, 4);
|
||||
delay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
test = 9999999;
|
||||
tft.drawFloat(test, 1, 160, 180, 4);
|
||||
delay(1000);
|
||||
|
||||
tft.fillCircle(160,180,5,TFT_YELLOW);
|
||||
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.drawString("X",160,180,2);
|
||||
|
||||
delay(4000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
|
||||
/*************************************************************
|
||||
This sketch implements a simple serial receive terminal
|
||||
program for monitoring serial debug messages from another
|
||||
board.
|
||||
|
||||
Connect GND to target board GND
|
||||
Connect RX line to TX line of target board
|
||||
Make sure the target and terminal have the same baud rate
|
||||
and serial stettings!
|
||||
|
||||
The sketch works with the ILI9341 TFT 240x320 display and
|
||||
the called up libraries.
|
||||
|
||||
The sketch uses the hardware scrolling feature of the
|
||||
display. Modification of this sketch may lead to problems
|
||||
unless the ILI9341 data sheet has been understood!
|
||||
|
||||
Updated by Bodmer 21/12/16 for TFT_eSPI library:
|
||||
https://github.com/Bodmer/TFT_eSPI
|
||||
|
||||
BSD license applies, all text above must be included in any
|
||||
redistribution
|
||||
*************************************************************/
|
||||
|
||||
#include <TFT_eSPI.h> // Hardware-specific library
|
||||
#include <SPI.h>
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
// The scrolling area must be a integral multiple of TEXT_HEIGHT
|
||||
#define TEXT_HEIGHT 16 // Height of text to be printed and scrolled
|
||||
#define BOT_FIXED_AREA 0 // Number of lines in bottom fixed area (lines counted from bottom of screen)
|
||||
#define TOP_FIXED_AREA 16 // Number of lines in top fixed area (lines counted from top of screen)
|
||||
#define YMAX 320 // Bottom of screen area
|
||||
|
||||
// The initial y coordinate of the top of the scrolling area
|
||||
uint16_t yStart = TOP_FIXED_AREA;
|
||||
// yArea must be a integral multiple of TEXT_HEIGHT
|
||||
uint16_t yArea = YMAX-TOP_FIXED_AREA-BOT_FIXED_AREA;
|
||||
// The initial y coordinate of the top of the bottom text line
|
||||
uint16_t yDraw = YMAX - BOT_FIXED_AREA - TEXT_HEIGHT;
|
||||
|
||||
// Keep track of the drawing x coordinate
|
||||
uint16_t xPos = 0;
|
||||
|
||||
// For the byte we read from the serial port
|
||||
byte data = 0;
|
||||
|
||||
// A few test variables used during debugging
|
||||
bool change_colour = 1;
|
||||
bool selected = 1;
|
||||
|
||||
// We have to blank the top line each time the display is scrolled, but this takes up to 13 milliseconds
|
||||
// for a full width line, meanwhile the serial buffer may be filling... and overflowing
|
||||
// We can speed up scrolling of short text lines by just blanking the character we drew
|
||||
int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking
|
||||
|
||||
void setup() {
|
||||
// Setup the TFT display
|
||||
tft.init();
|
||||
tft.setRotation(0); // Must be setRotation(0) for this sketch to work correctly
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
// Setup baud rate and draw top banner
|
||||
Serial.begin(9600);
|
||||
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLUE);
|
||||
tft.fillRect(0,0,240,16, TFT_BLUE);
|
||||
tft.drawCentreString(" Serial Terminal - 9600 baud ",120,0,2);
|
||||
|
||||
// Change colour for scrolling zone text
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
|
||||
// Setup scroll area
|
||||
setupScrollArea(TOP_FIXED_AREA, BOT_FIXED_AREA);
|
||||
|
||||
// Zero the array
|
||||
for (byte i = 0; i<18; i++) blank[i]=0;
|
||||
}
|
||||
|
||||
|
||||
void loop(void) {
|
||||
// These lines change the text colour when the serial buffer is emptied
|
||||
// These are test lines to see if we may be losing characters
|
||||
// Also uncomment the change_colour line below to try them
|
||||
//
|
||||
// if (change_colour){
|
||||
// change_colour = 0;
|
||||
// if (selected == 1) {tft.setTextColor(TFT_CYAN, TFT_BLACK); selected = 0;}
|
||||
// else {tft.setTextColor(TFT_MAGENTA, TFT_BLACK); selected = 1;}
|
||||
//}
|
||||
|
||||
while (Serial.available()) {
|
||||
data = Serial.read();
|
||||
// If it is a CR or we are near end of line then scroll one line
|
||||
if (data == '\r' || xPos>231) {
|
||||
xPos = 0;
|
||||
yDraw = scroll_line(); // It can take 13ms to scroll and blank 16 pixel lines
|
||||
}
|
||||
if (data > 31 && data < 128) {
|
||||
xPos += tft.drawChar(data,xPos,yDraw,2);
|
||||
blank[(18+(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT)%19]=xPos; // Keep a record of line lengths
|
||||
}
|
||||
//change_colour = 1; // Line to indicate buffer is being emptied
|
||||
}
|
||||
}
|
||||
|
||||
// ##############################################################################################
|
||||
// Call this function to scroll the display one text line
|
||||
// ##############################################################################################
|
||||
int scroll_line() {
|
||||
int yTemp = yStart; // Store the old yStart, this is where we draw the next line
|
||||
// Use the record of line lengths to optimise the rectangle size we need to erase the top line
|
||||
tft.fillRect(0,yStart,blank[(yStart-TOP_FIXED_AREA)/TEXT_HEIGHT],TEXT_HEIGHT, TFT_BLACK);
|
||||
|
||||
// Change the top of the scroll area
|
||||
yStart+=TEXT_HEIGHT;
|
||||
// The value must wrap around as the screen memory is a circular buffer
|
||||
if (yStart >= YMAX - BOT_FIXED_AREA) yStart = TOP_FIXED_AREA + (yStart - YMAX + BOT_FIXED_AREA);
|
||||
// Now we can scroll the display
|
||||
scrollAddress(yStart);
|
||||
return yTemp;
|
||||
}
|
||||
|
||||
// ##############################################################################################
|
||||
// Setup a portion of the screen for vertical scrolling
|
||||
// ##############################################################################################
|
||||
// We are using a hardware feature of the display, so we can only scroll in portrait orientation
|
||||
void setupScrollArea(uint16_t tfa, uint16_t bfa) {
|
||||
tft.writecommand(ILI9341_VSCRDEF); // Vertical scroll definition
|
||||
tft.writedata(tfa >> 8); // Top Fixed Area line count
|
||||
tft.writedata(tfa);
|
||||
tft.writedata((YMAX-tfa-bfa)>>8); // Vertical Scrolling Area line count
|
||||
tft.writedata(YMAX-tfa-bfa);
|
||||
tft.writedata(bfa >> 8); // Bottom Fixed Area line count
|
||||
tft.writedata(bfa);
|
||||
}
|
||||
|
||||
// ##############################################################################################
|
||||
// Setup the vertical scrolling start address pointer
|
||||
// ##############################################################################################
|
||||
void scrollAddress(uint16_t vsp) {
|
||||
tft.writecommand(ILI9341_VSCRSADD); // Vertical scrolling pointer
|
||||
tft.writedata(vsp>>8);
|
||||
tft.writedata(vsp);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,754 @@
|
||||
/*
|
||||
Adapted from the Adafruit and Xark's PDQ graphicstest sketch.
|
||||
|
||||
See end of file for original header text and MIT license info.
|
||||
|
||||
This sketch uses the GLCD font only.
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
#include "SPI.h"
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
// Use hardware SPI
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
|
||||
unsigned long total = 0;
|
||||
unsigned long tn = 0;
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
Serial.println(""); Serial.println("");
|
||||
Serial.println("Bodmer's TFT_eSPI library Test!");
|
||||
|
||||
tft.init();
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
|
||||
Serial.println(F("Benchmark Time (microseconds)"));
|
||||
|
||||
uint32_t usecHaD = testHaD();
|
||||
Serial.print(F("HaD pushColor "));
|
||||
Serial.println(usecHaD);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecFillScreen = testFillScreen();
|
||||
Serial.print(F("Screen fill "));
|
||||
Serial.println(usecFillScreen);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecText = testText();
|
||||
Serial.print(F("Text "));
|
||||
Serial.println(usecText);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecPixels = testPixels();
|
||||
Serial.print(F("Pixels "));
|
||||
Serial.println(usecPixels);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecLines = testLines(TFT_BLUE);
|
||||
Serial.print(F("Lines "));
|
||||
Serial.println(usecLines);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecFastLines = testFastLines(TFT_RED, TFT_BLUE);
|
||||
Serial.print(F("Horiz/Vert Lines "));
|
||||
Serial.println(usecFastLines);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecRects = testRects(TFT_GREEN);
|
||||
Serial.print(F("Rectangles (outline) "));
|
||||
Serial.println(usecRects);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecFilledRects = testFilledRects(TFT_YELLOW, TFT_MAGENTA);
|
||||
Serial.print(F("Rectangles (filled) "));
|
||||
Serial.println(usecFilledRects);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecFilledCircles = testFilledCircles(10, TFT_MAGENTA);
|
||||
Serial.print(F("Circles (filled) "));
|
||||
Serial.println(usecFilledCircles);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecCircles = testCircles(10, TFT_WHITE);
|
||||
Serial.print(F("Circles (outline) "));
|
||||
Serial.println(usecCircles);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecTriangles = testTriangles();
|
||||
Serial.print(F("Triangles (outline) "));
|
||||
Serial.println(usecTriangles);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecFilledTrangles = testFilledTriangles();
|
||||
Serial.print(F("Triangles (filled) "));
|
||||
Serial.println(usecFilledTrangles);
|
||||
delay(100);
|
||||
|
||||
uint32_t usecRoundRects = testRoundRects();
|
||||
Serial.print(F("Rounded rects (outline) "));
|
||||
Serial.println(usecRoundRects);
|
||||
delay(100);
|
||||
|
||||
uint32_t usedFilledRoundRects = testFilledRoundRects();
|
||||
Serial.print(F("Rounded rects (filled) "));
|
||||
Serial.println(usedFilledRoundRects);
|
||||
delay(100);
|
||||
|
||||
Serial.println(F("Done!"));
|
||||
|
||||
uint16_t c = 4;
|
||||
int8_t d = 1;
|
||||
for (int32_t i = 0; i < tft.height(); i++)
|
||||
{
|
||||
tft.drawFastHLine(0, i, tft.width(), c);
|
||||
c += d;
|
||||
if (c <= 4 || c >= 11)
|
||||
d = -d;
|
||||
}
|
||||
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextColor(TFT_MAGENTA);
|
||||
tft.setTextSize(2);
|
||||
|
||||
tft.println(F(" TFT_eSPI test"));
|
||||
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(TFT_WHITE);
|
||||
tft.println(F(""));
|
||||
tft.setTextSize(1);
|
||||
tft.println(F(""));
|
||||
tft.setTextColor(tft.color565(0x80, 0x80, 0x80));
|
||||
|
||||
tft.println(F(""));
|
||||
|
||||
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
tft.println(F(" Benchmark microseconds"));
|
||||
tft.println(F(""));
|
||||
tft.setTextColor(TFT_YELLOW);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("HaD pushColor "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecHaD);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Screen fill "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecFillScreen);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Text "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecText);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Pixels "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecPixels);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Lines "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecLines);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Horiz/Vert Lines "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecFastLines);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Rectangles "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecRects);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Rectangles-filled "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecFilledRects);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Circles "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecCircles);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Circles-filled "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecFilledCircles);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Triangles "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecTriangles);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Triangles-filled "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecFilledTrangles);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Rounded rects "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usecRoundRects);
|
||||
|
||||
tft.setTextColor(TFT_CYAN); tft.setTextSize(1);
|
||||
tft.print(F("Rounded rects-fill "));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
printnice(usedFilledRoundRects);
|
||||
|
||||
tft.setTextSize(1);
|
||||
tft.println(F(""));
|
||||
tft.setTextColor(TFT_GREEN); tft.setTextSize(2);
|
||||
tft.print(F("Benchmark Complete!"));
|
||||
|
||||
delay(60 * 1000L);
|
||||
}
|
||||
|
||||
void printnice(int32_t v)
|
||||
{
|
||||
char str[32] = { 0 };
|
||||
sprintf(str, "%d", v);
|
||||
for (char *p = (str+strlen(str))-3; p > str; p -= 3)
|
||||
{
|
||||
memmove(p+1, p, strlen(p)+1);
|
||||
*p = ',';
|
||||
|
||||
}
|
||||
while (strlen(str) < 10)
|
||||
{
|
||||
memmove(str+1, str, strlen(str)+1);
|
||||
*str = ' ';
|
||||
}
|
||||
tft.println(str);
|
||||
}
|
||||
|
||||
static inline uint32_t micros_start() __attribute__ ((always_inline));
|
||||
static inline uint32_t micros_start()
|
||||
{
|
||||
uint8_t oms = millis();
|
||||
while ((uint8_t)millis() == oms)
|
||||
;
|
||||
return micros();
|
||||
}
|
||||
|
||||
uint32_t testHaD()
|
||||
{
|
||||
// pseudo-code for cheesy RLE
|
||||
// start with color1
|
||||
// while more input data remaining
|
||||
// count = 0nnnnnnn = 1 byte or 1nnnnnnn nnnnnnnn 2 bytes (0 - 32767)
|
||||
// repeat color count times
|
||||
// toggle color1/color2
|
||||
static const uint8_t HaD_240x320[] PROGMEM =
|
||||
{
|
||||
0xb9, 0x50, 0x0e, 0x80, 0x93, 0x0e, 0x41, 0x11, 0x80, 0x8d, 0x11, 0x42, 0x12, 0x80, 0x89, 0x12,
|
||||
0x45, 0x12, 0x80, 0x85, 0x12, 0x48, 0x12, 0x80, 0x83, 0x12, 0x4a, 0x13, 0x7f, 0x13, 0x4c, 0x13,
|
||||
0x7d, 0x13, 0x4e, 0x13, 0x7b, 0x13, 0x50, 0x13, 0x79, 0x13, 0x52, 0x13, 0x77, 0x13, 0x54, 0x13,
|
||||
0x75, 0x13, 0x57, 0x11, 0x75, 0x11, 0x5a, 0x11, 0x73, 0x11, 0x5c, 0x11, 0x71, 0x11, 0x5e, 0x10,
|
||||
0x71, 0x10, 0x60, 0x10, 0x6f, 0x10, 0x61, 0x10, 0x6f, 0x10, 0x60, 0x11, 0x6f, 0x11, 0x5e, 0x13,
|
||||
0x6d, 0x13, 0x5c, 0x14, 0x6d, 0x14, 0x5a, 0x15, 0x6d, 0x15, 0x58, 0x17, 0x6b, 0x17, 0x37, 0x01,
|
||||
0x1f, 0x17, 0x6b, 0x17, 0x1f, 0x01, 0x17, 0x02, 0x1d, 0x18, 0x6b, 0x18, 0x1d, 0x02, 0x17, 0x03,
|
||||
0x1b, 0x19, 0x6b, 0x19, 0x1b, 0x03, 0x17, 0x05, 0x18, 0x1a, 0x6b, 0x1a, 0x18, 0x05, 0x17, 0x06,
|
||||
0x16, 0x1b, 0x6b, 0x1b, 0x16, 0x06, 0x17, 0x07, 0x14, 0x1c, 0x6b, 0x1c, 0x14, 0x07, 0x17, 0x08,
|
||||
0x12, 0x1d, 0x6b, 0x1d, 0x12, 0x08, 0x17, 0x09, 0x10, 0x1e, 0x6b, 0x1e, 0x10, 0x09, 0x17, 0x0a,
|
||||
0x0e, 0x1f, 0x6b, 0x1f, 0x0e, 0x0a, 0x17, 0x0b, 0x0c, 0x20, 0x6b, 0x20, 0x0c, 0x0b, 0x17, 0x0c,
|
||||
0x0b, 0x21, 0x69, 0x21, 0x0b, 0x0c, 0x18, 0x0d, 0x08, 0x23, 0x67, 0x23, 0x08, 0x0d, 0x19, 0x0e,
|
||||
0x06, 0x26, 0x63, 0x26, 0x06, 0x0e, 0x19, 0x0f, 0x04, 0x28, 0x61, 0x28, 0x04, 0x0f, 0x19, 0x10,
|
||||
0x02, 0x2a, 0x5f, 0x2a, 0x02, 0x10, 0x1a, 0x3c, 0x5d, 0x3c, 0x1b, 0x3d, 0x5b, 0x3d, 0x1c, 0x3d,
|
||||
0x59, 0x3d, 0x1d, 0x3e, 0x57, 0x3e, 0x1e, 0x3e, 0x55, 0x3e, 0x1f, 0x40, 0x51, 0x40, 0x20, 0x40,
|
||||
0x4f, 0x40, 0x22, 0x40, 0x22, 0x09, 0x22, 0x40, 0x24, 0x40, 0x1a, 0x17, 0x1a, 0x40, 0x26, 0x40,
|
||||
0x16, 0x1d, 0x16, 0x40, 0x28, 0x40, 0x12, 0x23, 0x12, 0x40, 0x2a, 0x40, 0x0f, 0x27, 0x0f, 0x40,
|
||||
0x2c, 0x41, 0x0b, 0x2b, 0x0b, 0x41, 0x2f, 0x3f, 0x09, 0x2f, 0x09, 0x3f, 0x32, 0x3d, 0x08, 0x33,
|
||||
0x08, 0x3d, 0x35, 0x3a, 0x08, 0x35, 0x08, 0x3a, 0x3a, 0x36, 0x07, 0x39, 0x07, 0x36, 0x41, 0x09,
|
||||
0x05, 0x23, 0x07, 0x3b, 0x07, 0x23, 0x05, 0x09, 0x54, 0x21, 0x07, 0x3d, 0x07, 0x21, 0x64, 0x1f,
|
||||
0x06, 0x41, 0x06, 0x1f, 0x66, 0x1d, 0x06, 0x43, 0x06, 0x1d, 0x68, 0x1b, 0x06, 0x45, 0x06, 0x1b,
|
||||
0x6b, 0x18, 0x06, 0x47, 0x06, 0x18, 0x6e, 0x16, 0x06, 0x49, 0x06, 0x16, 0x70, 0x14, 0x06, 0x4b,
|
||||
0x06, 0x14, 0x72, 0x13, 0x06, 0x4b, 0x06, 0x13, 0x74, 0x11, 0x06, 0x4d, 0x06, 0x11, 0x76, 0x0f,
|
||||
0x06, 0x4f, 0x06, 0x0f, 0x78, 0x0e, 0x05, 0x51, 0x05, 0x0e, 0x7a, 0x0c, 0x06, 0x51, 0x06, 0x0c,
|
||||
0x7d, 0x09, 0x06, 0x53, 0x06, 0x09, 0x80, 0x80, 0x08, 0x05, 0x55, 0x05, 0x08, 0x80, 0x82, 0x06,
|
||||
0x05, 0x57, 0x05, 0x06, 0x80, 0x84, 0x05, 0x05, 0x57, 0x05, 0x05, 0x80, 0x86, 0x03, 0x05, 0x59,
|
||||
0x05, 0x03, 0x80, 0x88, 0x02, 0x05, 0x59, 0x05, 0x02, 0x80, 0x8f, 0x5b, 0x80, 0x95, 0x5b, 0x80,
|
||||
0x94, 0x5d, 0x80, 0x93, 0x5d, 0x80, 0x92, 0x5e, 0x80, 0x92, 0x5f, 0x80, 0x91, 0x5f, 0x80, 0x90,
|
||||
0x61, 0x80, 0x8f, 0x61, 0x80, 0x8f, 0x61, 0x80, 0x8e, 0x63, 0x80, 0x8d, 0x63, 0x80, 0x8d, 0x63,
|
||||
0x80, 0x8d, 0x63, 0x80, 0x8c, 0x19, 0x07, 0x25, 0x07, 0x19, 0x80, 0x8b, 0x16, 0x0d, 0x1f, 0x0d,
|
||||
0x16, 0x80, 0x8b, 0x14, 0x11, 0x1b, 0x11, 0x14, 0x80, 0x8b, 0x13, 0x13, 0x19, 0x13, 0x13, 0x80,
|
||||
0x8b, 0x12, 0x15, 0x17, 0x15, 0x12, 0x80, 0x8a, 0x12, 0x17, 0x15, 0x17, 0x12, 0x80, 0x89, 0x11,
|
||||
0x19, 0x13, 0x19, 0x11, 0x80, 0x89, 0x11, 0x19, 0x13, 0x19, 0x11, 0x80, 0x89, 0x10, 0x1b, 0x11,
|
||||
0x1b, 0x10, 0x80, 0x89, 0x0f, 0x1c, 0x11, 0x1c, 0x0f, 0x80, 0x89, 0x0f, 0x1c, 0x11, 0x1c, 0x0f,
|
||||
0x80, 0x89, 0x0f, 0x1c, 0x11, 0x1c, 0x0f, 0x80, 0x89, 0x0e, 0x1d, 0x11, 0x1d, 0x0e, 0x80, 0x89,
|
||||
0x0e, 0x1c, 0x13, 0x1c, 0x0e, 0x80, 0x89, 0x0e, 0x1b, 0x15, 0x1b, 0x0e, 0x80, 0x89, 0x0e, 0x1b,
|
||||
0x15, 0x1b, 0x0e, 0x80, 0x89, 0x0e, 0x1a, 0x17, 0x1a, 0x0e, 0x80, 0x89, 0x0e, 0x18, 0x1b, 0x18,
|
||||
0x0e, 0x80, 0x89, 0x0e, 0x16, 0x1f, 0x16, 0x0e, 0x80, 0x89, 0x0e, 0x14, 0x23, 0x14, 0x0e, 0x80,
|
||||
0x89, 0x0f, 0x11, 0x27, 0x11, 0x0f, 0x80, 0x89, 0x0f, 0x0e, 0x2d, 0x0e, 0x0f, 0x80, 0x89, 0x0f,
|
||||
0x0c, 0x31, 0x0c, 0x0f, 0x80, 0x89, 0x0f, 0x0b, 0x33, 0x0b, 0x0f, 0x80, 0x8a, 0x0f, 0x09, 0x35,
|
||||
0x09, 0x0f, 0x80, 0x8b, 0x10, 0x08, 0x35, 0x08, 0x10, 0x80, 0x8b, 0x10, 0x07, 0x37, 0x07, 0x10,
|
||||
0x80, 0x8b, 0x11, 0x06, 0x37, 0x06, 0x11, 0x80, 0x8b, 0x12, 0x05, 0x37, 0x05, 0x12, 0x80, 0x8c,
|
||||
0x13, 0x03, 0x1b, 0x01, 0x1b, 0x03, 0x13, 0x80, 0x8d, 0x30, 0x03, 0x30, 0x80, 0x8d, 0x30, 0x04,
|
||||
0x2f, 0x80, 0x8d, 0x2f, 0x05, 0x2f, 0x80, 0x8e, 0x2e, 0x06, 0x2d, 0x80, 0x8f, 0x2d, 0x07, 0x2d,
|
||||
0x80, 0x8f, 0x2d, 0x07, 0x2d, 0x80, 0x90, 0x2c, 0x08, 0x2b, 0x80, 0x91, 0x2b, 0x09, 0x2b, 0x80,
|
||||
0x8c, 0x01, 0x05, 0x2a, 0x09, 0x2a, 0x05, 0x01, 0x80, 0x85, 0x03, 0x05, 0x2a, 0x09, 0x2a, 0x05,
|
||||
0x03, 0x80, 0x82, 0x04, 0x05, 0x2a, 0x09, 0x2a, 0x04, 0x05, 0x80, 0x80, 0x06, 0x05, 0x29, 0x04,
|
||||
0x02, 0x03, 0x29, 0x05, 0x06, 0x7e, 0x07, 0x05, 0x29, 0x03, 0x03, 0x03, 0x29, 0x05, 0x07, 0x7c,
|
||||
0x09, 0x05, 0x28, 0x02, 0x05, 0x02, 0x28, 0x05, 0x09, 0x7a, 0x0a, 0x05, 0x28, 0x02, 0x05, 0x02,
|
||||
0x28, 0x05, 0x0a, 0x78, 0x0c, 0x05, 0x27, 0x02, 0x05, 0x02, 0x27, 0x05, 0x0c, 0x76, 0x0d, 0x06,
|
||||
0x26, 0x01, 0x07, 0x01, 0x26, 0x06, 0x0d, 0x73, 0x10, 0x05, 0x55, 0x05, 0x10, 0x70, 0x12, 0x05,
|
||||
0x53, 0x05, 0x12, 0x6e, 0x13, 0x06, 0x51, 0x06, 0x13, 0x6c, 0x15, 0x05, 0x51, 0x05, 0x15, 0x6a,
|
||||
0x16, 0x06, 0x4f, 0x06, 0x16, 0x68, 0x18, 0x06, 0x4d, 0x06, 0x18, 0x66, 0x1a, 0x06, 0x4b, 0x06,
|
||||
0x1a, 0x64, 0x1c, 0x06, 0x49, 0x06, 0x1c, 0x55, 0x07, 0x05, 0x1e, 0x06, 0x49, 0x06, 0x1e, 0x05,
|
||||
0x07, 0x42, 0x30, 0x06, 0x47, 0x06, 0x30, 0x3a, 0x34, 0x06, 0x45, 0x06, 0x34, 0x35, 0x37, 0x06,
|
||||
0x43, 0x06, 0x37, 0x32, 0x39, 0x07, 0x3f, 0x07, 0x39, 0x2f, 0x3c, 0x07, 0x3d, 0x07, 0x3c, 0x2c,
|
||||
0x3e, 0x07, 0x3b, 0x07, 0x3e, 0x2a, 0x40, 0x06, 0x3b, 0x06, 0x40, 0x28, 0x40, 0x06, 0x3c, 0x07,
|
||||
0x40, 0x26, 0x3f, 0x08, 0x3d, 0x08, 0x3f, 0x24, 0x3f, 0x09, 0x3d, 0x09, 0x3f, 0x22, 0x3f, 0x0a,
|
||||
0x14, 0x01, 0x13, 0x02, 0x13, 0x0a, 0x3f, 0x20, 0x3f, 0x0b, 0x14, 0x01, 0x13, 0x02, 0x13, 0x0b,
|
||||
0x3f, 0x1f, 0x3e, 0x0c, 0x14, 0x01, 0x13, 0x02, 0x13, 0x0c, 0x3e, 0x1e, 0x3e, 0x0d, 0x13, 0x02,
|
||||
0x13, 0x02, 0x13, 0x0d, 0x3e, 0x1d, 0x3d, 0x0e, 0x13, 0x02, 0x13, 0x02, 0x13, 0x0e, 0x3d, 0x1c,
|
||||
0x3c, 0x11, 0x11, 0x04, 0x11, 0x04, 0x11, 0x11, 0x3c, 0x1b, 0x10, 0x01, 0x2a, 0x12, 0x11, 0x04,
|
||||
0x11, 0x04, 0x11, 0x12, 0x2a, 0x01, 0x10, 0x1a, 0x0f, 0x04, 0x28, 0x14, 0x0f, 0x06, 0x0f, 0x06,
|
||||
0x0f, 0x14, 0x28, 0x04, 0x0f, 0x19, 0x0e, 0x06, 0x26, 0x16, 0x0d, 0x08, 0x0d, 0x08, 0x0d, 0x16,
|
||||
0x26, 0x06, 0x0e, 0x19, 0x0d, 0x07, 0x25, 0x18, 0x0b, 0x0a, 0x0b, 0x0a, 0x0b, 0x18, 0x25, 0x07,
|
||||
0x0d, 0x19, 0x0c, 0x09, 0x23, 0x1c, 0x06, 0x0f, 0x05, 0x10, 0x05, 0x1c, 0x23, 0x09, 0x0c, 0x18,
|
||||
0x0c, 0x0b, 0x21, 0x69, 0x21, 0x0b, 0x0c, 0x17, 0x0b, 0x0d, 0x1f, 0x6b, 0x1f, 0x0d, 0x0b, 0x17,
|
||||
0x0a, 0x0f, 0x1e, 0x6b, 0x1e, 0x0f, 0x0a, 0x17, 0x09, 0x11, 0x1d, 0x6b, 0x1d, 0x11, 0x09, 0x17,
|
||||
0x07, 0x14, 0x1c, 0x6b, 0x1c, 0x14, 0x07, 0x17, 0x06, 0x16, 0x1b, 0x6b, 0x1b, 0x16, 0x06, 0x17,
|
||||
0x05, 0x18, 0x1a, 0x6b, 0x1a, 0x18, 0x05, 0x17, 0x04, 0x1a, 0x19, 0x6b, 0x19, 0x1a, 0x04, 0x17,
|
||||
0x03, 0x1b, 0x19, 0x6b, 0x19, 0x1b, 0x03, 0x17, 0x02, 0x1d, 0x18, 0x6b, 0x18, 0x1d, 0x02, 0x37,
|
||||
0x17, 0x6b, 0x17, 0x58, 0x16, 0x6b, 0x16, 0x5a, 0x14, 0x6d, 0x14, 0x5c, 0x13, 0x6d, 0x13, 0x5e,
|
||||
0x12, 0x6d, 0x12, 0x60, 0x10, 0x6f, 0x10, 0x61, 0x10, 0x6f, 0x10, 0x60, 0x11, 0x6f, 0x11, 0x5e,
|
||||
0x11, 0x71, 0x11, 0x5c, 0x12, 0x71, 0x12, 0x5a, 0x12, 0x73, 0x12, 0x58, 0x12, 0x75, 0x12, 0x56,
|
||||
0x13, 0x75, 0x13, 0x54, 0x13, 0x77, 0x13, 0x51, 0x14, 0x79, 0x14, 0x4e, 0x14, 0x7b, 0x14, 0x4c,
|
||||
0x14, 0x7d, 0x14, 0x4a, 0x14, 0x7f, 0x14, 0x48, 0x13, 0x80, 0x83, 0x13, 0x46, 0x13, 0x80, 0x85,
|
||||
0x13, 0x44, 0x12, 0x80, 0x89, 0x12, 0x42, 0x11, 0x80, 0x8d, 0x11, 0x40, 0x0f, 0x80, 0x93, 0x0f,
|
||||
0x45, 0x04, 0x80, 0x9d, 0x04, 0xb9, 0x56,
|
||||
};
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
uint32_t start = micros_start();
|
||||
|
||||
for (int i = 0; i < 0x10; i++)
|
||||
{
|
||||
tft.setAddrWindow(0, 0, 240, 320);
|
||||
|
||||
uint16_t cnt = 0;
|
||||
uint16_t color = tft.color565((i << 4) | i, (i << 4) | i, (i << 4) | i);
|
||||
uint16_t curcolor = 0;
|
||||
|
||||
const uint8_t *cmp = &HaD_240x320[0];
|
||||
|
||||
tft.startWrite();
|
||||
while (cmp < &HaD_240x320[sizeof(HaD_240x320)])
|
||||
{
|
||||
cnt = pgm_read_byte(cmp++);
|
||||
if (cnt & 0x80) cnt = ((cnt & 0x7f) << 8) | pgm_read_byte(cmp++);
|
||||
tft.pushColor(curcolor, cnt); // PDQ_GFX has count
|
||||
curcolor ^= color;
|
||||
}
|
||||
tft.endWrite();
|
||||
}
|
||||
|
||||
uint32_t t = micros() - start;
|
||||
|
||||
tft.setTextColor(TFT_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.setCursor(8, 285);
|
||||
tft.print(F("http://hackaday.io/"));
|
||||
tft.setCursor(96, 302);
|
||||
tft.print(F("Xark"));
|
||||
|
||||
delay(3 * 1000L);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
uint32_t testFillScreen()
|
||||
{
|
||||
uint32_t start = micros_start();
|
||||
// Shortened this tedious test!
|
||||
tft.fillScreen(TFT_WHITE);
|
||||
tft.fillScreen(TFT_RED);
|
||||
tft.fillScreen(TFT_GREEN);
|
||||
tft.fillScreen(TFT_BLUE);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
return (micros() - start)/5;
|
||||
}
|
||||
|
||||
uint32_t testText()
|
||||
{
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
uint32_t start = micros_start();
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextColor(TFT_WHITE,TFT_BLACK); tft.setTextSize(1);
|
||||
tft.println(F("Hello World!"));
|
||||
tft.setTextSize(2);
|
||||
tft.setTextColor(tft.color565(0xff, 0x00, 0x00));
|
||||
tft.print(F("RED "));
|
||||
tft.setTextColor(tft.color565(0x00, 0xff, 0x00));
|
||||
tft.print(F("GREEN "));
|
||||
tft.setTextColor(tft.color565(0x00, 0x00, 0xff));
|
||||
tft.println(F("BLUE"));
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
tft.println(1234.56);
|
||||
tft.setTextColor(TFT_RED); tft.setTextSize(3);
|
||||
tft.println(0xDEADBEEF, HEX);
|
||||
tft.println();
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
tft.setTextSize(5);
|
||||
tft.println(F("Groop"));
|
||||
tft.setTextSize(2);
|
||||
tft.println(F("I implore thee,"));
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
tft.setTextSize(1);
|
||||
tft.println(F("my foonting turlingdromes."));
|
||||
tft.println(F("And hooptiously drangle me"));
|
||||
tft.println(F("with crinkly bindlewurdles,"));
|
||||
tft.println(F("Or I will rend thee"));
|
||||
tft.println(F("in the gobberwarts"));
|
||||
tft.println(F("with my blurglecruncheon,"));
|
||||
tft.println(F("see if I don't!"));
|
||||
tft.println(F(""));
|
||||
tft.println(F(""));
|
||||
tft.setTextColor(TFT_MAGENTA);
|
||||
tft.setTextSize(6);
|
||||
tft.println(F("Woot!"));
|
||||
uint32_t t = micros() - start;
|
||||
delay(1000);
|
||||
return t;
|
||||
}
|
||||
|
||||
uint32_t testPixels()
|
||||
{
|
||||
int32_t w = tft.width();
|
||||
int32_t h = tft.height();
|
||||
|
||||
uint32_t start = micros_start();
|
||||
tft.startWrite();
|
||||
for (uint16_t y = 0; y < h; y++)
|
||||
{
|
||||
for (uint16_t x = 0; x < w; x++)
|
||||
{
|
||||
tft.drawPixel(x, y, tft.color565(x<<3, y<<3, x*y));
|
||||
}
|
||||
}
|
||||
tft.endWrite();
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
|
||||
uint32_t testLines(uint16_t color)
|
||||
{
|
||||
uint32_t start, t;
|
||||
int32_t x1, y1, x2, y2;
|
||||
int32_t w = tft.width();
|
||||
int32_t h = tft.height();
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
x1 = y1 = 0;
|
||||
y2 = h - 1;
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (x2 = 0; x2 < w; x2 += 6)
|
||||
{
|
||||
tft.drawLine(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
x2 = w - 1;
|
||||
|
||||
for (y2 = 0; y2 < h; y2 += 6)
|
||||
{
|
||||
tft.drawLine(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
t = micros() - start; // fillScreen doesn't count against timing
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = 0;
|
||||
y2 = h - 1;
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (x2 = 0; x2 < w; x2 += 6)
|
||||
{
|
||||
tft.drawLine(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
x2 = 0;
|
||||
for (y2 = 0; y2 < h; y2 += 6)
|
||||
{
|
||||
tft.drawLine(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
t += micros() - start;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
x1 = 0;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (x2 = 0; x2 < w; x2 += 6)
|
||||
{
|
||||
tft.drawLine(x1, y1, x2, y2, color);
|
||||
}
|
||||
x2 = w - 1;
|
||||
for (y2 = 0; y2 < h; y2 += 6)
|
||||
{
|
||||
tft.drawLine(x1, y1, x2, y2, color);
|
||||
}
|
||||
t += micros() - start;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (x2 = 0; x2 < w; x2 += 6)
|
||||
{
|
||||
tft.drawLine(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
x2 = 0;
|
||||
for (y2 = 0; y2 < h; y2 += 6)
|
||||
{
|
||||
tft.drawLine(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
t += micros() - start;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
uint32_t testFastLines(uint16_t color1, uint16_t color2)
|
||||
{
|
||||
uint32_t start;
|
||||
int32_t x, y;
|
||||
int32_t w = tft.width();
|
||||
int32_t h = tft.height();
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (y = 0; y < h; y += 5)
|
||||
tft.drawFastHLine(0, y, w, color1);
|
||||
for (x = 0; x < w; x += 5)
|
||||
tft.drawFastVLine(x, 0, h, color2);
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
uint32_t testRects(uint16_t color)
|
||||
{
|
||||
uint32_t start;
|
||||
int32_t n, i, i2;
|
||||
int32_t cx = tft.width() / 2;
|
||||
int32_t cy = tft.height() / 2;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
start = micros_start();
|
||||
for (i = 2; i < n; i += 6)
|
||||
{
|
||||
i2 = i / 2;
|
||||
tft.drawRect(cx-i2, cy-i2, i, i, color);
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
uint32_t testFilledRects(uint16_t color1, uint16_t color2)
|
||||
{
|
||||
uint32_t start, t = 0;
|
||||
int32_t n, i, i2;
|
||||
int32_t cx = tft.width() / 2 - 1;
|
||||
int32_t cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
for (i = n; i > 0; i -= 6)
|
||||
{
|
||||
i2 = i / 2;
|
||||
|
||||
start = micros_start();
|
||||
|
||||
tft.fillRect(cx-i2, cy-i2, i, i, color1);
|
||||
|
||||
t += micros() - start;
|
||||
|
||||
// Outlines are not included in timing results
|
||||
tft.drawRect(cx-i2, cy-i2, i, i, color2);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
uint32_t testFilledCircles(uint8_t radius, uint16_t color)
|
||||
{
|
||||
uint32_t start;
|
||||
int32_t x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (x = radius; x < w; x += r2)
|
||||
{
|
||||
for (y = radius; y < h; y += r2)
|
||||
{
|
||||
tft.fillCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
uint32_t testCircles(uint8_t radius, uint16_t color)
|
||||
{
|
||||
uint32_t start;
|
||||
int32_t x, y, r2 = radius * 2;
|
||||
int32_t w = tft.width() + radius;
|
||||
int32_t h = tft.height() + radius;
|
||||
|
||||
// Screen is not cleared for this one -- this is
|
||||
// intentional and does not affect the reported time.
|
||||
start = micros_start();
|
||||
|
||||
for (x = 0; x < w; x += r2)
|
||||
{
|
||||
for (y = 0; y < h; y += r2)
|
||||
{
|
||||
tft.drawCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
uint32_t testTriangles()
|
||||
{
|
||||
uint32_t start;
|
||||
int32_t n, i;
|
||||
int32_t cx = tft.width()/ 2 - 1;
|
||||
int32_t cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
n = min(cx, cy);
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (i = 0; i < n; i += 5)
|
||||
{
|
||||
tft.drawTriangle(
|
||||
cx , cy - i, // peak
|
||||
cx - i, cy + i, // bottom left
|
||||
cx + i, cy + i, // bottom right
|
||||
tft.color565(0, 0, i));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
uint32_t testFilledTriangles()
|
||||
{
|
||||
uint32_t start, t = 0;
|
||||
int32_t i;
|
||||
int32_t cx = tft.width() / 2 - 1;
|
||||
int32_t cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (i = min(cx,cy); i > 10; i -= 5) {
|
||||
start = micros_start();
|
||||
tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(0, i, i));
|
||||
t += micros() - start;
|
||||
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(i, i, 0));
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
uint32_t testRoundRects()
|
||||
{
|
||||
uint32_t start;
|
||||
int32_t w, i, i2;
|
||||
int32_t cx = tft.width() / 2 - 1;
|
||||
int32_t cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
w = min(tft.width(), tft.height());
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (i = 0; i < w; i += 6)
|
||||
{
|
||||
i2 = i / 2;
|
||||
tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
uint32_t testFilledRoundRects()
|
||||
{
|
||||
uint32_t start;
|
||||
int32_t i, i2;
|
||||
int32_t cx = tft.width() / 2 - 1;
|
||||
int32_t cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
start = micros_start();
|
||||
|
||||
for (i = min(tft.width(), tft.height()); i > 20; i -= 6)
|
||||
{
|
||||
i2 = i / 2;
|
||||
tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
/***************************************************
|
||||
Original sketch text:
|
||||
|
||||
This is an example sketch for the Adafruit 2.2" SPI display.
|
||||
This library works with the Adafruit 2.2" TFT Breakout w/SD card
|
||||
----> http://www.adafruit.com/products/1480
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional)
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
Adapted from the Adafruit graphicstest sketch, see original header at end
|
||||
of sketch.
|
||||
|
||||
This sketch uses the GLCD font (font 1) only.
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
|
||||
#include "SPI.h"
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
|
||||
unsigned long total = 0;
|
||||
unsigned long tn = 0;
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
|
||||
Serial.println(""); Serial.println("");
|
||||
Serial.println("TFT_eSPI library test!");
|
||||
|
||||
tft.init();
|
||||
|
||||
tn = micros();
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
yield(); Serial.println(F("Benchmark Time (microseconds)"));
|
||||
|
||||
yield(); Serial.print(F("Screen fill "));
|
||||
yield(); Serial.println(testFillScreen());
|
||||
//total+=testFillScreen();
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Text "));
|
||||
yield(); Serial.println(testText());
|
||||
//total+=testText();
|
||||
//delay(3000);
|
||||
|
||||
yield(); Serial.print(F("Lines "));
|
||||
yield(); Serial.println(testLines(TFT_CYAN));
|
||||
//total+=testLines(TFT_CYAN);
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Horiz/Vert Lines "));
|
||||
yield(); Serial.println(testFastLines(TFT_RED, TFT_BLUE));
|
||||
//total+=testFastLines(TFT_RED, TFT_BLUE);
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Rectangles (outline) "));
|
||||
yield(); Serial.println(testRects(TFT_GREEN));
|
||||
//total+=testRects(TFT_GREEN);
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Rectangles (filled) "));
|
||||
yield(); Serial.println(testFilledRects(TFT_YELLOW, TFT_MAGENTA));
|
||||
//total+=testFilledRects(TFT_YELLOW, TFT_MAGENTA);
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Circles (filled) "));
|
||||
yield(); Serial.println(testFilledCircles(10, TFT_MAGENTA));
|
||||
//total+= testFilledCircles(10, TFT_MAGENTA);
|
||||
|
||||
yield(); Serial.print(F("Circles (outline) "));
|
||||
yield(); Serial.println(testCircles(10, TFT_WHITE));
|
||||
//total+=testCircles(10, TFT_WHITE);
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Triangles (outline) "));
|
||||
yield(); Serial.println(testTriangles());
|
||||
//total+=testTriangles();
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Triangles (filled) "));
|
||||
yield(); Serial.println(testFilledTriangles());
|
||||
//total += testFilledTriangles();
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Rounded rects (outline) "));
|
||||
yield(); Serial.println(testRoundRects());
|
||||
//total+=testRoundRects();
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.print(F("Rounded rects (filled) "));
|
||||
yield(); Serial.println(testFilledRoundRects());
|
||||
//total+=testFilledRoundRects();
|
||||
//delay(500);
|
||||
|
||||
yield(); Serial.println(F("Done!")); yield();
|
||||
//Serial.print(F("Total = ")); Serial.println(total);
|
||||
|
||||
//yield();Serial.println(millis()-tn);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
for (uint8_t rotation = 0; rotation < 4; rotation++) {
|
||||
tft.setRotation(rotation);
|
||||
testText();
|
||||
delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned long testFillScreen() {
|
||||
unsigned long start = micros();
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.fillScreen(TFT_RED);
|
||||
tft.fillScreen(TFT_GREEN);
|
||||
tft.fillScreen(TFT_BLUE);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testText() {
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
unsigned long start = micros();
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextColor(TFT_WHITE); tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(TFT_YELLOW); tft.setTextSize(2);
|
||||
tft.println(1234.56);
|
||||
tft.setTextColor(TFT_RED); tft.setTextSize(3);
|
||||
tft.println(0xDEADBEEF, HEX);
|
||||
tft.println();
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
tft.setTextSize(5);
|
||||
tft.println("Groop");
|
||||
tft.setTextSize(2);
|
||||
tft.println("I implore thee,");
|
||||
//tft.setTextColor(TFT_GREEN,TFT_BLACK);
|
||||
tft.setTextSize(1);
|
||||
tft.println("my foonting turlingdromes.");
|
||||
tft.println("And hooptiously drangle me");
|
||||
tft.println("with crinkly bindlewurdles,");
|
||||
tft.println("Or I will rend thee");
|
||||
tft.println("in the gobberwarts");
|
||||
tft.println("with my blurglecruncheon,");
|
||||
tft.println("see if I don't!");
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testLines(uint16_t color) {
|
||||
unsigned long start, t;
|
||||
int x1, y1, x2, y2,
|
||||
w = tft.width(),
|
||||
h = tft.height();
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
x1 = y1 = 0;
|
||||
y2 = h - 1;
|
||||
start = micros();
|
||||
for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = w - 1;
|
||||
for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t = micros() - start; // fillScreen doesn't count against timing
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = 0;
|
||||
y2 = h - 1;
|
||||
start = micros();
|
||||
for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = 0;
|
||||
for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t += micros() - start;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
x1 = 0;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
start = micros();
|
||||
for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = w - 1;
|
||||
for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
t += micros() - start;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
x1 = w - 1;
|
||||
y1 = h - 1;
|
||||
y2 = 0;
|
||||
start = micros();
|
||||
for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
x2 = 0;
|
||||
for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFastLines(uint16_t color1, uint16_t color2) {
|
||||
unsigned long start;
|
||||
int x, y, w = tft.width(), h = tft.height();
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
start = micros();
|
||||
for (y = 0; y < h; y += 5) tft.drawFastHLine(0, y, w, color1);
|
||||
for (x = 0; x < w; x += 5) tft.drawFastVLine(x, 0, h, color2);
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testRects(uint16_t color) {
|
||||
unsigned long start;
|
||||
int n, i, i2,
|
||||
cx = tft.width() / 2,
|
||||
cy = tft.height() / 2;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
start = micros();
|
||||
for (i = 2; i < n; i += 6) {
|
||||
i2 = i / 2;
|
||||
tft.drawRect(cx - i2, cy - i2, i, i, color);
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
|
||||
unsigned long start, t = 0;
|
||||
int n, i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
n = min(tft.width(), tft.height());
|
||||
for (i = n - 1; i > 0; i -= 6) {
|
||||
i2 = i / 2;
|
||||
start = micros();
|
||||
tft.fillRect(cx - i2, cy - i2, i, i, color1);
|
||||
t += micros() - start;
|
||||
// Outlines are not included in timing results
|
||||
tft.drawRect(cx - i2, cy - i2, i, i, color2);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
|
||||
unsigned long start;
|
||||
int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
start = micros();
|
||||
for (x = radius; x < w; x += r2) {
|
||||
for (y = radius; y < h; y += r2) {
|
||||
tft.fillCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testCircles(uint8_t radius, uint16_t color) {
|
||||
unsigned long start;
|
||||
int x, y, r2 = radius * 2,
|
||||
w = tft.width() + radius,
|
||||
h = tft.height() + radius;
|
||||
|
||||
// Screen is not cleared for this one -- this is
|
||||
// intentional and does not affect the reported time.
|
||||
start = micros();
|
||||
for (x = 0; x < w; x += r2) {
|
||||
for (y = 0; y < h; y += r2) {
|
||||
tft.drawCircle(x, y, radius, color);
|
||||
}
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testTriangles() {
|
||||
unsigned long start;
|
||||
int n, i, cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
n = min(cx, cy);
|
||||
start = micros();
|
||||
for (i = 0; i < n; i += 5) {
|
||||
tft.drawTriangle(
|
||||
cx , cy - i, // peak
|
||||
cx - i, cy + i, // bottom left
|
||||
cx + i, cy + i, // bottom right
|
||||
tft.color565(0, 0, i));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledTriangles() {
|
||||
unsigned long start, t = 0;
|
||||
int i, cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
start = micros();
|
||||
for (i = min(cx, cy); i > 10; i -= 5) {
|
||||
start = micros();
|
||||
tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(0, i, i));
|
||||
t += micros() - start;
|
||||
tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
|
||||
tft.color565(i, i, 0));
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
unsigned long testRoundRects() {
|
||||
unsigned long start;
|
||||
int w, i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
w = min(tft.width(), tft.height());
|
||||
start = micros();
|
||||
for (i = 0; i < w; i += 6) {
|
||||
i2 = i / 2;
|
||||
tft.drawRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.color565(i, 0, 0));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
unsigned long testFilledRoundRects() {
|
||||
unsigned long start;
|
||||
int i, i2,
|
||||
cx = tft.width() / 2 - 1,
|
||||
cy = tft.height() / 2 - 1;
|
||||
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
start = micros();
|
||||
for (i = min(tft.width(), tft.height()); i > 20; i -= 6) {
|
||||
i2 = i / 2;
|
||||
tft.fillRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.color565(0, i, 0));
|
||||
}
|
||||
|
||||
return micros() - start;
|
||||
}
|
||||
|
||||
/***************************************************
|
||||
Original Adafruit text:
|
||||
|
||||
This is an example sketch for the Adafruit 2.2" SPI display.
|
||||
This library works with the Adafruit 2.2" TFT Breakout w/SD card
|
||||
----> http://www.adafruit.com/products/1480
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional)
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
334
libraries/TFT_eSPI/examples/320 x 240/UTFT_demo/UTFT_demo.ino
Normal file
334
libraries/TFT_eSPI/examples/320 x 240/UTFT_demo/UTFT_demo.ino
Normal file
@@ -0,0 +1,334 @@
|
||||
// Demo based on:
|
||||
// UTFT_Demo_320x240 by Henning Karlsen
|
||||
// web: http://www.henningkarlsen.com/electronics
|
||||
//
|
||||
/*
|
||||
|
||||
This sketch uses the GLCD and font 2 only.
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
#include "SPI.h"
|
||||
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
#define TFT_GREY 0x7BEF
|
||||
|
||||
TFT_eSPI myGLCD = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
unsigned long runTime = 0;
|
||||
void setup()
|
||||
{
|
||||
randomSeed(analogRead(A0));
|
||||
// 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[318];
|
||||
int x, x2;
|
||||
int y, y2;
|
||||
int r;
|
||||
runTime = millis();
|
||||
// Clear the screen and draw the frame
|
||||
myGLCD.fillScreen(TFT_BLACK);
|
||||
|
||||
|
||||
myGLCD.fillRect(0, 0, 319, 14,TFT_RED);
|
||||
|
||||
myGLCD.fillRect(0, 226, 319, 14,TFT_GREY);
|
||||
|
||||
myGLCD.setTextColor(TFT_BLACK,TFT_RED);
|
||||
myGLCD.drawCentreString("* TFT_eSPI *", 160, 4, 1);
|
||||
myGLCD.setTextColor(TFT_YELLOW,TFT_GREY);
|
||||
myGLCD.drawCentreString("Adapted by Bodmer", 160, 228,1);
|
||||
|
||||
myGLCD.drawRect(0, 14, 319, 211, TFT_BLUE);
|
||||
|
||||
// Draw crosshairs
|
||||
myGLCD.drawLine(159, 15, 159, 224,TFT_BLUE);
|
||||
myGLCD.drawLine(1, 119, 318, 119,TFT_BLUE);
|
||||
for (int i=9; i<310; i+=10)
|
||||
myGLCD.drawLine(i, 117, i, 121,TFT_BLUE);
|
||||
for (int i=19; i<220; i+=10)
|
||||
myGLCD.drawLine(157, i, 161, i,TFT_BLUE);
|
||||
|
||||
// Draw sin-, cos- and tan-lines
|
||||
myGLCD.setTextColor(TFT_CYAN);
|
||||
myGLCD.drawString("Sin", 5, 15,2);
|
||||
for (int i=1; i<318; i++)
|
||||
{
|
||||
myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95),TFT_CYAN);
|
||||
}
|
||||
myGLCD.setTextColor(TFT_RED);
|
||||
myGLCD.drawString("Cos", 5, 30,2);
|
||||
for (int i=1; i<318; i++)
|
||||
{
|
||||
myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95),TFT_RED);
|
||||
}
|
||||
myGLCD.setTextColor(TFT_YELLOW);
|
||||
myGLCD.drawString("Tan", 5, 45,2);
|
||||
for (int i=1; i<318; i++)
|
||||
{
|
||||
myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)),TFT_YELLOW);
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
myGLCD.drawLine(159, 15, 159, 224,TFT_BLUE);
|
||||
myGLCD.drawLine(1, 119, 318, 119,TFT_BLUE);
|
||||
int col = 0;
|
||||
// Draw a moving sinewave
|
||||
x=1;
|
||||
for (int i=1; i<(317*20); i++)
|
||||
{
|
||||
x++;
|
||||
if (x==318)
|
||||
x=1;
|
||||
if (i>318)
|
||||
{
|
||||
if ((x==159)||(buf[x-1]==119))
|
||||
col = TFT_BLUE;
|
||||
else
|
||||
myGLCD.drawPixel(x,buf[x-1],TFT_BLACK);
|
||||
}
|
||||
y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100)));
|
||||
myGLCD.drawPixel(x,y,TFT_BLUE);
|
||||
buf[x-1]=y;
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
// Draw some filled rectangles
|
||||
for (int i=1; i<6; i++)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 1:
|
||||
col = TFT_MAGENTA;
|
||||
break;
|
||||
case 2:
|
||||
col = TFT_RED;
|
||||
break;
|
||||
case 3:
|
||||
col = TFT_GREEN;
|
||||
break;
|
||||
case 4:
|
||||
col = TFT_BLUE;
|
||||
break;
|
||||
case 5:
|
||||
col = TFT_YELLOW;
|
||||
break;
|
||||
}
|
||||
myGLCD.fillRect(70+(i*20), 30+(i*20), 60, 60,col);
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
// Draw some filled, rounded rectangles
|
||||
for (int i=1; i<6; i++)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 1:
|
||||
col = TFT_MAGENTA;
|
||||
break;
|
||||
case 2:
|
||||
col = TFT_RED;
|
||||
break;
|
||||
case 3:
|
||||
col = TFT_GREEN;
|
||||
break;
|
||||
case 4:
|
||||
col = TFT_BLUE;
|
||||
break;
|
||||
case 5:
|
||||
col = TFT_YELLOW;
|
||||
break;
|
||||
}
|
||||
myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 60,60, 3,col);
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
// Draw some filled circles
|
||||
for (int i=1; i<6; i++)
|
||||
{
|
||||
switch (i)
|
||||
{
|
||||
case 1:
|
||||
col = TFT_MAGENTA;
|
||||
break;
|
||||
case 2:
|
||||
col = TFT_RED;
|
||||
break;
|
||||
case 3:
|
||||
col = TFT_GREEN;
|
||||
break;
|
||||
case 4:
|
||||
col = TFT_BLUE;
|
||||
break;
|
||||
case 5:
|
||||
col = TFT_YELLOW;
|
||||
break;
|
||||
}
|
||||
myGLCD.fillCircle(100+(i*20),60+(i*20), 30,col);
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
// Draw some lines in a pattern
|
||||
|
||||
for (int i=15; i<224; i+=5)
|
||||
{
|
||||
myGLCD.drawLine(1, i, (i*1.44)-10, 223,TFT_RED);
|
||||
}
|
||||
|
||||
for (int i=223; i>15; i-=5)
|
||||
{
|
||||
myGLCD.drawLine(317, i, (i*1.44)-11, 15,TFT_RED);
|
||||
}
|
||||
|
||||
for (int i=223; i>15; i-=5)
|
||||
{
|
||||
myGLCD.drawLine(1, i, 331-(i*1.44), 15,TFT_CYAN);
|
||||
}
|
||||
|
||||
for (int i=15; i<224; i+=5)
|
||||
{
|
||||
myGLCD.drawLine(317, i, 330-(i*1.44), 223,TFT_CYAN);
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
// Draw some random circles
|
||||
for (int i=0; i<100; i++)
|
||||
{
|
||||
x=32+random(256);
|
||||
y=45+random(146);
|
||||
r=random(30);
|
||||
myGLCD.drawCircle(x, y, r,random(0xFFFF));
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
// Draw some random rectangles
|
||||
for (int i=0; i<100; i++)
|
||||
{
|
||||
x=2+random(316);
|
||||
y=16+random(207);
|
||||
x2=2+random(316);
|
||||
y2=16+random(207);
|
||||
if (x2<x) {
|
||||
r=x;x=x2;x2=r;
|
||||
}
|
||||
if (y2<y) {
|
||||
r=y;y=y2;y2=r;
|
||||
}
|
||||
myGLCD.drawRect(x, y, x2-x, y2-y,random(0xFFFF));
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
// Draw some random rounded rectangles
|
||||
for (int i=0; i<100; i++)
|
||||
{
|
||||
x=2+random(316);
|
||||
y=16+random(207);
|
||||
x2=2+random(316);
|
||||
y2=16+random(207);
|
||||
// We need to get the width and height and do some window checking
|
||||
if (x2<x) {
|
||||
r=x;x=x2;x2=r;
|
||||
}
|
||||
if (y2<y) {
|
||||
r=y;y=y2;y2=r;
|
||||
}
|
||||
// We need a minimum size of 6
|
||||
if((x2-x)<6) x2=x+6;
|
||||
if((y2-y)<6) y2=y+6;
|
||||
myGLCD.drawRoundRect(x, y, x2-x,y2-y, 3,random(0xFFFF));
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
//randomSeed(1234);
|
||||
int colour = 0;
|
||||
for (int i=0; i<100; i++)
|
||||
{
|
||||
x=2+random(316);
|
||||
y=16+random(209);
|
||||
x2=2+random(316);
|
||||
y2=16+random(209);
|
||||
colour=random(0xFFFF);
|
||||
myGLCD.drawLine(x, y, x2, y2,colour);
|
||||
}
|
||||
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillRect(1,15,317,209,TFT_BLACK);
|
||||
|
||||
// This test has been modified as it takes more time to calculate the random numbers
|
||||
// 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
|
||||
// use the coords as the colour to produce the banding
|
||||
//byte i = 100;
|
||||
//while (i--) {
|
||||
// byte j = 100;
|
||||
// while (j--) myGLCD.drawPixel(i+110,j+70,i+j);
|
||||
// //while (j--) myGLCD.drawPixel(i+110,j+70,0xFFFF);
|
||||
//}
|
||||
delay(0);
|
||||
|
||||
myGLCD.fillScreen(TFT_BLUE);
|
||||
myGLCD.fillRoundRect(80, 70, 239-80,169-70, 3,TFT_RED);
|
||||
|
||||
myGLCD.setTextColor(TFT_WHITE,TFT_RED);
|
||||
myGLCD.drawCentreString("That's it!", 160, 93,2);
|
||||
myGLCD.drawCentreString("Restarting in a", 160, 119,2);
|
||||
myGLCD.drawCentreString("few seconds...", 160, 132,2);
|
||||
|
||||
runTime = millis()-runTime;
|
||||
myGLCD.setTextColor(TFT_GREEN,TFT_BLUE);
|
||||
myGLCD.drawCentreString("Runtime: (msecs)", 160, 210,2);
|
||||
myGLCD.setTextDatum(TC_DATUM);
|
||||
myGLCD.drawNumber(runTime, 160, 225,2);
|
||||
delay (5000);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user