First draft release

Not yet fully tested but seems to work OK!
This commit is contained in:
Bodmer committed 2017-02-22 03:07:17 +00:00
1 parent 357665d9b5
commit e1b2959577
144 files changed
+94409

No files matched your search

@@ -0,0 +1,442 @@
// Adapted by Bodmer to work with a NodeMCU and ILI9341 or ST7735 display.
//
// This code currently does not "blink" the eye!
//
// Library used is here:
// https://github.com/Bodmer/TFT_eSPI
//
// To do, maybe, one day:
// 1. Get the eye to blink
// 2. Add another screen for another eye
// 3. Add varaible to set how wide open the eye is
// 4. Add a reflected highlight to the cornea
// 5. Add top eyelid shaddow to eye surface
// 6. Add aliasing to blur mask edge
//
// With one lidded eye drawn the code runs at 28-33fps (at 27-40MHz SPI clock)
// which is quite reasonable. Operation at an 80MHz SPI clock is possible but
// the display may not be able to cope with a clock rate that high and the
// performance improvement is small. Operate the ESP8266 at 160MHz for best
// frame rate. Note the images are stored in SPI FLASH (PROGMEM) so performance
// will be constrained by the increased memory access time.
// Original header for this sketch is below. Note: the technical aspects of the
// text no longer apply to this modified version of the sketch:
/*
//--------------------------------------------------------------------------
// Uncanny eyes for PJRC Teensy 3.1 with Adafruit 1.5" OLED (product #1431)
// or 1.44" eye[e].tft LCD (#2088). This uses Teensy-3.1-specific features and
// WILL NOT work on normal Arduino or other boards! Use 72 MHz (Optimized)
// board speed -- OLED does not work at 96 MHz.
//
// Adafruit invests time and resources providing this open source code,
// please support Adafruit and open-source hardware by purchasing products
// from Adafruit!
//
// Written by Phil Burgess / Paint Your Dragon for Adafruit Industries.
// MIT license. SPI FIFO insight from Paul Stoffregen's ILI9341_t3 library.
// Inspired by David Boccabella's (Marcwolf) hybrid servo/OLED eye concept.
//--------------------------------------------------------------------------
*/
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
// Enable ONE of these #includes for the various eyes:
#include "defaultEye.h" // Standard human-ish hazel eye
//#include "noScleraEye.h" // Large iris, no sclera
//#include "dragonEye.h" // Slit pupil fiery dragon/demon eye
//#include "goatEye.h" // Horizontal pupil goat/Krampus eye
#define DISPLAY_DC D3 // Data/command pin for BOTH displays
#define DISPLAY_RESET D4 // Reset pin for BOTH displays
#define SELECT_L_PIN D8 // LEFT eye chip select pin
#define SELECT_R_PIN D8 // RIGHT eye chip select pin
// INPUT CONFIG (for eye motion -- enable or comment out as needed) --------
// The ESP8266 is rather constrained here as it only has one analogue port.
// An I2C ADC could be used for more analogue channels
//#define JOYSTICK_X_PIN A0 // Analog pin for eye horiz pos (else auto)
//#define JOYSTICK_Y_PIN A0 // Analog pin for eye vert position (")
//#define JOYSTICK_X_FLIP // If set, reverse stick X axis
//#define JOYSTICK_Y_FLIP // If set, reverse stick Y axis
#define TRACKING // If enabled, eyelid tracks pupil
//#define IRIS_PIN A0 // Photocell or potentiometer (else auto iris)
//#define IRIS_PIN_FLIP // If set, reverse reading from dial/photocell
//#define IRIS_SMOOTH // If enabled, filter input from IRIS_PIN
#define IRIS_MIN 140 // Clip lower analogRead() range from IRIS_PIN
#define IRIS_MAX 260 // Clip upper "
#define WINK_L_PIN 0 // Pin for LEFT eye wink button
#define BLINK_PIN 1 // Pin for blink button (BOTH eyes)
#define WINK_R_PIN 2 // Pin for RIGHT eye wink button
#define AUTOBLINK // If enabled, eyes blink autonomously
// Probably don't need to edit any config below this line, -----------------
// unless building a single-eye project (pendant, etc.), in which case one
// of the two elements in the eye[] array further down can be commented out.
// Eye blinks are a tiny 3-state machine. Per-eye allows winks + blinks.
#define NOBLINK 0 // Not currently engaged in a blink
#define ENBLINK 1 // Eyelid is currently closing
#define DEBLINK 2 // Eyelid is currently opening
typedef struct {
int8_t pin; // Optional button here for indiv. wink
uint8_t state; // NOBLINK/ENBLINK/DEBLINK
int32_t duration; // Duration of blink state (micros)
uint32_t startTime; // Time (micros) of last state change
} eyeBlink;
struct {
TFT_eSPI tft; // OLED/eye[e].tft object
uint8_t cs; // Chip select pin
eyeBlink blink; // Current blink state
} eye[] = { // OK to comment out one of these for single-eye display:
TFT_eSPI(),SELECT_L_PIN,{WINK_L_PIN,NOBLINK},
//TFT_eSPI(),SELECT_R_PIN,{WINK_R_PIN,NOBLINK},
};
#define NUM_EYES (sizeof(eye) / sizeof(eye[0]))
uint32_t fstart = 0; // start time to improve frame rate calculation at startup
// INITIALIZATION -- runs once at startup ----------------------------------
void setup(void) {
uint8_t e = 0;
Serial.begin(250000);
randomSeed(analogRead(A0)); // Seed random() from floating analog input
eye[e].tft.init();
eye[e].tft.fillScreen(TFT_BLACK);
eye[e].tft.setRotation(0);
fstart = millis()-1; // Subtract 1 to avoid divide by zero later
}
// EYE-RENDERING FUNCTION --------------------------------------------------
#define BUFFER_SIZE 256 // 64 to 512 seems optimum = 30 fps for default eye
void drawEye( // Renders one eye. Inputs must be pre-clipped & valid.
// Use native 32 bit variables where possible as this is 10% faster!
uint8_t e, // Eye array index; 0 or 1 for left/right
uint32_t iScale, // Scale factor for iris
uint32_t scleraX, // First pixel X offset into sclera image
uint32_t scleraY, // First pixel Y offset into sclera image
uint32_t uT, // Upper eyelid threshold value
uint32_t lT) { // Lower eyelid threshold value
uint32_t screenX, screenY, scleraXsave;
int32_t irisX, irisY;
uint32_t p, a;
uint32_t d;
uint32_t pixels = 0;
uint16_t pbuffer[BUFFER_SIZE]; // This one needs to be 16 bit
// Set up raw pixel dump to entire screen. Although such writes can wrap
// around automatically from end of rect back to beginning, the region is
// reset on each frame here in case of an SPI glitch.
//eye[e].tft.setAddrWindow(319-127, 0, 319, 127);
eye[e].tft.setAddrWindow(0, 0, 127, 127);
//digitalWrite(eye[e].cs, LOW); // Chip select
// Now just issue raw 16-bit values for every pixel...
scleraXsave = scleraX; // Save initial X value to reset on each line
irisY = scleraY - (SCLERA_HEIGHT - IRIS_HEIGHT) / 2;
for(screenY=0; screenY<SCREEN_HEIGHT; screenY++, scleraY++, irisY++) {
scleraX = scleraXsave;
irisX = scleraXsave - (SCLERA_WIDTH - IRIS_WIDTH) / 2;
for(screenX=0; screenX<SCREEN_WIDTH; screenX++, scleraX++, irisX++) {
if((pgm_read_byte(lower + screenY * SCREEN_WIDTH + screenX) <= lT) ||
(pgm_read_byte(upper + screenY * SCREEN_WIDTH + screenX) <= uT)) { // Covered by eyelid
p = 0;
} else if((irisY < 0) || (irisY >= IRIS_HEIGHT) ||
(irisX < 0) || (irisX >= IRIS_WIDTH)) { // In sclera
p = pgm_read_word(sclera + scleraY * SCLERA_WIDTH + scleraX);
} else { // Maybe iris...
p = pgm_read_word(polar + irisY * IRIS_WIDTH + irisX); // Polar angle/dist
d = (iScale * (p & 0x7F)) / 128; // Distance (Y)
if(d < IRIS_MAP_HEIGHT) { // Within iris area
a = (IRIS_MAP_WIDTH * (p >> 7)) / 512; // Angle (X)
p = pgm_read_word(iris + d * IRIS_MAP_WIDTH + a); // Pixel = iris
} else { // Not in iris
p = pgm_read_word(sclera + scleraY * SCLERA_WIDTH + scleraX); // Pixel = sclera
}
}
*(pbuffer + pixels++) = p>>8 | p<<8;
if (pixels >= BUFFER_SIZE) { yield(); eye[e].tft.pushColors((uint8_t*)pbuffer, pixels*2); pixels = 0;}
}
}
if (pixels) { eye[e].tft.pushColors(pbuffer, pixels); pixels = 0;}
}
// EYE ANIMATION -----------------------------------------------------------
const uint8_t ease[] = { // Ease in/out curve for eye movements 3*t^2-2*t^3
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, // T
3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 9, 10, 10, // h
11, 12, 12, 13, 14, 15, 15, 16, 17, 18, 18, 19, 20, 21, 22, 23, // x
24, 25, 26, 27, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, // 2
40, 41, 42, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 56, 57, 58, // A
60, 61, 62, 63, 65, 66, 67, 69, 70, 72, 73, 74, 76, 77, 78, 80, // l
81, 83, 84, 85, 87, 88, 90, 91, 93, 94, 96, 97, 98,100,101,103, // e
104,106,107,109,110,112,113,115,116,118,119,121,122,124,125,127, // c
128,130,131,133,134,136,137,139,140,142,143,145,146,148,149,151, // J
152,154,155,157,158,159,161,162,164,165,167,168,170,171,172,174, // a
175,177,178,179,181,182,183,185,186,188,189,190,192,193,194,195, // c
197,198,199,201,202,203,204,205,207,208,209,210,211,213,214,215, // o
216,217,218,219,220,221,222,224,225,226,227,228,228,229,230,231, // b
232,233,234,235,236,237,237,238,239,240,240,241,242,243,243,244, // s
245,245,246,246,247,248,248,249,249,250,250,251,251,251,252,252, // o
252,253,253,253,254,254,254,254,254,255,255,255,255,255,255,255 }; // n
#ifdef AUTOBLINK
uint32_t timeOfLastBlink = 0L, timeToNextBlink = 0L;
#endif
void frame( // Process motion for a single frame of left or right eye
uint32_t iScale) { // Iris scale (0-1023) passed in
static uint32_t frames = 0; // Used in frame rate calculation
static uint8_t eyeIndex = 0; // eye[] array counter
int32_t eyeX, eyeY;
uint32_t t = micros(); // Time at start of function
Serial.print((++frames * 1000) / (millis() - fstart)); Serial.println("fps");// Show frame rate
if(++eyeIndex >= NUM_EYES) eyeIndex = 0; // Cycle through eyes, 1 per call
// Autonomous X/Y eye motion
// Periodically initiates motion to a new random point, random speed,
// holds there for random period until next motion.
static boolean eyeInMotion = false;
static int32_t eyeOldX=512, eyeOldY=512, eyeNewX=512, eyeNewY=512;
static uint32_t eyeMoveStartTime = 0L;
static int32_t eyeMoveDuration = 0L;
int32_t dt = t - eyeMoveStartTime; // uS elapsed since last eye event
if(eyeInMotion) { // Currently moving?
if(dt >= eyeMoveDuration) { // Time up? Destination reached.
eyeInMotion = false; // Stop moving
eyeMoveDuration = random(3000000L); // 0-3 sec stop
eyeMoveStartTime = t; // Save initial time of stop
eyeX = eyeOldX = eyeNewX; // Save position
eyeY = eyeOldY = eyeNewY;
} else { // Move time's not yet fully elapsed -- interpolate position
int16_t e = ease[255 * dt / eyeMoveDuration] + 1; // Ease curve
eyeX = eyeOldX + (((eyeNewX - eyeOldX) * e) / 256); // Interp X
eyeY = eyeOldY + (((eyeNewY - eyeOldY) * e) / 256); // and Y
}
} else { // Eye stopped
eyeX = eyeOldX;
eyeY = eyeOldY;
if(dt > eyeMoveDuration) { // Time up? Begin new move.
int16_t dx, dy;
uint32_t d;
do { // Pick new dest in circle
eyeNewX = random(1024);
eyeNewY = random(1024);
dx = (eyeNewX * 2) - 1023;
dy = (eyeNewY * 2) - 1023;
} while((d = (dx * dx + dy * dy)) > (1023 * 1023)); // Keep trying
eyeMoveDuration = random(50000, 150000);//random(72000, 144000); // ~1/14 - ~1/7 sec
eyeMoveStartTime = t; // Save initial time of move
eyeInMotion = true; // Start move on next frame
}
}
// Blinking
/*
#ifdef AUTOBLINK
// Similar to the autonomous eye movement above -- blink start times
// and durations are random (within ranges).
if((t - timeOfLastBlink) >= timeToNextBlink) { // Start new blink?
timeOfLastBlink = t;
uint32_t blinkDuration = random(36000, 72000); // ~1/28 - ~1/14 sec
// Set up durations for both eyes (if not already winking)
for(uint8_t e=0; e<NUM_EYES; e++) {
if(eye[e].blink.state == NOBLINK) {
eye[e].blink.state = ENBLINK;
eye[e].blink.startTime = t;
eye[e].blink.duration = blinkDuration;
}
}
timeToNextBlink = blinkDuration * 3 + random(4000000);
}
#endif
*/
/*
if(eye[eyeIndex].blink.state) { // Eye currently blinking?
// Check if current blink state time has elapsed
if((t - eye[eyeIndex].blink.startTime) >= eye[eyeIndex].blink.duration) {
// Yes -- increment blink state, unless...
if((eye[eyeIndex].blink.state == ENBLINK) && // Enblinking and...
((digitalRead(BLINK_PIN) == LOW) || // blink or wink held...
digitalRead(eye[eyeIndex].blink.pin) == LOW)) {
// Don't advance state yet -- eye is held closed instead
} else { // No buttons, or other state...
if(++eye[eyeIndex].blink.state > DEBLINK) { // Deblinking finished?
eye[eyeIndex].blink.state = NOBLINK; // No longer blinking
} else { // Advancing from ENBLINK to DEBLINK mode
eye[eyeIndex].blink.duration *= 2; // DEBLINK is 1/2 ENBLINK speed
eye[eyeIndex].blink.startTime = t;
}
}
}
} else { // Not currently blinking...check buttons!
if(digitalRead(BLINK_PIN) == LOW) {
// Manually-initiated blinks have random durations like auto-blink
uint32_t blinkDuration = random(36000, 72000);
for(uint8_t e=0; e<NUM_EYES; e++) {
if(eye[e].blink.state == NOBLINK) {
eye[e].blink.state = ENBLINK;
eye[e].blink.startTime = t;
eye[e].blink.duration = blinkDuration;
}
}
} else if(digitalRead(eye[eyeIndex].blink.pin) == LOW) { // Wink!
eye[eyeIndex].blink.state = ENBLINK;
eye[eyeIndex].blink.startTime = t;
eye[eyeIndex].blink.duration = random(45000, 90000);
}
}
*/
// Process motion, blinking and iris scale into renderable values
// Iris scaling: remap from 0-1023 input to iris map height pixel units
iScale = ((IRIS_MAP_HEIGHT + 1) * 1024) /
(1024 - (iScale * (IRIS_MAP_HEIGHT - 1) / IRIS_MAP_HEIGHT));
// Scale eye X/Y positions (0-1023) to pixel units used by drawEye()
eyeX = map(eyeX, 0, 1023, 0, SCLERA_WIDTH - 128);
eyeY = map(eyeY, 0, 1023, 0, SCLERA_HEIGHT - 128);
if(eyeIndex == 1) eyeX = (SCLERA_WIDTH - 128) - eyeX; // Mirrored display
// Horizontal position is offset so that eyes are very slightly crossed
// to appear fixated (converged) at a conversational distance. Number
// here was extracted from my posterior and not mathematically based.
// I suppose one could get all clever with a range sensor, but for now...
eyeX += 4;
if(eyeX > (SCLERA_WIDTH - 128)) eyeX = (SCLERA_WIDTH - 128);
// Eyelids are rendered using a brightness threshold image. This same
// map can be used to simplify another problem: making the upper eyelid
// track the pupil (eyes tend to open only as much as needed -- e.g. look
// down and the upper eyelid drops). Just sample a point in the upper
// lid map slightly above the pupil to determine the rendering threshold.
static uint8_t uThreshold = 128;
uint8_t lThreshold, n;
#ifdef TRACKING
int16_t sampleX = SCLERA_WIDTH / 2 - (eyeX / 2), // Reduce X influence
sampleY = SCLERA_HEIGHT / 2 - (eyeY + IRIS_HEIGHT / 4);
// Eyelid is slightly asymmetrical, so two readings are taken, averaged
if(sampleY < 0) n = 0;
else n = (pgm_read_byte(upper + sampleY * SCREEN_WIDTH + sampleX) +
pgm_read_byte(upper + sampleY * SCREEN_WIDTH + (SCREEN_WIDTH - 1 - sampleX))) / 2;
uThreshold = (uThreshold * 3 + n) / 4; // Filter/soften motion
// Lower eyelid doesn't track the same way, but seems to be pulled upward
// by tension from the upper lid.
lThreshold = 254 - uThreshold;
#else // No tracking -- eyelids full open unless blink modifies them
uThreshold = lThreshold = 0;
#endif
// The upper/lower thresholds are then scaled relative to the current
// blink position so that blinks work together with pupil tracking.
if(eye[eyeIndex].blink.state) { // Eye currently blinking?
uint32_t s = (t - eye[eyeIndex].blink.startTime);
if(s >= eye[eyeIndex].blink.duration) s = 255; // At or past blink end
else s = 255 * s / eye[eyeIndex].blink.duration; // Mid-blink
s = (eye[eyeIndex].blink.state == DEBLINK) ? 1 + s : 256 - s;
n = (uThreshold * s + 254 * (257 - s)) / 256;
lThreshold = (lThreshold * s + 254 * (257 - s)) / 256;
} else {
n = uThreshold;
}
// Pass all the derived values to the eye-rendering function:
drawEye(eyeIndex, iScale, eyeX, eyeY, n, lThreshold);
}
// AUTONOMOUS IRIS SCALING (if no photocell or dial) -----------------------
#if !defined(IRIS_PIN) || (IRIS_PIN < 0)
// Autonomous iris motion uses a fractal behavior to similate both the major
// reaction of the eye plus the continuous smaller adjustments that occur.
uint16_t oldIris = (IRIS_MIN + IRIS_MAX) / 2, newIris;
void split( // Subdivides motion path into two sub-paths w/randimization
int16_t startValue, // Iris scale value (IRIS_MIN to IRIS_MAX) at start
int16_t endValue, // Iris scale value at end
uint32_t startTime, // micros() at start
int32_t duration, // Start-to-end time, in microseconds
int16_t range) { // Allowable scale value variance when subdividing
if(range >= 8) { // Limit subdvision count, because recursion
range /= 2; // Split range & time in half for subdivision,
duration /= 2; // then pick random center point within range:
int16_t midValue = (startValue + endValue - range) / 2 + random(range);
uint32_t midTime = startTime + duration;
split(startValue, midValue, startTime, duration, range); // First half
split(midValue , endValue, midTime , duration, range); // Second half
} else { // No more subdivisons, do iris motion...
int32_t dt; // Time (micros) since start of motion
int16_t v; // Interim value
while((dt = (micros() - startTime)) < duration) {
v = startValue + (((endValue - startValue) * dt) / duration);
if(v < IRIS_MIN) v = IRIS_MIN; // Clip just in case
else if(v > IRIS_MAX) v = IRIS_MAX;
frame(v); // Draw frame w/interim iris scale value
}
}
}
#endif // !IRIS_PIN
// MAIN LOOP -- runs continuously after setup() ----------------------------
void loop() {
#if defined(IRIS_PIN) && (IRIS_PIN >= 0) // Interactive iris
uint16_t v = 512; //analogRead(IRIS_PIN); // Raw dial/photocell reading
#ifdef IRIS_PIN_FLIP
v = 1023 - v;
#endif
v = map(v, 0, 1023, IRIS_MIN, IRIS_MAX); // Scale to iris range
#ifdef IRIS_SMOOTH // Filter input (gradual motion)
static uint16_t irisValue = (IRIS_MIN + IRIS_MAX) / 2;
irisValue = ((irisValue * 15) + v) / 16;
frame(irisValue);
#else // Unfiltered (immediate motion)
frame(v);
#endif // IRIS_SMOOTH
#else // Autonomous iris scaling -- invoke recursive function
newIris = random(IRIS_MIN, IRIS_MAX);
split(oldIris, newIris, micros(), 10000000L, IRIS_MAX - IRIS_MIN);
oldIris = newIris;
#endif // IRIS_PIN
//screenshotToConsole();
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,220 @@
// Include code in this tab and call screenshotToConsole() this dumps an
// image off the screen and sends it to a PC via the serial port in a Run
// Length Encoded format for viewing with a "ILIScreenshotViewer" utility.
// The PC "ILIScreenshotViewer" is part of the ILI9241_due library in the
// Tools folder, that library can be found here:
// https://github.com/marekburiak/ILI9341_Due
// Converted by Bodmer to operate with the TFT_ILI9341_ESP library:
// https://github.com/Bodmer/TFT_ILI9341_ESP
/*
The functions below have been adapted from the ILI9341_due library, the file
header from the .cpp source file is included below:
ILI9341_due_.cpp - Arduino Due library for interfacing with ILI9341-based TFTs
Copyright (c) 2014 Marek Buriak
This library is based on ILI9341_t3 library from Paul Stoffregen
(https://github.com/PaulStoffregen/ILI9341_t3), Adafruit_ILI9341
and Adafruit_GFX libraries from Limor Fried/Ladyada
(https://github.com/adafruit/Adafruit_ILI9341).
This file is part of the Arduino ILI9341_due library.
Sources for this library can be found at https://github.com/marekburiak/ILI9341_Due.
ILI9341_due is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
ILI9341_due is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details:
<http://www.gnu.org/licenses/>.
*/
//====================================================================================
void screenshotToConsole()
{
uint8_t e = 0;
uint8_t lastColor[3];
uint8_t color[3];
uint32_t sameColorPixelCount = 0;
uint16_t sameColorPixelCount16 = 0;
uint32_t sameColorStartIndex = 0;
uint32_t totalImageDataLength = 0;
// delay(1000);
// Header text
Serial.println((eye[e].tft.width() - 1));
Serial.println((eye[e].tft.height() - 1));
Serial.println(F("==== PIXEL DATA START ===="));
// Get first pixel to prime the Run Length Encoded
// Function format is: tft.readRectRGB( x, y, width, height, buffer);
// color is a pointer to a buffer that the RGB 8 bit values are piped into
// the buffer size must be >= (width * height * 3) bytes
eye[e].tft.readRectRGB(0, 0, 1, 1, color); // 1 x 1 so reading 1 pixel at 0,0
lastColor[0] = color[0]; // Red
lastColor[1] = color[1]; // Green
lastColor[2] = color[2]; // Blue
printHex8(color, 3); //Send color of the first pixel to serial port
totalImageDataLength += 6;
sameColorStartIndex = 0;
for (uint32_t py = 0; py < (eye[e].tft.height() - 1); py++)
{
for (uint32_t px = 0; px < (eye[e].tft.width() - 1); px++)
{
uint32_t i = px + eye[e].tft.width() * py;
yield();
if (i)
{
eye[e].tft.readRectRGB(px, py, 1, 1, color);
if (color[0] != lastColor[0] ||
color[1] != lastColor[1] ||
color[2] != lastColor[2])
{
sameColorPixelCount = i - sameColorStartIndex;
if (sameColorPixelCount > 65535)
{
sameColorPixelCount16 = 65535;
printHex16(&sameColorPixelCount16, 1);
printHex8(lastColor, 3);
totalImageDataLength += 10;
sameColorPixelCount16 = sameColorPixelCount - 65535;
}
else
sameColorPixelCount16 = sameColorPixelCount;
printHex16(&sameColorPixelCount16, 1);
printHex8(color, 3);
totalImageDataLength += 10;
sameColorStartIndex = i;
lastColor[0] = color[0];
lastColor[1] = color[1];
lastColor[2] = color[2];
}
}
}
}
sameColorPixelCount = (uint32_t)eye[e].tft.width() * (uint32_t)eye[e].tft.height() - sameColorStartIndex;
if (sameColorPixelCount > 65535)
{
sameColorPixelCount16 = 65535;
printHex16(&sameColorPixelCount16, 1);
printHex8(lastColor, 3);
totalImageDataLength += 10;
sameColorPixelCount16 = sameColorPixelCount - 65535;
}
else
sameColorPixelCount16 = sameColorPixelCount;
printHex16(&sameColorPixelCount16, 1);
totalImageDataLength += 4;
printHex32(&totalImageDataLength, 1);
// Footer text
Serial.println();
Serial.println(F("==== PIXEL DATA END ===="));
Serial.print(F("Total Image Data Length: "));
Serial.println(totalImageDataLength);
}
void printHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex
{
char tmp[length * 2 + 1];
byte first;
byte second;
for (int i = 0; i < length; i++) {
first = (data[i] >> 4) & 0x0f;
second = data[i] & 0x0f;
// base for converting single digit numbers to ASCII is 48
// base for 10-16 to become upper-case characters A-F is 55
// note: difference is 7
tmp[i * 2] = first + 48;
tmp[i * 2 + 1] = second + 48;
if (first > 9) tmp[i * 2] += 7;
if (second > 9) tmp[i * 2 + 1] += 7;
}
tmp[length * 2] = 0;
Serial.print(tmp);
}
void printHex16(uint16_t *data, uint8_t length) // prints 8-bit data in hex
{
char tmp[length * 4 + 1];
byte first;
byte second;
byte third;
byte fourth;
for (int i = 0; i < length; i++) {
first = (data[i] >> 12) & 0x0f;
second = (data[i] >> 8) & 0x0f;
third = (data[i] >> 4) & 0x0f;
fourth = data[i] & 0x0f;
//Serial << first << " " << second << " " << third << " " << fourth << endl;
// base for converting single digit numbers to ASCII is 48
// base for 10-16 to become upper-case characters A-F is 55
// note: difference is 7
tmp[i * 4] = first + 48;
tmp[i * 4 + 1] = second + 48;
tmp[i * 4 + 2] = third + 48;
tmp[i * 4 + 3] = fourth + 48;
//tmp[i*5+4] = 32; // add trailing space
if (first > 9) tmp[i * 4] += 7;
if (second > 9) tmp[i * 4 + 1] += 7;
if (third > 9) tmp[i * 4 + 2] += 7;
if (fourth > 9) tmp[i * 4 + 3] += 7;
}
tmp[length * 4] = 0;
Serial.print(tmp);
}
void printHex32(uint32_t *data, uint8_t length) // prints 8-bit data in hex
{
char tmp[length * 8 + 1];
byte dataByte[8];
for (int i = 0; i < length; i++) {
dataByte[0] = (data[i] >> 28) & 0x0f;
dataByte[1] = (data[i] >> 24) & 0x0f;
dataByte[2] = (data[i] >> 20) & 0x0f;
dataByte[3] = (data[i] >> 16) & 0x0f;
dataByte[4] = (data[i] >> 12) & 0x0f;
dataByte[5] = (data[i] >> 8) & 0x0f;
dataByte[6] = (data[i] >> 4) & 0x0f;
dataByte[7] = data[i] & 0x0f;
//Serial << first << " " << second << " " << third << " " << fourth << endl;
// base for converting single digit numbers to ASCII is 48
// base for 10-16 to become upper-case characters A-F is 55
// note: difference is 7
tmp[i * 4] = dataByte[0] + 48;
tmp[i * 4 + 1] = dataByte[1] + 48;
tmp[i * 4 + 2] = dataByte[2] + 48;
tmp[i * 4 + 3] = dataByte[3] + 48;
tmp[i * 4 + 4] = dataByte[4] + 48;
tmp[i * 4 + 5] = dataByte[5] + 48;
tmp[i * 4 + 6] = dataByte[6] + 48;
tmp[i * 4 + 7] = dataByte[7] + 48;
//tmp[i*5+4] = 32; // add trailing space
if (dataByte[0] > 9) tmp[i * 4] += 7;
if (dataByte[1] > 9) tmp[i * 4 + 1] += 7;
if (dataByte[2] > 9) tmp[i * 4 + 2] += 7;
if (dataByte[3] > 9) tmp[i * 4 + 3] += 7;
if (dataByte[4] > 9) tmp[i * 4 + 4] += 7;
if (dataByte[5] > 9) tmp[i * 4 + 5] += 7;
if (dataByte[6] > 9) tmp[i * 4 + 6] += 7;
if (dataByte[7] > 9) tmp[i * 4 + 7] += 7;
}
tmp[length * 8] = 0;
Serial.print(tmp);
}
@@ -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,160 @@
//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 64
#define GRIDY 48
#define CELLXY 5
#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 neighborhood
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 "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() {
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(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
#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 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 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,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,166 @@
// 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
// 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,165 @@
// 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
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(10);
}
// #########################################################################
// 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
int 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,141 @@
/*
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
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // 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);
}
+146
View File
@@ -0,0 +1,146 @@
/*
An example analogue clock using a TFT LCD screen to show the time
use of some of the drawing commands with the modified Adafruit_TFT_AS 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.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
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
boolean initial = 1;
void setup(void) {
tft.init();
tft.setRotation(2);
//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 = millis()+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,133 @@
/*
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...
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
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,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 circles
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, 6, 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
int 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;
}
+42
View File
@@ -0,0 +1,42 @@
// We need this header file to use FLASH as storage with PROGMEM directive:
#include <pgmspace.h>
// Icon width and height
const uint16_t alertWidth = 32;
const uint16_t alertHeight = 32;
// The icon file can be created with the "UTFT ImageConverter 565" bitmap to .c file creation utility, more can be pasted in here
const unsigned short alert[1024] PROGMEM={
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0840,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1080,0xAC66,0xEDE8,0xFE69,0xC4C6,0x2901,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xBCC6,0xFE68,0xFE68,0xFE6A,0xFE68,0xEDE8,0x18A1,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x8344,0xFE48,0xFE8C,0xFFDD,0xFFFF,0xFEF0,0xFE48,0xB466,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 3, 128 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1880,0xEDC7,0xFE48,0xFF99,0xFFBC,0xFF9B,0xFFBD,0xFE6A,0xFE48,0x5A23,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 4, 160 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x9BE5,0xFE28,0xFED0,0xFFBC,0xFF7A,0xFF9A,0xFF9B,0xFF35,0xFE28,0xBCA6,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 5, 192 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3962,0xFE28,0xFE28,0xFF9A,0xFF79,0xFF9A,0xFF9B,0xFF9A,0xFFBD,0xFE6B,0xFE28,0x72E3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 6, 224 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xB465,0xFE28,0xFEF2,0xFF7A,0xFF79,0xFF7A,0xFF9A,0xFF7A,0xFF7A,0xFF78,0xFE28,0xDD67,0x0860,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 7, 256 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x5A22,0xFE07,0xFE29,0xFF9B,0xFF37,0xFF58,0xFF79,0xFF79,0xFF79,0xFF58,0xFF9B,0xFEAE,0xFE07,0x93A4,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 8, 288 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xC4A5,0xFE07,0xFF15,0xFF37,0xFF36,0xAD11,0x2965,0x2965,0xCDF4,0xFF37,0xFF37,0xFF79,0xFE07,0xFE07,0x2901,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 9, 320 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7B03,0xFDE7,0xFE4B,0xFF79,0xFEF4,0xFF15,0xB552,0x2945,0x2945,0xDE55,0xFF16,0xFF15,0xFF58,0xFED1,0xFDE7,0xAC25,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 10, 352 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0840,0xDD26,0xFDE7,0xFF57,0xFED3,0xFED2,0xFEF4,0xBD93,0x2124,0x2124,0xDE75,0xFF14,0xFED3,0xFED3,0xFF7A,0xFE08,0xFDE7,0x49A2,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 11, 384 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x9BA4,0xFDC6,0xFE6E,0xFF36,0xFE90,0xFEB1,0xFED3,0xC592,0x2124,0x2124,0xE675,0xFED3,0xFEB2,0xFEB1,0xFEF3,0xFEF3,0xFDC6,0xBC45,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 12, 416 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3141,0xF5C6,0xF5C7,0xFF58,0xFE90,0xFE6F,0xFE8F,0xFEB1,0xCDB2,0x2104,0x2104,0xF6B4,0xFEB1,0xFE90,0xFE8F,0xFE90,0xFF58,0xFE0A,0xF5C6,0x72A3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 13, 448 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xABE4,0xF5A6,0xFEB1,0xFED3,0xFE4E,0xFE6E,0xFE6F,0xFE90,0xD5F2,0x18E3,0x18E3,0xFED4,0xFE90,0xFE6F,0xFE6F,0xFE6E,0xFE91,0xFF36,0xF5A6,0xCCA5,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 14, 480 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x5202,0xF5A6,0xF5C7,0xFF58,0xFE4D,0xFE4D,0xFE4D,0xFE4E,0xFE6F,0xDE11,0x18C3,0x18C3,0xFED3,0xFE6F,0xFE6E,0xFE4E,0xFE4D,0xFE4D,0xFF16,0xFE2C,0xF5A6,0x9363,0x0000,0x0000,0x0000,0x0000,0x0000, // row 15, 512 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0xBC44,0xF585,0xFED3,0xFE6F,0xFE2C,0xFE2C,0xFE2D,0xFE4D,0xFE4E,0xE630,0x10A2,0x2104,0xFED1,0xFE4E,0xFE4D,0xFE4D,0xFE2D,0xFE2C,0xFE4D,0xFF37,0xF586,0xF585,0x28E1,0x0000,0x0000,0x0000,0x0000, // row 16, 544 pixels
0x0000,0x0000,0x0000,0x0000,0x7282,0xF565,0xF5EA,0xFF16,0xFE0B,0xFE0B,0xFE0B,0xFE2C,0xFE2C,0xFE4D,0xF670,0x1082,0x2924,0xFEB0,0xFE2D,0xFE2C,0xFE2C,0xFE2C,0xFE0B,0xFE0B,0xFEB2,0xFE6F,0xF565,0xA383,0x0000,0x0000,0x0000,0x0000, // row 17, 576 pixels
0x0000,0x0000,0x0000,0x0840,0xD4C4,0xF565,0xFEF5,0xFE0C,0xFDE9,0xFDEA,0xFE0A,0xFE0B,0xFE0B,0xFE2C,0xFE8F,0x0861,0x2964,0xFE8F,0xFE2C,0xFE0B,0xFE0B,0xFE0B,0xFE0A,0xFDEA,0xFE0B,0xFF37,0xF586,0xF565,0x4181,0x0000,0x0000,0x0000, // row 18, 608 pixels
0x0000,0x0000,0x0000,0x9343,0xF545,0xF60C,0xFED3,0xFDC8,0xFDC8,0xFDC9,0xFDE9,0xFDEA,0xFDEA,0xFE0B,0xFE8E,0x0861,0x3184,0xFE6D,0xFE0B,0xFE0A,0xFDEA,0xFDEA,0xFDE9,0xFDC9,0xFDC9,0xFE4E,0xFEB2,0xF545,0xB3E3,0x0000,0x0000,0x0000, // row 19, 640 pixels
0x0000,0x0000,0x28E0,0xF544,0xF545,0xFF17,0xFDC8,0xFDA7,0xFDA7,0xFDC8,0xFDC8,0xFDC9,0xFDC9,0xFDE9,0xFE6C,0x10A2,0x39C4,0xFE4C,0xFDEA,0xFDE9,0xFDC9,0xFDC9,0xFDC8,0xFDC8,0xFDA7,0xFDA8,0xFF16,0xF588,0xF544,0x6222,0x0000,0x0000, // row 20, 672 pixels
0x0000,0x0000,0xA383,0xF524,0xF64E,0xFE4E,0xFD86,0xFD86,0xFD87,0xFDA7,0xFDA7,0xFDA8,0xFDC8,0xFDC8,0xFE2A,0xA469,0xB4EA,0xFE2A,0xFDC9,0xFDC8,0xFDC8,0xFDA8,0xFDA7,0xFDA7,0xFD87,0xFD86,0xFDEA,0xFED3,0xF524,0xC443,0x0000,0x0000, // row 21, 704 pixels
0x0000,0x51C1,0xF504,0xF546,0xFF16,0xF565,0xFD65,0xFD65,0xFD86,0xFD86,0xFD86,0xFDA7,0xFDA7,0xFDA7,0xFDE8,0xFE6A,0xFE4A,0xFDE8,0xFDA7,0xFDA7,0xFDA7,0xFDA7,0xFD86,0xFD86,0xFD86,0xFD65,0xFD65,0xFEB2,0xF5CA,0xF504,0x8AE2,0x0000, // row 22, 736 pixels
0x0000,0xB3A2,0xED03,0xFE92,0xFDC9,0xF543,0xF544,0xFD44,0xFD65,0xFD65,0xFD65,0xFD86,0xFD86,0xFD86,0xFDA7,0xFDC7,0xFDC7,0xFDA7,0xFD86,0xFD86,0xFD86,0xFD86,0xFD65,0xFD65,0xFD65,0xFD44,0xF544,0xFD86,0xFEF5,0xED03,0xE4C3,0x1880, // row 23, 768 pixels
0x7241,0xECE3,0xF567,0xFED3,0xF523,0xF523,0xF523,0xF543,0xF544,0xF544,0xFD65,0xFD65,0xFD65,0xFD65,0xD4E6,0x39C5,0x39A5,0xD4E6,0xFD86,0xFD65,0xFD65,0xFD65,0xFD65,0xF544,0xF544,0xF543,0xF523,0xF523,0xFE2E,0xF5EC,0xECE3,0x9B42, // row 24, 800 pixels
0xD443,0xECE3,0xFED4,0xF565,0xF502,0xF502,0xF522,0xF523,0xF523,0xF543,0xF544,0xF544,0xF544,0xFD65,0x8B64,0x18C3,0x18C3,0x8344,0xFD85,0xFD44,0xF544,0xF544,0xF544,0xF543,0xF523,0xF523,0xF522,0xF502,0xF523,0xFEF5,0xED04,0xECE3, // row 25, 832 pixels
0xECC3,0xF5AB,0xFE6F,0xF501,0xF4E1,0xF501,0xF502,0xF502,0xF522,0xF522,0xF523,0xF523,0xF523,0xFD84,0xC504,0x20E1,0x18E1,0xC4E4,0xFD84,0xF543,0xF523,0xF523,0xF523,0xF522,0xF522,0xF502,0xF502,0xF501,0xF501,0xFDC9,0xF62F,0xECC3, // row 26, 864 pixels
0xECC2,0xFE92,0xF523,0xF4E0,0xF4E0,0xF4E1,0xF4E1,0xF501,0xF501,0xF502,0xF502,0xF522,0xF522,0xF543,0xFDE3,0xFEA5,0xF6A4,0xFE04,0xF543,0xF522,0xF522,0xF522,0xF502,0xF502,0xF501,0xF501,0xF4E1,0xF4E1,0xF4E0,0xF4E1,0xFED4,0xECC2, // row 27, 896 pixels
0xECA2,0xF5EC,0xF4E0,0xF4C0,0xF4E0,0xF4E0,0xF4E0,0xF4E1,0xF4E1,0xF501,0xF501,0xF501,0xF502,0xF502,0xF542,0xFDA2,0xFDA2,0xF542,0xF502,0xF502,0xF502,0xF501,0xF501,0xF501,0xF4E1,0xF4E1,0xF4E0,0xF4E0,0xF4E0,0xF4C0,0xF5A9,0xECA2, // row 28, 928 pixels
0xECA2,0xECA2,0xECC2,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4E1,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xECC2,0xECC3,0xECA2, // row 29, 960 pixels
0x8AC1,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0x9B01, // row 30, 992 pixels
0x0000,0x1880,0x51A0,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x61E0,0x28E0,0x0000}; // row 31, 1024 pixels
+41
View File
@@ -0,0 +1,41 @@
// We need this header file to use FLASH as storage with PROGMEM directive:
#include <pgmspace.h>
// Icon width and height
const uint16_t closeWidth = 32;
const uint16_t closeHeight = 32;
// The icon file can be created with the "UTFT ImageConverter 565" bitmap to .c file creation utility, more can be pasted in here
const unsigned short close[1024] PROGMEM={
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x30C3,0x4124,0x61C7,0x61C7,0x4124,0x30E3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x48E3,0xA249,0xEB8E,0xFCB2,0xFD14,0xFD75,0xFD96,0xFD34,0xFCF3,0xEBEF,0xA28A,0x4904,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x58E3,0xC228,0xFC10,0xFD34,0xFE18,0xFE59,0xFE79,0xFE9A,0xFE9A,0xFE9A,0xFE9A,0xFE59,0xFD75,0xFC51,0xC28A,0x5904,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2041,0x8945,0xF34D,0xFD34,0xFDB6,0xFD75,0xFD55,0xFD55,0xFD96,0xFDD7,0xFDF7,0xFDF7,0xFDB6,0xFDB6,0xFDD7,0xFDF7,0xFD75,0xF38E,0x8965,0x2041,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 3, 128 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x4082,0xE208,0xF410,0xFD34,0xFC92,0xFBEF,0xFBAE,0xFBEF,0xFC71,0xFD14,0xFD75,0xFDB6,0xFD75,0xFD14,0xFC92,0xFC51,0xFC71,0xFCF3,0xFD75,0xFC30,0xEA28,0x40A2,0x0000,0x0000,0x0000,0x0000,0x0000, // row 4, 160 pixels
0x0000,0x0000,0x0000,0x0000,0x3861,0xE1E7,0xF451,0xFC92,0xFB4D,0xFA49,0xFA49,0xFAEB,0xFBAE,0xFC71,0xFD34,0xFDB6,0xFE18,0xFDB6,0xFD34,0xFC71,0xFBAE,0xFB0C,0xFAEB,0xFBAE,0xFCD3,0xFC71,0xE208,0x4082,0x0000,0x0000,0x0000,0x0000, // row 5, 192 pixels
0x0000,0x0000,0x0000,0x1020,0xD986,0xF430,0xFC30,0xFA28,0xF924,0xF965,0xFA8A,0xFB0C,0xFBAE,0xFC51,0xFD14,0xFD75,0xFDB6,0xFD75,0xFD14,0xFC51,0xFC71,0xFBEF,0xFA28,0xF9C7,0xFA8A,0xFC51,0xF430,0xD9A6,0x1020,0x0000,0x0000,0x0000, // row 6, 224 pixels
0x0000,0x0000,0x0000,0x78A2,0xEB6D,0xFC30,0xF9C7,0xF861,0xF8A2,0xFA08,0xFEDB,0xFD55,0xFB4D,0xFC10,0xFC92,0xFD14,0xFD34,0xFD14,0xFC92,0xFCB2,0xFF7D,0xFF7D,0xFB2C,0xF945,0xF8E3,0xF9E7,0xFC30,0xEB8E,0x78C3,0x0000,0x0000,0x0000, // row 7, 256 pixels
0x0000,0x0000,0x3841,0xD9E7,0xF492,0xF208,0xF041,0xF800,0xF945,0xFE9A,0xFFFF,0xFFFF,0xFD75,0xFB8E,0xFC10,0xFC51,0xFC71,0xFC51,0xFCB2,0xFF7D,0xFFFF,0xFFFF,0xFF3C,0xFA8A,0xF882,0xF841,0xFA08,0xFC92,0xDA08,0x3841,0x0000,0x0000, // row 8, 288 pixels
0x0000,0x0000,0x88A2,0xEBCF,0xF2EB,0xF061,0xF000,0xF8E3,0xFE79,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFD75,0xFB4D,0xFBAE,0xFBAE,0xFC71,0xFF7D,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFEFB,0xFA28,0xF800,0xF061,0xF2EB,0xEBEF,0x90C3,0x0000,0x0000, // row 9, 320 pixels
0x0000,0x2820,0xD1C7,0xF410,0xE945,0xE800,0xF000,0xFE9A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFD34,0xFAEB,0xFBCF,0xFF5D,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFF1C,0xF986,0xF000,0xF145,0xF410,0xD1E7,0x2820,0x0000, // row 10, 352 pixels
0x0000,0x6841,0xDB2C,0xEACB,0xE041,0xE800,0xF000,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFD14,0xFF1C,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFBCF,0xF082,0xF000,0xE841,0xEACB,0xE34D,0x7061,0x0000, // row 11, 384 pixels
0x0000,0x9861,0xE3CF,0xE186,0xE000,0xE800,0xE800,0xF145,0xFEDB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFB8E,0xF000,0xF000,0xE800,0xE800,0xE986,0xEBCF,0xA082,0x0000, // row 12, 416 pixels
0x0800,0xB8A2,0xE3AE,0xD8A2,0xD800,0xE000,0xE800,0xE800,0xF145,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFB8E,0xF000,0xF000,0xE800,0xE800,0xE000,0xE0A2,0xEBAE,0xC0C3,0x0800, // row 13, 448 pixels
0x1800,0xC124,0xE30C,0xD020,0xD800,0xE000,0xE000,0xE800,0xE800,0xF145,0xFEDB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFB8E,0xF000,0xF000,0xE800,0xE800,0xE000,0xE000,0xD820,0xE30C,0xC124,0x1800, // row 14, 480 pixels
0x2800,0xC165,0xDAAA,0xC800,0xD000,0xD800,0xE000,0xE000,0xE800,0xE800,0xF124,0xFE79,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFB6D,0xF000,0xF000,0xE800,0xE800,0xE000,0xE000,0xD800,0xD000,0xDAAA,0xC165,0x2800, // row 15, 512 pixels
0x2000,0xB924,0xD269,0xC800,0xD000,0xD000,0xD800,0xE000,0xE000,0xE800,0xE924,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xF36D,0xE800,0xE800,0xE800,0xE000,0xE000,0xD800,0xD000,0xD000,0xDA69,0xC145,0x2800, // row 16, 544 pixels
0x1000,0xB0A2,0xD28A,0xC000,0xC800,0xD000,0xD000,0xD800,0xD800,0xE165,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xF3AE,0xE000,0xE000,0xD800,0xD800,0xD000,0xD000,0xC800,0xD28A,0xB8C3,0x1000, // row 17, 576 pixels
0x0000,0xA800,0xD2AA,0xB800,0xC000,0xC800,0xC800,0xD000,0xD965,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xEBAE,0xD800,0xD800,0xD000,0xC800,0xC800,0xC000,0xD2AA,0xB020,0x0000, // row 18, 608 pixels
0x0000,0x8000,0xCA69,0xB841,0xB800,0xC000,0xC800,0xD186,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xEBCF,0xD000,0xC800,0xC800,0xC000,0xC041,0xCA69,0x8000,0x0000, // row 19, 640 pixels
0x0000,0x4800,0xC1C7,0xB8E3,0xB800,0xB800,0xC000,0xF69A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xEBEF,0xFE79,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xE410,0xC841,0xC000,0xB800,0xC0E3,0xC1C7,0x4800,0x0000, // row 20, 672 pixels
0x0000,0x1000,0xB061,0xC1E7,0xB000,0xB000,0xB800,0xD269,0xFFBE,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xE38E,0xD000,0xD965,0xF69A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xDB0C,0xC020,0xB800,0xB000,0xC1E7,0xB061,0x1000,0x0000, // row 21, 704 pixels
0x0000,0x0000,0x6000,0xB9C7,0xB061,0xB000,0xB000,0xB800,0xCA49,0xFF9E,0xFFFF,0xFFFF,0xFFFF,0xE38E,0xC800,0xC800,0xC800,0xD186,0xF69A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xDB0C,0xB800,0xB800,0xB000,0xB061,0xC1C7,0x6000,0x0000,0x0000, // row 22, 736 pixels
0x0000,0x0000,0x1800,0xB041,0xB986,0xA800,0xA800,0xB000,0xB000,0xCA49,0xFF7D,0xFFFF,0xDB8E,0xC000,0xC000,0xC000,0xC000,0xC000,0xC986,0xF6DB,0xFFFF,0xFFFF,0xD30C,0xB800,0xB000,0xB000,0xA800,0xB986,0xB041,0x1800,0x0000,0x0000, // row 23, 768 pixels
0x0000,0x0000,0x0000,0x5800,0xB0E3,0xA8C3,0xA800,0xA800,0xA800,0xB000,0xCACB,0xD38E,0xB000,0xB800,0xB800,0xB800,0xB800,0xB800,0xB800,0xC145,0xF6DB,0xD34D,0xB000,0xB000,0xA800,0xA800,0xB0C3,0xB0E3,0x5800,0x0000,0x0000,0x0000, // row 24, 800 pixels
0x0000,0x0000,0x0000,0x0000,0x6000,0xB124,0xA882,0xA000,0xA800,0xA800,0xA800,0xA800,0xB000,0xB000,0xB000,0xB000,0xB000,0xB000,0xB000,0xB000,0xB000,0xA800,0xA800,0xA800,0xA800,0xA882,0xB124,0x6000,0x0000,0x0000,0x0000,0x0000, // row 25, 832 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x6000,0xB104,0xA882,0xA000,0xA000,0xA000,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA000,0xA000,0xA882,0xB104,0x6000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 26, 864 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x6000,0xB0A2,0xA8C3,0xA020,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA020,0xA8C3,0xB0A2,0x6000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 27, 896 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x4800,0xA800,0xB0C3,0xA0A2,0x9800,0x9800,0x9800,0x9800,0xA000,0xA000,0xA000,0x9800,0x9800,0x9800,0xA082,0xB0E3,0xA800,0x4800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 28, 928 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x5800,0xA800,0xB0A2,0xA8E3,0xA0A2,0xA041,0x9800,0x9800,0xA041,0xA0A2,0xA8E3,0xB0A2,0xA800,0x5800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 29, 960 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3000,0x6000,0x8800,0xA000,0xA800,0xA800,0xA000,0x8800,0x6000,0x3000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 30, 992 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}; // row 31, 1024 pixels
+41
View File
@@ -0,0 +1,41 @@
// We need this header file to use FLASH as storage with PROGMEM directive:
#include <pgmspace.h>
// Icon width and height
const uint16_t infoWidth = 32;
const uint16_t infoHeight = 32;
// The icon file can be created with the "UTFT ImageConverter 565" bitmap to .c file creation utility, more can be pasted in here
const unsigned short info[1024] PROGMEM={
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0861,0x4A69,0x8C71,0xA514,0xBDF7,0xBDF7,0xA514,0x8C71,0x4A69,0x0861,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x39E7,0x9CF3,0xEF7D,0xF79E,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xF79E,0xEF7D,0x9CF3,0x39E7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2965,0x9492,0xF79E,0xFFDF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFDF,0xF79E,0x9492,0x2965,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 3, 128 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x630C,0xEF7D,0xFFDF,0xFFFF,0xFFFF,0xFFFF,0xD75F,0xB6BF,0x9E5F,0x963F,0x963F,0x9E5F,0xB6BF,0xD75F,0xFFFF,0xFFFF,0xFFFF,0xFFDF,0xEF7D,0x630C,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 4, 160 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x73AE,0xEF7D,0xFFDF,0xFFFF,0xFFDF,0xBEDF,0x7DBF,0x7DBF,0x7DDF,0x7DDF,0x7DDF,0x7DDF,0x7DDF,0x7DBF,0x759F,0x7DBE,0xBEBF,0xFFDF,0xFFFF,0xFFDF,0xEF7D,0x73AE,0x0000,0x0000,0x0000,0x0000,0x0000, // row 5, 192 pixels
0x0000,0x0000,0x0000,0x0000,0x630C,0xEF7D,0xFFFF,0xFFFF,0xE77F,0x7DBE,0x759E,0x759F,0x7DBF,0x7DDF,0x7DDF,0x85FF,0x7DDF,0x7DDF,0x7DBF,0x759F,0x759E,0x6D7E,0x7DBE,0xDF7F,0xFFFF,0xFFFF,0xEF7D,0x630C,0x0000,0x0000,0x0000,0x0000, // row 6, 224 pixels
0x0000,0x0000,0x0000,0x31A6,0xEF5D,0xFFDF,0xFFFF,0xCF1E,0x6D7E,0x6D7E,0x759E,0x759F,0x7DBF,0x7DDF,0x8E1F,0xBEDF,0xC6FF,0x8DFF,0x75BF,0x759F,0x759E,0x6D7E,0x655E,0x655D,0xCF1E,0xFFFF,0xFFDF,0xEF5D,0x31A6,0x0000,0x0000,0x0000, // row 7, 256 pixels
0x0000,0x0000,0x0000,0x94B2,0xF7BE,0xFFFF,0xDF5E,0x655D,0x655D,0x6D7E,0x6D7E,0x759E,0x75BF,0x759F,0xEFBF,0xFFFF,0xFFFF,0xEFBF,0x759F,0x759E,0x6D7E,0x6D7E,0x655D,0x653D,0x653D,0xDF5E,0xFFFF,0xF7BE,0x94B2,0x0000,0x0000,0x0000, // row 8, 288 pixels
0x0000,0x0000,0x4228,0xEF7D,0xFFFF,0xF7BF,0x6D5D,0x653D,0x655D,0x6D5E,0x6D7E,0x759E,0x759E,0x85DF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8DFE,0x6D7E,0x6D7E,0x6D5E,0x655D,0x653D,0x5D1D,0x6D5D,0xF7BF,0xFFFF,0xEF7D,0x4228,0x0000,0x0000, // row 9, 320 pixels
0x0000,0x0000,0xA534,0xFFDF,0xFFDF,0xA65D,0x5D1D,0x5D1D,0x653D,0x655E,0x6D7E,0x6D7E,0x6D7E,0x651E,0xE77F,0xFFFF,0xFFFF,0xF7BF,0x5CFE,0x6D7E,0x6D7E,0x655E,0x653D,0x5D1D,0x5D1D,0x54FC,0xA65D,0xFFDF,0xFFDF,0xA534,0x0000,0x0000, // row 10, 352 pixels
0x0000,0x18E3,0xEF5D,0xFFFF,0xEF9E,0x5CFC,0x54FC,0x5D1D,0x5D3D,0x653D,0x655E,0x6D7E,0x6D7E,0x653E,0x6D3E,0xB67E,0xBEBE,0x755E,0x5D1E,0x6D5E,0x655E,0x653D,0x5D3D,0x5D1D,0x54FC,0x54DC,0x54FC,0xEF9E,0xFFFF,0xEF5D,0x18E3,0x0000, // row 11, 384 pixels
0x0000,0x630C,0xEF7D,0xFFDF,0xB69D,0x54DC,0x54FC,0x5CFC,0x5D1D,0x653D,0x653D,0x655E,0x6D5E,0x655E,0x5CFE,0x4C9D,0x4C7D,0x54DD,0x653E,0x655E,0x653D,0x653D,0x5D1D,0x5CFC,0x54FC,0x54DC,0x4CBC,0xB69D,0xFFDF,0xEF7D,0x630C,0x0000, // row 12, 416 pixels
0x0000,0x94B2,0xF7BE,0xFFDF,0x85BC,0x4CBC,0x54DC,0x54FC,0x5CFD,0x5D1D,0x5D3D,0x653D,0x655D,0x653D,0x85DE,0xC6FE,0xC6FE,0x85BE,0x653D,0x653D,0x5D3D,0x5D1D,0x5CFD,0x54FC,0x54DC,0x4CBC,0x4CBB,0x85BC,0xFFDF,0xF7BE,0x94B2,0x0000, // row 13, 448 pixels
0x0000,0xB5B6,0xFFDF,0xF7BE,0x651C,0x4CBB,0x4CBC,0x54DC,0x54FC,0x5CFC,0x5D1D,0x5D1D,0x653D,0x5D1D,0xE77E,0xFFDF,0xFFDF,0xEF9E,0x5CFD,0x5D1D,0x5D1D,0x5CFC,0x54FC,0x54DC,0x4CBC,0x4CBB,0x449B,0x651B,0xF7BE,0xFFDF,0xB5B6,0x0000, // row 14, 480 pixels
0x0000,0xC638,0xFFDF,0xF7BE,0x54DB,0x449B,0x4CBB,0x4CBC,0x54DC,0x54FC,0x54FC,0x5D1D,0x5D1D,0x7D7D,0xF7BE,0xF7BE,0xF7BE,0xF7BE,0x7D7D,0x5CFD,0x54FC,0x54FC,0x54DC,0x4CBC,0x4CBB,0x449B,0x447B,0x54BB,0xF7BE,0xFFDF,0xC638,0x0000, // row 15, 512 pixels
0x0000,0xC638,0xFFDF,0xF79E,0x4CBB,0x449B,0x449B,0x4CBB,0x4CBC,0x54DC,0x54DC,0x54FC,0x54DC,0x753C,0xF7BE,0xF7BE,0xF7BE,0xF7BE,0x753C,0x54DC,0x54DC,0x54DC,0x4CBC,0x4CBB,0x449B,0x449B,0x3C7B,0x4C9B,0xF79E,0xFFDF,0xC638,0x0000, // row 16, 544 pixels
0x0000,0xB5B6,0xFFDF,0xF7BE,0x5CFB,0x3C7B,0x447B,0x449B,0x4CBB,0x4CBC,0x4CBC,0x4CDC,0x4CBC,0x6D1C,0xF7BE,0xF7BE,0xF7BE,0xF7BE,0x6CFC,0x4CBC,0x4CBC,0x4CBC,0x4CBB,0x449B,0x447B,0x3C7B,0x3C5A,0x54DB,0xF7BE,0xFFDF,0xB5B6,0x0000, // row 17, 576 pixels
0x0000,0x94B2,0xF7BE,0xF7BE,0x755B,0x3C5A,0x3C7B,0x447B,0x449B,0x449B,0x4CBB,0x4CBB,0x4C9B,0x6CFB,0xF79E,0xF79E,0xF79E,0xF79E,0x64FB,0x449B,0x4CBB,0x449B,0x449B,0x447B,0x3C7B,0x3C5A,0x3C5A,0x753B,0xF7BE,0xF7BE,0x9CD3,0x0000, // row 18, 608 pixels
0x0000,0x6B4D,0xEF7D,0xF7BE,0xA61C,0x3C5A,0x3C5A,0x3C7B,0x447B,0x447B,0x449B,0x449B,0x447B,0x64DB,0xF79E,0xF79E,0xF79E,0xF79E,0x64DB,0x447B,0x449B,0x447B,0x447B,0x3C7B,0x3C5A,0x3C5A,0x343A,0xA61C,0xF7BE,0xEF7D,0x6B4D,0x0000, // row 19, 640 pixels
0x0000,0x2124,0xE71C,0xFFDF,0xDF3D,0x3C5A,0x343A,0x3C5A,0x3C5A,0x3C7B,0x3C7B,0x447B,0x3C5B,0x64BA,0xF79E,0xF79E,0xF79E,0xF79E,0x64BA,0x3C5B,0x3C7B,0x3C7B,0x3C5A,0x3C5A,0x343A,0x343A,0x343A,0xDF3D,0xFFDF,0xE71C,0x2124,0x0000, // row 20, 672 pixels
0x0000,0x0000,0xAD75,0xF7BE,0xF79E,0x859B,0x343A,0x343A,0x345A,0x3C5A,0x3C5A,0x3C5A,0x3C5A,0x5C9A,0xEF7D,0xEF7D,0xEF7D,0xEF7D,0x5C9A,0x3C3A,0x3C5A,0x3C5A,0x345A,0x343A,0x343A,0x341A,0x859B,0xF79E,0xF7BE,0xAD75,0x0000,0x0000, // row 21, 704 pixels
0x0000,0x0000,0x528A,0xE71C,0xFFDF,0xDF3D,0x3C5A,0x343A,0x343A,0x343A,0x343A,0x3C5A,0x343A,0x4C5A,0xEF7D,0xEF7D,0xEF7D,0xEF7D,0x4C59,0x343A,0x343A,0x343A,0x343A,0x343A,0x341A,0x3C5A,0xDF3D,0xFFDF,0xE71C,0x528A,0x0000,0x0000, // row 22, 736 pixels
0x0000,0x0000,0x0000,0x9CD3,0xF79E,0xF7BE,0xBE7C,0x3419,0x341A,0x341A,0x343A,0x343A,0x341A,0x2B99,0xC69C,0xEF7D,0xEF7D,0xD6DC,0x2398,0x341A,0x343A,0x341A,0x341A,0x2C19,0x2C19,0xBE7C,0xF7BE,0xF79E,0x9CD3,0x0000,0x0000,0x0000, // row 23, 768 pixels
0x0000,0x0000,0x0000,0x39E7,0xDEDB,0xFFDF,0xF79E,0x9DFB,0x2C19,0x2C19,0x2C1A,0x341A,0x341A,0x2BB9,0x2B57,0x6459,0x74B9,0x2337,0x2BB9,0x341A,0x2C1A,0x2C19,0x2C19,0x2C19,0x9DFB,0xF79E,0xFFDF,0xDEDB,0x39E7,0x0000,0x0000,0x0000, // row 24, 800 pixels
0x0000,0x0000,0x0000,0x0000,0x632C,0xDEFB,0xFFDF,0xEF7D,0xB65C,0x3C39,0x2BF9,0x2C19,0x2C19,0x2BF9,0x2398,0x1B58,0x1B37,0x2398,0x2BF9,0x2C19,0x2BF9,0x2BF9,0x3439,0xB65C,0xEF7D,0xFFDF,0xDEFB,0x632C,0x0000,0x0000,0x0000,0x0000, // row 25, 832 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x73AE,0xDEFB,0xF7BE,0xF79E,0xDF1C,0x7D5A,0x2BF9,0x2BF9,0x2BF9,0x2BF9,0x23D9,0x23D9,0x2BF9,0x2BF9,0x2BF9,0x2BF9,0x7D5A,0xDF1C,0xF79E,0xF7BE,0xDEFB,0x73AE,0x0000,0x0000,0x0000,0x0000,0x0000, // row 26, 864 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x632C,0xDEDB,0xF79E,0xFFDF,0xEF7D,0xD6FC,0x9DFB,0x5CDA,0x4C9A,0x3419,0x3419,0x4C9A,0x5CDA,0x9DFB,0xD6FC,0xEF7D,0xFFDF,0xF79E,0xDEDB,0x632C,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 27, 896 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x4208,0x94B2,0xDEFB,0xF7BE,0xFFDF,0xF7BE,0xF79E,0xEF7D,0xEF5D,0xEF5D,0xEF7D,0xF79E,0xF7BE,0xFFDF,0xF7BE,0xDEFB,0x94B2,0x4208,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 28, 928 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x528A,0xA534,0xDEDB,0xE73C,0xF79E,0xF7BE,0xF7BE,0xF7BE,0xF7BE,0xF79E,0xE73C,0xDEDB,0xA534,0x528A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 29, 960 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x18C3,0x5AEB,0x8C71,0xAD55,0xBDD7,0xBDD7,0xAD55,0x8C71,0x5AEB,0x18C3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 30, 992 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}; // row 31, 1024 pixels
@@ -0,0 +1,110 @@
// Icons are stored in tabs ^ e.g. Alert.h etc above this line
// more than one icon can be in a header file
/*
This sketch demonstrates loading images from arrays stored in program (FLASH) memory.
Works with TFT_eSPI library here:
https://github.com/Bodmer/TFT_eSPI
This sketch does not use/need any fonts at all...
Arrays containing FLASH images can be created with UTFT library tool:
(libraries\UTFT\Tools\ImageConverter565.exe)
Convert to .c format then copy into a new tab
The number and size of icons is limited by available FLASH memory. The icon array will
use width x height x 2 bytes of FLASH, i.e. 32 x 32 icon uses ~2048 bytes
Performance is good enough for most applications:
A 32 x 32 icon can be drawn by a humble ESP8266 in ~3.6 milliseconds, i.e. ~280 icons per second!
A 320 x 240 screen can be completely filled with icons in about 270ms
Code derived from ILI9341_due example
*/
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
// Include the header files that contain the icons
#include "alert.h"
#include "Close.h"
#include "Info.h"
long count = 0; // Loop count
void setup()
{
Serial.begin(115200);
tft.begin();
tft.setRotation(1); // landscape
tft.fillScreen(TFT_BLACK);
// Draw the icons
drawIcon(info, 100, 100, infoWidth, infoHeight);
drawIcon(alert, 140, 100, alertWidth, alertHeight);
drawIcon(close, 180, 100, closeWidth, closeHeight);
// Pause here to admire the icons!
delay(4000);
}
void loop()
{
// Loop filling and clearing screen to show draw speed
drawIcon(info, random(tft.width() - infoWidth), random(tft.height() - infoHeight), infoWidth, infoHeight);
drawIcon(alert, random(tft.width() - alertWidth), random(tft.height() - alertHeight), alertWidth, alertHeight);
drawIcon(close, random(tft.width() - closeWidth), random(tft.height() - closeHeight), alertWidth, closeHeight);
// Clear screen after 100 x 3 = 300 icons drawn
if (100 == count++) {
count = 1;
tft.setRotation(2 * random(2)); // Rotate randomly to clear display left>right or right>left to reduce monotony!
tft.fillScreen(TFT_BLACK);
tft.setRotation(1);
Serial.println(millis());
}
}
//====================================================================================
// This is the function to draw the icon stored as an array in program memory (FLASH)
//====================================================================================
// To speed up rendering we use a 64 pixel buffer
#define BUFF_SIZE 64
// Draw array "icon" of defined width and height at coordinate x,y
// Maximum icon size is 255x255 pixels to avoid integer overflow
void drawIcon(const unsigned short* icon, int16_t x, int16_t y, int8_t width, int8_t height) {
uint16_t pix_buffer[BUFF_SIZE]; // Pixel buffer (16 bits per pixel)
// Set up a window the right size to stream pixels into
tft.setWindow(x, y, x + width - 1, y + height - 1);
// Work out the number whole buffers to send
uint16_t nb = ((uint16_t)height * width) / BUFF_SIZE;
// Fill and send "nb" buffers to TFT
for (int i = 0; i < nb; i++) {
for (int j = 0; j < BUFF_SIZE; j++) {
pix_buffer[j] = pgm_read_word(&icon[i * BUFF_SIZE + j]);
}
tft.pushColors(pix_buffer, BUFF_SIZE);
}
// Work out number of pixels not yet sent
uint16_t np = ((uint16_t)height * width) % BUFF_SIZE;
// Send any partial buffer left over
if (np) {
for (int i = 0; i < np; i++) pix_buffer[i] = pgm_read_word(&icon[nb * BUFF_SIZE + i]);
tft.pushColors(pix_buffer, np);
}
}
@@ -0,0 +1,102 @@
/*
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
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // 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,92 @@
// Mandlebrot
// This will run slowly due to the large number of calculations per pixel
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define ILI9341_GREY 0x7BEF
unsigned long runTime = 0;
float sx = 0, sy = 0;
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
void setup()
{
//randomSeed(analogRead(A0));
//pinMode(7, OUTPUT);
//digitalWrite(7, LOW);
//delay(10);
//digitalWrite(7, HIGH);
// Setup the LCD
tft.init();
tft.setRotation(3);
}
void loop()
{
runTime = millis();
tft.fillScreen(ILI9341_BLACK);
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);
}
}
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
//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,84 @@
// A fun MATRIX-like screen demo of scrolling
// Screen will flicker initially until fully drawn
// then scroll smoothly
// Needs GLCD font enabled in User_Setup.h
#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 randomt 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 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) yDraw = scroll_slow(320,8); // Scroll 320 lines, 8ms 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
This example uses the hardware SPI only
Needs Font 2 (also Font 4 if using large scale label)
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
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);
}
}
+295
View File
@@ -0,0 +1,295 @@
/*
Example animated analogue meters using a ILI9341 TFT LCD screen
Needs Font 2 (also Font 4 if using large scale label)
Comment out lines 153 and 197 to reduce needle flicker and
to remove need for Font 4 (which uses ~5k of FLASH!)
*/
#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 = 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() + 35;
d += 4; if (d >= 360) d = 0;
//value[0] = map(analogRead(A0), 0, 1023, 0, 100); // Test with value form Analogue 0
//value[1] = map(analogRead(A1), 0, 1023, 0, 100); // Test with value form Analogue 1
//value[2] = map(analogRead(A2), 0, 1023, 0, 100); // Test with value form Analogue 2
//value[3] = map(analogRead(A3), 0, 1023, 0, 100); // Test with value form Analogue 3
//value[4] = map(analogRead(A4), 0, 1023, 0, 100); // Test with value form Analogue 4
//value[5] = map(analogRead(A5), 0, 1023, 0, 100); // Test with value form Analogue 5
// 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(); // It takes aout 3.5ms to plot each gauge for a 1 pixel move, 21ms for 6 gauges
plotNeedle(value[0], 0); // It takes between 2 and 12ms to replot the needle with zero delay
//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,86 @@
// 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() {
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);
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;
}
+219
View File
@@ -0,0 +1,219 @@
/*
* 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;
// Quick way to draw a dashed line
tft.setWindow(dashline_x,0,dashline_x+dashline_w-1,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
}
}
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,76 @@
/*
Test the tft.print() viz embedded tft.write() function
This sketch used font 2, 4, 7
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // Graphics and font library for 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,155 @@
/*
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.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // 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;
}
//====================================================================================
+100
View File
@@ -0,0 +1,100 @@
// Spiro
// Rainbow patern generator
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
unsigned long runTime = 0;
float sx = 0, sy = 0;
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
void setup()
{
//randomSeed(analogRead(A0));
//pinMode(7, OUTPUT);
//digitalWrite(7, LOW);
//delay(10);
//digitalWrite(7, HIGH);
// 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) * 0.0174532925);
sy = sin((i / n - 90) * 0.0174532925);
x0 = sx * (120 - r) + 159;
yy0 = sy * (120 - r) + 119;
sy = cos(((i % 360) - 90) * 0.0174532925);
sx = sin(((i % 360) - 90) * 0.0174532925);
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) * 0.0174532925);
sy = sin((i / n - 90) * 0.0174532925);
x0 = sx * (120 - r) + 159;
yy0 = sy * (120 - r) + 119;
sy = cos(((i % 360) - 90) * 0.0174532925);
sx = sin(((i % 360) - 90) * 0.0174532925);
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,91 @@
// Animates 256 white pixels to simulate flying through a star field
// Demonstrates use of the fastPixel() function in the library
// which is about 15% faster than drawPixel()
#include <SPI.h>
#include <TFT_eSPI.h>
// Use hardware SPI
TFT_eSPI tft = TFT_eSPI();
// With 256 stars the update frame rate is about 45Hz
#define NSTARS 256
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] = {};
Serial.println(t1 - t0);
}
@@ -0,0 +1,120 @@
/*
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
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // 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,156 @@
/*************************************************************
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
*************************************************************/
// In most cases characters don't get lost at 9600 baud but
// it is a good idea to increase the serial Rx buffer from 64
// to 512 or 1024 bytes especially if higher baud rates are
// used (this sketch does not need much RAM).
// The method described here works well:
// http://www.hobbytronics.co.uk/arduino-serial-buffer-size
//
#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
boolean change_colour = 1;
boolean 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,760 @@
/*
Adapted from the Adafruit and Xark's PDQ graphicstest sketch.
This sketch uses the GLCD font only.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include "SPI.h"
#include "TFT_eSPI.h"
// These are used to get information about static SRAM and flash memory sizes
extern "C" char __data_start[]; // start of SRAM data
extern "C" char _end[]; // end of SRAM data (used to check amount of SRAM this program's variables use)
extern "C" char __data_load_end[]; // end of FLASH (used to check amount of Flash this program's code and data uses)
// 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("Bodmer's 2.2\" SPI TFT Test!");
tft.init();
}
void loop(void)
{
Serial.print(F(__DATE__ " " __TIME__ " - Flash=0x"));
//Serial.print((uint16_t)__data_load_end, HEX);
Serial.print(F(" RAM=0x"));
//Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX);
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 "));
tft.setTextSize(1);
tft.setTextColor(TFT_WHITE);
tft.println(F(" SPI LCD Benchmark (Atmega328p @ 16MHz)"));
tft.setTextSize(1);
tft.println(F(""));
tft.setTextColor(tft.color565(0x80, 0x80, 0x80));
tft.print(F(" Memory Used: Flash=0x"));
//tft.print((uint16_t)__data_load_end, HEX);
tft.print(F(" RAM=0x"));
// tft.println((uint16_t)_end - (uint16_t)__data_start, HEX);
tft.println(F(""));
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, "%lu", 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.setWindow(0, 0, 240-1, 320-1);
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];
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;
}
}
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();
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));
}
}
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,366 @@
/*
Adapted from the Adafruit graphicstest sketch.
This sketch uses the GLCD font (font 1) only.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#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() {
yield();Serial.begin(9600);
while (!Serial);
yield();Serial.println("TFT_eSPI 2.2\" SPI TFT 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.print(F("Done! Total = ")); yield();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
****************************************************/
+363
View File
@@ -0,0 +1,363 @@
// Demo based on:
// UTFT_Demo_320x240 by Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
/*
This sketch uses the GLCD and font 2 only. Disable other fonts to make
the sketch fit in an UNO!
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_eSPI library folder.
If using an UNO or Mega (ATmega328 or ATmega2560 processor) then for best
performance use the F_AS_T option found in the User_Setup.h file in the
TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#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);
}
@@ -0,0 +1,158 @@
//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 <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define GRIDX 32
#define GRIDY 24
#define CELLXY 5
#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
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 = 300;
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 neighborhood
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.
*/
+42
View File
@@ -0,0 +1,42 @@
// We need this header file to use FLASH as storage with PROGMEM directive:
#include <avr/pgmspace.h>
// Icon width and height
const uint16_t alertWidth = 32;
const uint16_t alertHeight = 32;
// The icon file can be created with the "UTFT ImageConverter 565" bitmap to .c file creation utility, more can be pasted in here
const unsigned short alert[1024] PROGMEM={
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0840,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1080,0xAC66,0xEDE8,0xFE69,0xC4C6,0x2901,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xBCC6,0xFE68,0xFE68,0xFE6A,0xFE68,0xEDE8,0x18A1,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x8344,0xFE48,0xFE8C,0xFFDD,0xFFFF,0xFEF0,0xFE48,0xB466,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 3, 128 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x1880,0xEDC7,0xFE48,0xFF99,0xFFBC,0xFF9B,0xFFBD,0xFE6A,0xFE48,0x5A23,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 4, 160 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x9BE5,0xFE28,0xFED0,0xFFBC,0xFF7A,0xFF9A,0xFF9B,0xFF35,0xFE28,0xBCA6,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 5, 192 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3962,0xFE28,0xFE28,0xFF9A,0xFF79,0xFF9A,0xFF9B,0xFF9A,0xFFBD,0xFE6B,0xFE28,0x72E3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 6, 224 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xB465,0xFE28,0xFEF2,0xFF7A,0xFF79,0xFF7A,0xFF9A,0xFF7A,0xFF7A,0xFF78,0xFE28,0xDD67,0x0860,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 7, 256 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x5A22,0xFE07,0xFE29,0xFF9B,0xFF37,0xFF58,0xFF79,0xFF79,0xFF79,0xFF58,0xFF9B,0xFEAE,0xFE07,0x93A4,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 8, 288 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xC4A5,0xFE07,0xFF15,0xFF37,0xFF36,0xAD11,0x2965,0x2965,0xCDF4,0xFF37,0xFF37,0xFF79,0xFE07,0xFE07,0x2901,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 9, 320 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x7B03,0xFDE7,0xFE4B,0xFF79,0xFEF4,0xFF15,0xB552,0x2945,0x2945,0xDE55,0xFF16,0xFF15,0xFF58,0xFED1,0xFDE7,0xAC25,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 10, 352 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0840,0xDD26,0xFDE7,0xFF57,0xFED3,0xFED2,0xFEF4,0xBD93,0x2124,0x2124,0xDE75,0xFF14,0xFED3,0xFED3,0xFF7A,0xFE08,0xFDE7,0x49A2,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 11, 384 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x9BA4,0xFDC6,0xFE6E,0xFF36,0xFE90,0xFEB1,0xFED3,0xC592,0x2124,0x2124,0xE675,0xFED3,0xFEB2,0xFEB1,0xFEF3,0xFEF3,0xFDC6,0xBC45,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 12, 416 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3141,0xF5C6,0xF5C7,0xFF58,0xFE90,0xFE6F,0xFE8F,0xFEB1,0xCDB2,0x2104,0x2104,0xF6B4,0xFEB1,0xFE90,0xFE8F,0xFE90,0xFF58,0xFE0A,0xF5C6,0x72A3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 13, 448 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xABE4,0xF5A6,0xFEB1,0xFED3,0xFE4E,0xFE6E,0xFE6F,0xFE90,0xD5F2,0x18E3,0x18E3,0xFED4,0xFE90,0xFE6F,0xFE6F,0xFE6E,0xFE91,0xFF36,0xF5A6,0xCCA5,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 14, 480 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x5202,0xF5A6,0xF5C7,0xFF58,0xFE4D,0xFE4D,0xFE4D,0xFE4E,0xFE6F,0xDE11,0x18C3,0x18C3,0xFED3,0xFE6F,0xFE6E,0xFE4E,0xFE4D,0xFE4D,0xFF16,0xFE2C,0xF5A6,0x9363,0x0000,0x0000,0x0000,0x0000,0x0000, // row 15, 512 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0xBC44,0xF585,0xFED3,0xFE6F,0xFE2C,0xFE2C,0xFE2D,0xFE4D,0xFE4E,0xE630,0x10A2,0x2104,0xFED1,0xFE4E,0xFE4D,0xFE4D,0xFE2D,0xFE2C,0xFE4D,0xFF37,0xF586,0xF585,0x28E1,0x0000,0x0000,0x0000,0x0000, // row 16, 544 pixels
0x0000,0x0000,0x0000,0x0000,0x7282,0xF565,0xF5EA,0xFF16,0xFE0B,0xFE0B,0xFE0B,0xFE2C,0xFE2C,0xFE4D,0xF670,0x1082,0x2924,0xFEB0,0xFE2D,0xFE2C,0xFE2C,0xFE2C,0xFE0B,0xFE0B,0xFEB2,0xFE6F,0xF565,0xA383,0x0000,0x0000,0x0000,0x0000, // row 17, 576 pixels
0x0000,0x0000,0x0000,0x0840,0xD4C4,0xF565,0xFEF5,0xFE0C,0xFDE9,0xFDEA,0xFE0A,0xFE0B,0xFE0B,0xFE2C,0xFE8F,0x0861,0x2964,0xFE8F,0xFE2C,0xFE0B,0xFE0B,0xFE0B,0xFE0A,0xFDEA,0xFE0B,0xFF37,0xF586,0xF565,0x4181,0x0000,0x0000,0x0000, // row 18, 608 pixels
0x0000,0x0000,0x0000,0x9343,0xF545,0xF60C,0xFED3,0xFDC8,0xFDC8,0xFDC9,0xFDE9,0xFDEA,0xFDEA,0xFE0B,0xFE8E,0x0861,0x3184,0xFE6D,0xFE0B,0xFE0A,0xFDEA,0xFDEA,0xFDE9,0xFDC9,0xFDC9,0xFE4E,0xFEB2,0xF545,0xB3E3,0x0000,0x0000,0x0000, // row 19, 640 pixels
0x0000,0x0000,0x28E0,0xF544,0xF545,0xFF17,0xFDC8,0xFDA7,0xFDA7,0xFDC8,0xFDC8,0xFDC9,0xFDC9,0xFDE9,0xFE6C,0x10A2,0x39C4,0xFE4C,0xFDEA,0xFDE9,0xFDC9,0xFDC9,0xFDC8,0xFDC8,0xFDA7,0xFDA8,0xFF16,0xF588,0xF544,0x6222,0x0000,0x0000, // row 20, 672 pixels
0x0000,0x0000,0xA383,0xF524,0xF64E,0xFE4E,0xFD86,0xFD86,0xFD87,0xFDA7,0xFDA7,0xFDA8,0xFDC8,0xFDC8,0xFE2A,0xA469,0xB4EA,0xFE2A,0xFDC9,0xFDC8,0xFDC8,0xFDA8,0xFDA7,0xFDA7,0xFD87,0xFD86,0xFDEA,0xFED3,0xF524,0xC443,0x0000,0x0000, // row 21, 704 pixels
0x0000,0x51C1,0xF504,0xF546,0xFF16,0xF565,0xFD65,0xFD65,0xFD86,0xFD86,0xFD86,0xFDA7,0xFDA7,0xFDA7,0xFDE8,0xFE6A,0xFE4A,0xFDE8,0xFDA7,0xFDA7,0xFDA7,0xFDA7,0xFD86,0xFD86,0xFD86,0xFD65,0xFD65,0xFEB2,0xF5CA,0xF504,0x8AE2,0x0000, // row 22, 736 pixels
0x0000,0xB3A2,0xED03,0xFE92,0xFDC9,0xF543,0xF544,0xFD44,0xFD65,0xFD65,0xFD65,0xFD86,0xFD86,0xFD86,0xFDA7,0xFDC7,0xFDC7,0xFDA7,0xFD86,0xFD86,0xFD86,0xFD86,0xFD65,0xFD65,0xFD65,0xFD44,0xF544,0xFD86,0xFEF5,0xED03,0xE4C3,0x1880, // row 23, 768 pixels
0x7241,0xECE3,0xF567,0xFED3,0xF523,0xF523,0xF523,0xF543,0xF544,0xF544,0xFD65,0xFD65,0xFD65,0xFD65,0xD4E6,0x39C5,0x39A5,0xD4E6,0xFD86,0xFD65,0xFD65,0xFD65,0xFD65,0xF544,0xF544,0xF543,0xF523,0xF523,0xFE2E,0xF5EC,0xECE3,0x9B42, // row 24, 800 pixels
0xD443,0xECE3,0xFED4,0xF565,0xF502,0xF502,0xF522,0xF523,0xF523,0xF543,0xF544,0xF544,0xF544,0xFD65,0x8B64,0x18C3,0x18C3,0x8344,0xFD85,0xFD44,0xF544,0xF544,0xF544,0xF543,0xF523,0xF523,0xF522,0xF502,0xF523,0xFEF5,0xED04,0xECE3, // row 25, 832 pixels
0xECC3,0xF5AB,0xFE6F,0xF501,0xF4E1,0xF501,0xF502,0xF502,0xF522,0xF522,0xF523,0xF523,0xF523,0xFD84,0xC504,0x20E1,0x18E1,0xC4E4,0xFD84,0xF543,0xF523,0xF523,0xF523,0xF522,0xF522,0xF502,0xF502,0xF501,0xF501,0xFDC9,0xF62F,0xECC3, // row 26, 864 pixels
0xECC2,0xFE92,0xF523,0xF4E0,0xF4E0,0xF4E1,0xF4E1,0xF501,0xF501,0xF502,0xF502,0xF522,0xF522,0xF543,0xFDE3,0xFEA5,0xF6A4,0xFE04,0xF543,0xF522,0xF522,0xF522,0xF502,0xF502,0xF501,0xF501,0xF4E1,0xF4E1,0xF4E0,0xF4E1,0xFED4,0xECC2, // row 27, 896 pixels
0xECA2,0xF5EC,0xF4E0,0xF4C0,0xF4E0,0xF4E0,0xF4E0,0xF4E1,0xF4E1,0xF501,0xF501,0xF501,0xF502,0xF502,0xF542,0xFDA2,0xFDA2,0xF542,0xF502,0xF502,0xF502,0xF501,0xF501,0xF501,0xF4E1,0xF4E1,0xF4E0,0xF4E0,0xF4E0,0xF4C0,0xF5A9,0xECA2, // row 28, 928 pixels
0xECA2,0xECA2,0xECC2,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4E1,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E2,0xF4E1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xF4C1,0xECC2,0xECC3,0xECA2, // row 29, 960 pixels
0x8AC1,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0xEC82,0x9B01, // row 30, 992 pixels
0x0000,0x1880,0x51A0,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x8AA1,0x61E0,0x28E0,0x0000}; // row 31, 1024 pixels
+41
View File
@@ -0,0 +1,41 @@
// We need this header file to use FLASH as storage with PROGMEM directive:
#include <avr/pgmspace.h>
// Icon width and height
const uint16_t closeWidth = 32;
const uint16_t closeHeight = 32;
// The icon file can be created with the "UTFT ImageConverter 565" bitmap to .c file creation utility, more can be pasted in here
const unsigned short close[1024] PROGMEM={
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x30C3,0x4124,0x61C7,0x61C7,0x4124,0x30E3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x48E3,0xA249,0xEB8E,0xFCB2,0xFD14,0xFD75,0xFD96,0xFD34,0xFCF3,0xEBEF,0xA28A,0x4904,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x58E3,0xC228,0xFC10,0xFD34,0xFE18,0xFE59,0xFE79,0xFE9A,0xFE9A,0xFE9A,0xFE9A,0xFE59,0xFD75,0xFC51,0xC28A,0x5904,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2041,0x8945,0xF34D,0xFD34,0xFDB6,0xFD75,0xFD55,0xFD55,0xFD96,0xFDD7,0xFDF7,0xFDF7,0xFDB6,0xFDB6,0xFDD7,0xFDF7,0xFD75,0xF38E,0x8965,0x2041,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 3, 128 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x4082,0xE208,0xF410,0xFD34,0xFC92,0xFBEF,0xFBAE,0xFBEF,0xFC71,0xFD14,0xFD75,0xFDB6,0xFD75,0xFD14,0xFC92,0xFC51,0xFC71,0xFCF3,0xFD75,0xFC30,0xEA28,0x40A2,0x0000,0x0000,0x0000,0x0000,0x0000, // row 4, 160 pixels
0x0000,0x0000,0x0000,0x0000,0x3861,0xE1E7,0xF451,0xFC92,0xFB4D,0xFA49,0xFA49,0xFAEB,0xFBAE,0xFC71,0xFD34,0xFDB6,0xFE18,0xFDB6,0xFD34,0xFC71,0xFBAE,0xFB0C,0xFAEB,0xFBAE,0xFCD3,0xFC71,0xE208,0x4082,0x0000,0x0000,0x0000,0x0000, // row 5, 192 pixels
0x0000,0x0000,0x0000,0x1020,0xD986,0xF430,0xFC30,0xFA28,0xF924,0xF965,0xFA8A,0xFB0C,0xFBAE,0xFC51,0xFD14,0xFD75,0xFDB6,0xFD75,0xFD14,0xFC51,0xFC71,0xFBEF,0xFA28,0xF9C7,0xFA8A,0xFC51,0xF430,0xD9A6,0x1020,0x0000,0x0000,0x0000, // row 6, 224 pixels
0x0000,0x0000,0x0000,0x78A2,0xEB6D,0xFC30,0xF9C7,0xF861,0xF8A2,0xFA08,0xFEDB,0xFD55,0xFB4D,0xFC10,0xFC92,0xFD14,0xFD34,0xFD14,0xFC92,0xFCB2,0xFF7D,0xFF7D,0xFB2C,0xF945,0xF8E3,0xF9E7,0xFC30,0xEB8E,0x78C3,0x0000,0x0000,0x0000, // row 7, 256 pixels
0x0000,0x0000,0x3841,0xD9E7,0xF492,0xF208,0xF041,0xF800,0xF945,0xFE9A,0xFFFF,0xFFFF,0xFD75,0xFB8E,0xFC10,0xFC51,0xFC71,0xFC51,0xFCB2,0xFF7D,0xFFFF,0xFFFF,0xFF3C,0xFA8A,0xF882,0xF841,0xFA08,0xFC92,0xDA08,0x3841,0x0000,0x0000, // row 8, 288 pixels
0x0000,0x0000,0x88A2,0xEBCF,0xF2EB,0xF061,0xF000,0xF8E3,0xFE79,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFD75,0xFB4D,0xFBAE,0xFBAE,0xFC71,0xFF7D,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFEFB,0xFA28,0xF800,0xF061,0xF2EB,0xEBEF,0x90C3,0x0000,0x0000, // row 9, 320 pixels
0x0000,0x2820,0xD1C7,0xF410,0xE945,0xE800,0xF000,0xFE9A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFD34,0xFAEB,0xFBCF,0xFF5D,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFF1C,0xF986,0xF000,0xF145,0xF410,0xD1E7,0x2820,0x0000, // row 10, 352 pixels
0x0000,0x6841,0xDB2C,0xEACB,0xE041,0xE800,0xF000,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFD14,0xFF1C,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFBCF,0xF082,0xF000,0xE841,0xEACB,0xE34D,0x7061,0x0000, // row 11, 384 pixels
0x0000,0x9861,0xE3CF,0xE186,0xE000,0xE800,0xE800,0xF145,0xFEDB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFB8E,0xF000,0xF000,0xE800,0xE800,0xE986,0xEBCF,0xA082,0x0000, // row 12, 416 pixels
0x0800,0xB8A2,0xE3AE,0xD8A2,0xD800,0xE000,0xE800,0xE800,0xF145,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFB8E,0xF000,0xF000,0xE800,0xE800,0xE000,0xE0A2,0xEBAE,0xC0C3,0x0800, // row 13, 448 pixels
0x1800,0xC124,0xE30C,0xD020,0xD800,0xE000,0xE000,0xE800,0xE800,0xF145,0xFEDB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFB8E,0xF000,0xF000,0xE800,0xE800,0xE000,0xE000,0xD820,0xE30C,0xC124,0x1800, // row 14, 480 pixels
0x2800,0xC165,0xDAAA,0xC800,0xD000,0xD800,0xE000,0xE000,0xE800,0xE800,0xF124,0xFE79,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFB6D,0xF000,0xF000,0xE800,0xE800,0xE000,0xE000,0xD800,0xD000,0xDAAA,0xC165,0x2800, // row 15, 512 pixels
0x2000,0xB924,0xD269,0xC800,0xD000,0xD000,0xD800,0xE000,0xE000,0xE800,0xE924,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xF36D,0xE800,0xE800,0xE800,0xE000,0xE000,0xD800,0xD000,0xD000,0xDA69,0xC145,0x2800, // row 16, 544 pixels
0x1000,0xB0A2,0xD28A,0xC000,0xC800,0xD000,0xD000,0xD800,0xD800,0xE165,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xF3AE,0xE000,0xE000,0xD800,0xD800,0xD000,0xD000,0xC800,0xD28A,0xB8C3,0x1000, // row 17, 576 pixels
0x0000,0xA800,0xD2AA,0xB800,0xC000,0xC800,0xC800,0xD000,0xD965,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xEBAE,0xD800,0xD800,0xD000,0xC800,0xC800,0xC000,0xD2AA,0xB020,0x0000, // row 18, 608 pixels
0x0000,0x8000,0xCA69,0xB841,0xB800,0xC000,0xC800,0xD186,0xFEFB,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xEBCF,0xD000,0xC800,0xC800,0xC000,0xC041,0xCA69,0x8000,0x0000, // row 19, 640 pixels
0x0000,0x4800,0xC1C7,0xB8E3,0xB800,0xB800,0xC000,0xF69A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xEBEF,0xFE79,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xE410,0xC841,0xC000,0xB800,0xC0E3,0xC1C7,0x4800,0x0000, // row 20, 672 pixels
0x0000,0x1000,0xB061,0xC1E7,0xB000,0xB000,0xB800,0xD269,0xFFBE,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xE38E,0xD000,0xD965,0xF69A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xDB0C,0xC020,0xB800,0xB000,0xC1E7,0xB061,0x1000,0x0000, // row 21, 704 pixels
0x0000,0x0000,0x6000,0xB9C7,0xB061,0xB000,0xB000,0xB800,0xCA49,0xFF9E,0xFFFF,0xFFFF,0xFFFF,0xE38E,0xC800,0xC800,0xC800,0xD186,0xF69A,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xDB0C,0xB800,0xB800,0xB000,0xB061,0xC1C7,0x6000,0x0000,0x0000, // row 22, 736 pixels
0x0000,0x0000,0x1800,0xB041,0xB986,0xA800,0xA800,0xB000,0xB000,0xCA49,0xFF7D,0xFFFF,0xDB8E,0xC000,0xC000,0xC000,0xC000,0xC000,0xC986,0xF6DB,0xFFFF,0xFFFF,0xD30C,0xB800,0xB000,0xB000,0xA800,0xB986,0xB041,0x1800,0x0000,0x0000, // row 23, 768 pixels
0x0000,0x0000,0x0000,0x5800,0xB0E3,0xA8C3,0xA800,0xA800,0xA800,0xB000,0xCACB,0xD38E,0xB000,0xB800,0xB800,0xB800,0xB800,0xB800,0xB800,0xC145,0xF6DB,0xD34D,0xB000,0xB000,0xA800,0xA800,0xB0C3,0xB0E3,0x5800,0x0000,0x0000,0x0000, // row 24, 800 pixels
0x0000,0x0000,0x0000,0x0000,0x6000,0xB124,0xA882,0xA000,0xA800,0xA800,0xA800,0xA800,0xB000,0xB000,0xB000,0xB000,0xB000,0xB000,0xB000,0xB000,0xB000,0xA800,0xA800,0xA800,0xA800,0xA882,0xB124,0x6000,0x0000,0x0000,0x0000,0x0000, // row 25, 832 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x6000,0xB104,0xA882,0xA000,0xA000,0xA000,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA800,0xA000,0xA000,0xA882,0xB104,0x6000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 26, 864 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x6000,0xB0A2,0xA8C3,0xA020,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA000,0xA020,0xA8C3,0xB0A2,0x6000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 27, 896 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x4800,0xA800,0xB0C3,0xA0A2,0x9800,0x9800,0x9800,0x9800,0xA000,0xA000,0xA000,0x9800,0x9800,0x9800,0xA082,0xB0E3,0xA800,0x4800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 28, 928 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x5800,0xA800,0xB0A2,0xA8E3,0xA0A2,0xA041,0x9800,0x9800,0xA041,0xA0A2,0xA8E3,0xB0A2,0xA800,0x5800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 29, 960 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3000,0x6000,0x8800,0xA000,0xA800,0xA800,0xA000,0x8800,0x6000,0x3000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 30, 992 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}; // row 31, 1024 pixels
@@ -0,0 +1,109 @@
// Code partly derived from ILI9341_Due library example
// Draws the 3 icons across the middle of the screen and pauses.
// Then draws 300 icons at random locations, clears screen and repeats
//
// This demonstrates drawing icons from FLASH
// Icons are stored in tabs, e.g. Alert.h etc
// more than one icon can be in a header file.
/*
This sketch demonstrates loading images from arrays stored in program (FLASH) memory.
This sketch does not use/need any fonts at all...
Arrays containing FLASH images can be created with UTFT library tool:
(libraries\UTFT\Tools\ImageConverter565.exe)
Convert to .c format then copy into a new tab
The number and size of icons is limited by available FLASH memory. The icon array will
use width x height x 2 bytes of FLASH, i.e. 32 x 32 icon uses ~2048 bytes
*/
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
// Include the header files that contain the icons
#include "alert.h"
#include "Close.h"
#include "Info.h"
long count = 0; // Loop count
void setup()
{
Serial.begin(115200);
tft.init();
tft.setRotation(1); // landscape
tft.fillScreen(TFT_BLACK);
// Draw the icons
drawIcon(info, (tft.width() - infoWidth)/2 - 50, (tft.height() - infoHeight)/2, infoWidth, infoHeight);
drawIcon(alert, (tft.width() - alertWidth)/2, (tft.height() - alertHeight)/2, alertWidth, alertHeight);
drawIcon(close, (tft.width() - closeWidth)/2 + 50, (tft.height() - closeHeight)/2, closeWidth, closeHeight);
// Pause here to admire the icons!
delay(4000);
}
void loop()
{
// Loop filling and clearing screen
drawIcon(info, random(tft.width() - infoWidth), random(tft.height() - infoHeight), infoWidth, infoHeight);
drawIcon(alert, random(tft.width() - alertWidth), random(tft.height() - alertHeight), alertWidth, alertHeight);
drawIcon(close, random(tft.width() - closeWidth), random(tft.height() - closeHeight), alertWidth, closeHeight);
// Clear screen after 100 x 3 = 300 icons drawn
if (100 == count++) {
count = 1;
tft.setRotation(2 * random(2)); // Rotate randomly to clear display left>right or right>left to reduce monotony!
tft.fillScreen(TFT_BLACK);
tft.setRotation(1);
Serial.println(millis());
}
}
//====================================================================================
// This is the function to draw the icon stored as an array in program memory (FLASH)
//====================================================================================
// To speed up rendering we use a 64 pixel buffer
#define BUFF_SIZE 64
// Draw array "icon" of defined width and height at coordinate x,y
// Maximum icon size is 255x255 pixels to avoid integer overflow
void drawIcon(const unsigned short* icon, int16_t x, int16_t y, int8_t width, int8_t height) {
uint16_t pix_buffer[BUFF_SIZE]; // Pixel buffer (16 bits per pixel)
// Set up a window the right size to stream pixels into
tft.setAddrWindow(x, y, x + width - 1, y + height - 1);
// Work out the number whole buffers to send
uint16_t nb = ((uint16_t)height * width) / BUFF_SIZE;
// Fill and send "nb" buffers to TFT
for (int i = 0; i < nb; i++) {
for (int j = 0; j < BUFF_SIZE; j++) {
pix_buffer[j] = pgm_read_word(&icon[i * BUFF_SIZE + j]);
}
tft.pushColors(pix_buffer, BUFF_SIZE);
}
// Work out number of pixels not yet sent
uint16_t np = ((uint16_t)height * width) % BUFF_SIZE;
// Send any partial buffer left over
if (np) {
for (int i = 0; i < np; i++) pix_buffer[i] = pgm_read_word(&icon[nb * BUFF_SIZE + i]);
tft.pushColors(pix_buffer, np);
}
}
+41
View File
@@ -0,0 +1,41 @@
// We need this header file to use FLASH as storage with PROGMEM directive:
#include <avr/pgmspace.h>
// Icon width and height
const uint16_t infoWidth = 32;
const uint16_t infoHeight = 32;
// The icon file can be created with the "UTFT ImageConverter 565" bitmap to .c file creation utility, more can be pasted in here
const unsigned short info[1024] PROGMEM={
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 0, 32 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0861,0x4A69,0x8C71,0xA514,0xBDF7,0xBDF7,0xA514,0x8C71,0x4A69,0x0861,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 1, 64 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x39E7,0x9CF3,0xEF7D,0xF79E,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xFFDF,0xF79E,0xEF7D,0x9CF3,0x39E7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 2, 96 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x2965,0x9492,0xF79E,0xFFDF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFDF,0xF79E,0x9492,0x2965,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 3, 128 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x630C,0xEF7D,0xFFDF,0xFFFF,0xFFFF,0xFFFF,0xD75F,0xB6BF,0x9E5F,0x963F,0x963F,0x9E5F,0xB6BF,0xD75F,0xFFFF,0xFFFF,0xFFFF,0xFFDF,0xEF7D,0x630C,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 4, 160 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x73AE,0xEF7D,0xFFDF,0xFFFF,0xFFDF,0xBEDF,0x7DBF,0x7DBF,0x7DDF,0x7DDF,0x7DDF,0x7DDF,0x7DDF,0x7DBF,0x759F,0x7DBE,0xBEBF,0xFFDF,0xFFFF,0xFFDF,0xEF7D,0x73AE,0x0000,0x0000,0x0000,0x0000,0x0000, // row 5, 192 pixels
0x0000,0x0000,0x0000,0x0000,0x630C,0xEF7D,0xFFFF,0xFFFF,0xE77F,0x7DBE,0x759E,0x759F,0x7DBF,0x7DDF,0x7DDF,0x85FF,0x7DDF,0x7DDF,0x7DBF,0x759F,0x759E,0x6D7E,0x7DBE,0xDF7F,0xFFFF,0xFFFF,0xEF7D,0x630C,0x0000,0x0000,0x0000,0x0000, // row 6, 224 pixels
0x0000,0x0000,0x0000,0x31A6,0xEF5D,0xFFDF,0xFFFF,0xCF1E,0x6D7E,0x6D7E,0x759E,0x759F,0x7DBF,0x7DDF,0x8E1F,0xBEDF,0xC6FF,0x8DFF,0x75BF,0x759F,0x759E,0x6D7E,0x655E,0x655D,0xCF1E,0xFFFF,0xFFDF,0xEF5D,0x31A6,0x0000,0x0000,0x0000, // row 7, 256 pixels
0x0000,0x0000,0x0000,0x94B2,0xF7BE,0xFFFF,0xDF5E,0x655D,0x655D,0x6D7E,0x6D7E,0x759E,0x75BF,0x759F,0xEFBF,0xFFFF,0xFFFF,0xEFBF,0x759F,0x759E,0x6D7E,0x6D7E,0x655D,0x653D,0x653D,0xDF5E,0xFFFF,0xF7BE,0x94B2,0x0000,0x0000,0x0000, // row 8, 288 pixels
0x0000,0x0000,0x4228,0xEF7D,0xFFFF,0xF7BF,0x6D5D,0x653D,0x655D,0x6D5E,0x6D7E,0x759E,0x759E,0x85DF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8DFE,0x6D7E,0x6D7E,0x6D5E,0x655D,0x653D,0x5D1D,0x6D5D,0xF7BF,0xFFFF,0xEF7D,0x4228,0x0000,0x0000, // row 9, 320 pixels
0x0000,0x0000,0xA534,0xFFDF,0xFFDF,0xA65D,0x5D1D,0x5D1D,0x653D,0x655E,0x6D7E,0x6D7E,0x6D7E,0x651E,0xE77F,0xFFFF,0xFFFF,0xF7BF,0x5CFE,0x6D7E,0x6D7E,0x655E,0x653D,0x5D1D,0x5D1D,0x54FC,0xA65D,0xFFDF,0xFFDF,0xA534,0x0000,0x0000, // row 10, 352 pixels
0x0000,0x18E3,0xEF5D,0xFFFF,0xEF9E,0x5CFC,0x54FC,0x5D1D,0x5D3D,0x653D,0x655E,0x6D7E,0x6D7E,0x653E,0x6D3E,0xB67E,0xBEBE,0x755E,0x5D1E,0x6D5E,0x655E,0x653D,0x5D3D,0x5D1D,0x54FC,0x54DC,0x54FC,0xEF9E,0xFFFF,0xEF5D,0x18E3,0x0000, // row 11, 384 pixels
0x0000,0x630C,0xEF7D,0xFFDF,0xB69D,0x54DC,0x54FC,0x5CFC,0x5D1D,0x653D,0x653D,0x655E,0x6D5E,0x655E,0x5CFE,0x4C9D,0x4C7D,0x54DD,0x653E,0x655E,0x653D,0x653D,0x5D1D,0x5CFC,0x54FC,0x54DC,0x4CBC,0xB69D,0xFFDF,0xEF7D,0x630C,0x0000, // row 12, 416 pixels
0x0000,0x94B2,0xF7BE,0xFFDF,0x85BC,0x4CBC,0x54DC,0x54FC,0x5CFD,0x5D1D,0x5D3D,0x653D,0x655D,0x653D,0x85DE,0xC6FE,0xC6FE,0x85BE,0x653D,0x653D,0x5D3D,0x5D1D,0x5CFD,0x54FC,0x54DC,0x4CBC,0x4CBB,0x85BC,0xFFDF,0xF7BE,0x94B2,0x0000, // row 13, 448 pixels
0x0000,0xB5B6,0xFFDF,0xF7BE,0x651C,0x4CBB,0x4CBC,0x54DC,0x54FC,0x5CFC,0x5D1D,0x5D1D,0x653D,0x5D1D,0xE77E,0xFFDF,0xFFDF,0xEF9E,0x5CFD,0x5D1D,0x5D1D,0x5CFC,0x54FC,0x54DC,0x4CBC,0x4CBB,0x449B,0x651B,0xF7BE,0xFFDF,0xB5B6,0x0000, // row 14, 480 pixels
0x0000,0xC638,0xFFDF,0xF7BE,0x54DB,0x449B,0x4CBB,0x4CBC,0x54DC,0x54FC,0x54FC,0x5D1D,0x5D1D,0x7D7D,0xF7BE,0xF7BE,0xF7BE,0xF7BE,0x7D7D,0x5CFD,0x54FC,0x54FC,0x54DC,0x4CBC,0x4CBB,0x449B,0x447B,0x54BB,0xF7BE,0xFFDF,0xC638,0x0000, // row 15, 512 pixels
0x0000,0xC638,0xFFDF,0xF79E,0x4CBB,0x449B,0x449B,0x4CBB,0x4CBC,0x54DC,0x54DC,0x54FC,0x54DC,0x753C,0xF7BE,0xF7BE,0xF7BE,0xF7BE,0x753C,0x54DC,0x54DC,0x54DC,0x4CBC,0x4CBB,0x449B,0x449B,0x3C7B,0x4C9B,0xF79E,0xFFDF,0xC638,0x0000, // row 16, 544 pixels
0x0000,0xB5B6,0xFFDF,0xF7BE,0x5CFB,0x3C7B,0x447B,0x449B,0x4CBB,0x4CBC,0x4CBC,0x4CDC,0x4CBC,0x6D1C,0xF7BE,0xF7BE,0xF7BE,0xF7BE,0x6CFC,0x4CBC,0x4CBC,0x4CBC,0x4CBB,0x449B,0x447B,0x3C7B,0x3C5A,0x54DB,0xF7BE,0xFFDF,0xB5B6,0x0000, // row 17, 576 pixels
0x0000,0x94B2,0xF7BE,0xF7BE,0x755B,0x3C5A,0x3C7B,0x447B,0x449B,0x449B,0x4CBB,0x4CBB,0x4C9B,0x6CFB,0xF79E,0xF79E,0xF79E,0xF79E,0x64FB,0x449B,0x4CBB,0x449B,0x449B,0x447B,0x3C7B,0x3C5A,0x3C5A,0x753B,0xF7BE,0xF7BE,0x9CD3,0x0000, // row 18, 608 pixels
0x0000,0x6B4D,0xEF7D,0xF7BE,0xA61C,0x3C5A,0x3C5A,0x3C7B,0x447B,0x447B,0x449B,0x449B,0x447B,0x64DB,0xF79E,0xF79E,0xF79E,0xF79E,0x64DB,0x447B,0x449B,0x447B,0x447B,0x3C7B,0x3C5A,0x3C5A,0x343A,0xA61C,0xF7BE,0xEF7D,0x6B4D,0x0000, // row 19, 640 pixels
0x0000,0x2124,0xE71C,0xFFDF,0xDF3D,0x3C5A,0x343A,0x3C5A,0x3C5A,0x3C7B,0x3C7B,0x447B,0x3C5B,0x64BA,0xF79E,0xF79E,0xF79E,0xF79E,0x64BA,0x3C5B,0x3C7B,0x3C7B,0x3C5A,0x3C5A,0x343A,0x343A,0x343A,0xDF3D,0xFFDF,0xE71C,0x2124,0x0000, // row 20, 672 pixels
0x0000,0x0000,0xAD75,0xF7BE,0xF79E,0x859B,0x343A,0x343A,0x345A,0x3C5A,0x3C5A,0x3C5A,0x3C5A,0x5C9A,0xEF7D,0xEF7D,0xEF7D,0xEF7D,0x5C9A,0x3C3A,0x3C5A,0x3C5A,0x345A,0x343A,0x343A,0x341A,0x859B,0xF79E,0xF7BE,0xAD75,0x0000,0x0000, // row 21, 704 pixels
0x0000,0x0000,0x528A,0xE71C,0xFFDF,0xDF3D,0x3C5A,0x343A,0x343A,0x343A,0x343A,0x3C5A,0x343A,0x4C5A,0xEF7D,0xEF7D,0xEF7D,0xEF7D,0x4C59,0x343A,0x343A,0x343A,0x343A,0x343A,0x341A,0x3C5A,0xDF3D,0xFFDF,0xE71C,0x528A,0x0000,0x0000, // row 22, 736 pixels
0x0000,0x0000,0x0000,0x9CD3,0xF79E,0xF7BE,0xBE7C,0x3419,0x341A,0x341A,0x343A,0x343A,0x341A,0x2B99,0xC69C,0xEF7D,0xEF7D,0xD6DC,0x2398,0x341A,0x343A,0x341A,0x341A,0x2C19,0x2C19,0xBE7C,0xF7BE,0xF79E,0x9CD3,0x0000,0x0000,0x0000, // row 23, 768 pixels
0x0000,0x0000,0x0000,0x39E7,0xDEDB,0xFFDF,0xF79E,0x9DFB,0x2C19,0x2C19,0x2C1A,0x341A,0x341A,0x2BB9,0x2B57,0x6459,0x74B9,0x2337,0x2BB9,0x341A,0x2C1A,0x2C19,0x2C19,0x2C19,0x9DFB,0xF79E,0xFFDF,0xDEDB,0x39E7,0x0000,0x0000,0x0000, // row 24, 800 pixels
0x0000,0x0000,0x0000,0x0000,0x632C,0xDEFB,0xFFDF,0xEF7D,0xB65C,0x3C39,0x2BF9,0x2C19,0x2C19,0x2BF9,0x2398,0x1B58,0x1B37,0x2398,0x2BF9,0x2C19,0x2BF9,0x2BF9,0x3439,0xB65C,0xEF7D,0xFFDF,0xDEFB,0x632C,0x0000,0x0000,0x0000,0x0000, // row 25, 832 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x73AE,0xDEFB,0xF7BE,0xF79E,0xDF1C,0x7D5A,0x2BF9,0x2BF9,0x2BF9,0x2BF9,0x23D9,0x23D9,0x2BF9,0x2BF9,0x2BF9,0x2BF9,0x7D5A,0xDF1C,0xF79E,0xF7BE,0xDEFB,0x73AE,0x0000,0x0000,0x0000,0x0000,0x0000, // row 26, 864 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x632C,0xDEDB,0xF79E,0xFFDF,0xEF7D,0xD6FC,0x9DFB,0x5CDA,0x4C9A,0x3419,0x3419,0x4C9A,0x5CDA,0x9DFB,0xD6FC,0xEF7D,0xFFDF,0xF79E,0xDEDB,0x632C,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 27, 896 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x4208,0x94B2,0xDEFB,0xF7BE,0xFFDF,0xF7BE,0xF79E,0xEF7D,0xEF5D,0xEF5D,0xEF7D,0xF79E,0xF7BE,0xFFDF,0xF7BE,0xDEFB,0x94B2,0x4208,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 28, 928 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x528A,0xA534,0xDEDB,0xE73C,0xF79E,0xF7BE,0xF7BE,0xF7BE,0xF7BE,0xF79E,0xE73C,0xDEDB,0xA534,0x528A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 29, 960 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x18C3,0x5AEB,0x8C71,0xAD55,0xBDD7,0xBDD7,0xAD55,0x8C71,0x5AEB,0x18C3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 30, 992 pixels
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}; // row 31, 1024 pixels
+218
View File
@@ -0,0 +1,218 @@
/*
* Pong
* Original Code from https://github.com/rparrett/pongclock
*
*/
#define BLACK 0x0000
#define WHITE 0xFFFF
#define GREY 0x5AEB
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
int16_t h = 128;
int16_t w = 160;
int dly = 5;
int16_t paddle_h = 25;
int16_t paddle_w = 2;
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 = 4;
int16_t ball_h = 4;
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);
initgame();
tft.setTextColor(WHITE, BLACK);
delay(2000);
}
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,h-1,BLACK);
tft.setTextDatum(TC_DATUM);
tft.setTextColor(WHITE,GREY);
tft.drawString("TFT_eSPI example", w/2, h-26 , 2);
}
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;
// Quick way to draw a dashed line
tft.setAddrWindow(dashline_x,0,dashline_x+dashline_w-1,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
}
}
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,215 @@
/*
Display all the fonts.
This sketch uses the GLCD (font 1) and fonts 2, 4, 6, 7, 8
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_eSPI library folder.
If using an UNO or Mega (ATmega328 or ATmega2560 processor) then for best
performance use the F_AS_T option found in the User_Setup.h file in the
TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
// New background colour
#define TFT_BROWN 0x38E0
// Pause in milliseconds between screens, change to 0 to time font rendering
#define WAIT 500
#include <TFT_eSPI.h> // Graphics and font library for ST7735 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("01", 0, 0, 8);
delay(WAIT);
tft.drawString("23", 0, 0, 8);
delay(WAIT);
tft.drawString("45", 0, 0, 8);
delay(WAIT);
tft.drawString("67", 0, 0, 8);
delay(WAIT);
tft.drawString("89", 0, 0, 8);
delay(WAIT);
tft.drawString("0:.", 0, 0, 8);
delay(WAIT);
tft.setTextColor(TFT_MAGENTA);
tft.drawNumber(millis() - targetTime, 0, 100, 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);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("4567", 0, 0, 8);
delay(WAIT);
tft.fillScreen(TFT_BROWN);
tft.drawString("890:.", 0, 0, 8);
delay(WAIT);
tft.setTextColor(TFT_MAGENTA);
tft.drawNumber(millis() - targetTime, 0, 100, 4);
delay(4000);;
}
@@ -0,0 +1,210 @@
/*
An example analogue meter using a ST7735 TFT LCD screen
This example uses the hardware SPI only
Needs Font 2 (also Font 4 if using large scale label)
Updated by Bodmer for variable meter size
*/
// Define meter size
#define M_SIZE 0.667
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define ST7735_GREY 0x5AEB
#define ST7735_ORANGE 0xFD20 /* 255, 165, 0 */
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) {
Serial.begin(57600); // For debug
tft.init();
tft.setRotation(3);
tft.fillScreen(ST7735_BLACK);
analogMeter(); // Draw analogue meter
updateTime = millis(); // Next update time
}
void loop() {
if (updateTime <= millis()) {
updateTime = millis() + 35; // Update meter 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);
//value[0] = random(0,100);
//unsigned long tt = millis();
plotNeedle(value[0], 0); // It takes between 2 and 14ms to replot the needle with zero delay
//Serial.println(millis()-tt);
}
}
// #########################################################################
// Draw the analogue meter on the screen
// #########################################################################
void analogMeter()
{
// Meter outline
tft.fillRect(0, 0, M_SIZE*239, M_SIZE*131, ST7735_GREY);
tft.fillRect(1, M_SIZE*3, M_SIZE*234, M_SIZE*125, ST7735_WHITE);
tft.setTextColor(ST7735_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*150;
uint16_t x1 = sx * M_SIZE*100 + M_SIZE*120;
uint16_t y1 = sy * M_SIZE*100 + M_SIZE*150;
// 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*150;
int x3 = sx2 * M_SIZE*100 + M_SIZE*120;
int y3 = sy2 * M_SIZE*100 + M_SIZE*150;
// Yellow zone limits
//if (i >= -50 && i < 0) {
// tft.fillTriangle(x0, y0, x1, y1, x2, y2, ST7735_YELLOW);
// tft.fillTriangle(x1, y1, x2, y2, x3, y3, ST7735_YELLOW);
//}
// Green zone limits
if (i >= 0 && i < 25) {
tft.fillTriangle(x0, y0, x1, y1, x2, y2, ST7735_GREEN);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, ST7735_GREEN);
}
// Orange zone limits
if (i >= 25 && i < 50) {
tft.fillTriangle(x0, y0, x1, y1, x2, y2, ST7735_ORANGE);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, ST7735_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*150;
x1 = sx * M_SIZE*100 + M_SIZE*120;
y1 = sy * M_SIZE*100 + M_SIZE*150;
// Draw tick
tft.drawLine(x0, y0, x1, y1, ST7735_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*150;
switch (i / 25) {
case -2: tft.drawCentreString("0", x0+4, y0-4, 1); break;
case -1: tft.drawCentreString("25", x0+2, y0, 1); break;
case 0: tft.drawCentreString("50", x0, y0, 1); break;
case 1: tft.drawCentreString("75", x0, y0, 1); break;
case 2: tft.drawCentreString("100", x0-2, y0-4, 1); 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*150;
// Draw scale arc, don't draw the last part
if (i < 50) tft.drawLine(x0, y0, x1, y1, ST7735_BLACK);
}
tft.drawString("%RH", M_SIZE*(3 + 230 - 40), M_SIZE*(119 - 20), 2); // Units at bottom right
//tft.drawCentreString("%RH", M_SIZE*120, M_SIZE*75, 4); // Comment out to avoid font 4
tft.drawRect(1, M_SIZE*3, M_SIZE*236, M_SIZE*126, ST7735_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(ST7735_BLACK, ST7735_WHITE);
char buf[8]; dtostrf(value, 4, 0, buf);
tft.drawRightString(buf, 33, 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
// Calculate 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 + 24 * ltx) - 1, M_SIZE*(150 - 24), osx - 1, osy, ST7735_WHITE);
tft.drawLine(M_SIZE*(120 + 24 * ltx), M_SIZE*(150 - 24), osx, osy, ST7735_WHITE);
tft.drawLine(M_SIZE*(120 + 24 * ltx) + 1, M_SIZE*(150 - 24), osx + 1, osy, ST7735_WHITE);
// Re-plot text under needle
tft.setTextColor(ST7735_BLACK, ST7735_WHITE);
//tft.drawCentreString("%RH", M_SIZE*120, M_SIZE*75, 4); // // Comment out to avoid font 4
// Store new needle end coords for next erase
ltx = tx;
osx = M_SIZE*(sx * 98 + 120);
osy = M_SIZE*(sy * 98 + 150);
// Draw the needle in the new postion, magenta makes needle a bit bolder
// draws 3 lines to thicken needle
tft.drawLine(M_SIZE*(120 + 24 * ltx) - 1, M_SIZE*(150 - 24), osx - 1, osy, ST7735_RED);
tft.drawLine(M_SIZE*(120 + 24 * ltx), M_SIZE*(150 - 24), osx, osy, ST7735_MAGENTA);
tft.drawLine(M_SIZE*(120 + 24 * ltx) + 1, M_SIZE*(150 - 24), osx + 1, osy, ST7735_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);
}
}
@@ -0,0 +1,159 @@
/*
Font draw speed and flicker test, draws all numbers 0-999 in each font
(0-99 in font 8)
Average time in milliseconds to draw a character is shown in red
A total of 2890 characters are drawn in each font (190 in font 8)
Needs fonts 2, 4, 6, 7 and 8
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_eSPI library folder.
If using an UNO or Mega (ATmega328 or ATmega2560 processor) then for best
performance use the F_AS_T option found in the User_Setup.h file in the
TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#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 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++) {
tft.drawNumber(i, 0, 0, 1);
}
drawTime = millis() - drawTime;
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.drawFloat(drawTime / 2890.0, 3, 0, 80, 4);
if (drawTime < 100) tft.drawString("Font 1 not loaded!", 0, 108, 2);
delay(4000);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
drawTime = millis();
for (int i = 0; i < 1000; i++) {
tft.drawNumber(i, 0, 0, 2);
}
drawTime = millis() - drawTime;
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.drawFloat(drawTime / 2890.0, 3, 0, 80, 4);
if (drawTime < 200) tft.drawString("Font 2 not loaded!", 0, 108, 2);
delay(4000);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
drawTime = millis();
for (int i = 0; i < 1000; i++) {
tft.drawNumber(i, 0, 0, 4);
}
drawTime = millis() - drawTime;
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.drawFloat(drawTime / 2890.0, 3, 0, 80, 4);
if (drawTime < 200) tft.drawString("Font 4 not loaded!", 0, 108, 2);
delay(4000);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
drawTime = millis();
for (int i = 0; i < 1000; i++) {
tft.drawNumber(i, 0, 0, 6);
}
drawTime = millis() - drawTime;
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.drawFloat(drawTime / 2890.0, 3, 0, 80, 4);
if (drawTime < 200) tft.drawString("Font 6 not loaded!", 0, 108, 2);
delay(4000);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
drawTime = millis();
for (int i = 0; i < 1000; i++) {
tft.drawNumber(i, 0, 0, 7);
}
drawTime = millis() - drawTime;
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.drawFloat(drawTime / 2890.0, 3, 0, 80, 4);
if (drawTime < 200) tft.drawString("Font 7 not loaded!", 0, 108, 2);
delay(4000);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
drawTime = millis();
for (int i = 0; i < 100; i++) {
tft.drawNumber(i, 0, 0, 8);
}
drawTime = millis() - drawTime;
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.drawFloat(drawTime / 190.0, 3, 0, 80, 4);
if (drawTime < 200) tft.drawString("Font 8 not loaded!", 0, 108, 2);
delay(4000);
}
@@ -0,0 +1,135 @@
/*
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.)
For a more accurate clock, it would be better to use the RTClib library.
But this is just a demo.
This examples uses the hardware SPI only. Non-hardware SPI
is just too slow (~8 times slower!)
Based on clock sketch by Gilchrist 6/2/2014 1.0
Updated by Bodmer
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> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
uint32_t targetTime = 0; // for next 1 second timeout
byte omm = 99;
boolean initial = 1;
byte xcolon = 0;
unsigned int colour = 0;
static uint8_t conv2d(const char* p) {
uint8_t v = 0;
if ('0' <= *p && *p <= '9')
v = *p - '0';
return 10 * v + *++p - '0';
}
uint8_t hh=conv2d(__TIME__), mm=conv2d(__TIME__+3), ss=conv2d(__TIME__+6); // Get H, M, S from compile time
void setup(void) {
tft.init();
tft.setRotation(1);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // Note: the new fonts do not draw the background colour
targetTime = millis() + 1000;
}
void loop() {
if (targetTime < millis()) {
targetTime = millis()+1000;
ss++; // Advance second
if (ss==60) {
ss=0;
omm = mm;
mm++; // Advance minute
if(mm>59) {
mm=0;
hh++; // Advance hour
if (hh>23) {
hh=0;
}
}
}
if (ss==0 || initial) {
initial = 0;
tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
tft.setCursor (8, 52);
tft.print(__DATE__); // This uses the standard ADAFruit small font
tft.setTextColor(ST7735_BLUE, ST7735_BLACK);
tft.drawCentreString("It is windy",120,48,2); // Next size up font 2
//tft.setTextColor(0xF81F, ST7735_BLACK); // Pink
//tft.drawCentreString("12.34",80,100,6); // Large font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 . : a p m
}
// Update digital time
byte xpos = 6;
byte ypos = 0;
if (omm != mm) { // Only redraw every minute to minimise flicker
// Uncomment ONE of the next 2 lines, using the ghost image demonstrates text overlay as time is drawn over it
tft.setTextColor(0x39C4, ST7735_BLACK); // Leave a 7 segment ghost image, comment out next line!
//tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Set font colour to back to wipe image
// Font 7 is to show a pseudo 7 segment display.
// Font 7 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : .
tft.drawString("88:88",xpos,ypos,7); // Overwrite the text to clear it
tft.setTextColor(0xFBE0, ST7735_BLACK); // Orange
omm = mm;
if (hh<10) xpos+= tft.drawChar('0',xpos,ypos,7);
xpos+= tft.drawNumber(hh,xpos,ypos,7);
xcolon=xpos;
xpos+= tft.drawChar(':',xpos,ypos,7);
if (mm<10) xpos+= tft.drawChar('0',xpos,ypos,7);
tft.drawNumber(mm,xpos,ypos,7);
}
if (ss%2) { // Flash the colon
tft.setTextColor(0x39C4, ST7735_BLACK);
xpos+= tft.drawChar(':',xcolon,ypos,7);
tft.setTextColor(0xFBE0, ST7735_BLACK);
}
else {
tft.drawChar(':',xcolon,ypos,7);
colour = random(0xFFFF);
// Erase the text with a rectangle
tft.fillRect (0, 64, 160, 20, ST7735_BLACK);
tft.setTextColor(colour);
tft.drawRightString("Colour",75,64,4); // Right justified string drawing to x position 75
String scolour = String(colour,HEX);
scolour.toUpperCase();
char buffer[20];
scolour.toCharArray(buffer,20);
tft.drawString(buffer,82,64,4);
}
}
}
@@ -0,0 +1,134 @@
/*
An example analogue clock using a TFT LCD screen to show the time
use of some of the drawing commands with the ST7735 library.
For a more accurate clock, it would be better to use the RTClib library.
But this is just a demo.
This examples uses the hardware SPI only. Non-hardware SPI
is just too slow (~8 times slower!)
Gilchrist 6/2/2014 1.0
Updated by Bodmer
*/
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
#define ST7735_GREY 0xBDF7
float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; // Saved H, M, S x & y multipliers
float sdeg=0, mdeg=0, hdeg=0;
uint16_t osx=64, osy=64, omx=64, omy=64, ohx=64, ohy=64; // Saved H, M, S x & y coords
uint16_t x0=0, x1=0, y0=0, y1=0;
uint32_t targetTime = 0; // for next 1 second timeout
static uint8_t conv2d(const char* p) {
uint8_t v = 0;
if ('0' <= *p && *p <= '9')
v = *p - '0';
return 10 * v + *++p - '0';
}
uint8_t hh=conv2d(__TIME__), mm=conv2d(__TIME__+3), ss=conv2d(__TIME__+6); // Get H, M, S from compile time
boolean initial = 1;
void setup(void) {
tft.init();
tft.setRotation(0);
tft.fillScreen(ST7735_GREY);
tft.setTextColor(ST7735_GREEN, ST7735_GREY); // Adding a black background colour erases previous text automatically
// Draw clock face
tft.fillCircle(64, 64, 61, ST7735_BLUE);
tft.fillCircle(64, 64, 57, ST7735_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*57+64;
y0 = sy*57+64;
x1 = sx*50+64;
y1 = sy*50+64;
tft.drawLine(x0, y0, x1, y1, ST7735_BLUE);
}
// 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*53+64;
y0 = sy*53+64;
tft.drawPixel(x0, y0, ST7735_BLUE);
if(i==0 || i==180) tft.fillCircle(x0, y0, 1, ST7735_CYAN);
if(i==0 || i==180) tft.fillCircle(x0+1, y0, 1, ST7735_CYAN);
if(i==90 || i==270) tft.fillCircle(x0, y0, 1, ST7735_CYAN);
if(i==90 || i==270) tft.fillCircle(x0+1, y0, 1, ST7735_CYAN);
}
tft.fillCircle(65, 65, 3, ST7735_RED);
// Draw text at position 64,125 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",64,130,4);
targetTime = millis() + 1000;
}
void loop() {
if (targetTime < millis()) {
targetTime = millis()+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, 65, 65, ST7735_BLACK);
ohx = hx*33+65;
ohy = hy*33+65;
tft.drawLine(omx, omy, 65, 65, ST7735_BLACK);
omx = mx*44+65;
omy = my*44+65;
}
// Redraw new hand positions, hour and minute hands not erased here to avoid flicker
tft.drawLine(osx, osy, 65, 65, ST7735_BLACK);
tft.drawLine(ohx, ohy, 65, 65, ST7735_WHITE);
tft.drawLine(omx, omy, 65, 65, ST7735_WHITE);
osx = sx*47+65;
osy = sy*47+65;
tft.drawLine(osx, osy, 65, 65, ST7735_RED);
tft.fillCircle(65, 65, 3, ST7735_RED);
}
}
@@ -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 circles
for (int i = 0; i < 20; i++)
{
int rx = random(40);
int ry = random(40);
int x = rx + random(160 - rx - rx);
int y = ry + random(128 - ry - ry);
tft.fillEllipse(x, y, rx, ry, random(0xFFFF));
}
delay(2000);
tft.fillScreen(TFT_BLACK);
for (int i = 0; i < 20; i++)
{
int rx = random(40);
int ry = random(40);
int x = rx + random(160 - rx - rx);
int y = ry + random(128 - ry - ry);
tft.drawEllipse(x, y, rx, ry, random(0xFFFF));
}
delay(2000);
}
@@ -0,0 +1,90 @@
/*
Test the tft.print() viz embedded tft.write() function
This sketch used font 2, 4, 7
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
#define TFT_GREY 0x5AEB // New colour
void setup(void) {
tft.init();
tft.setRotation(1);
}
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(2);
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((long)3735928559, HEX); // Should print DEADBEEF
// Set the font colour to be green with black background, set to font 2
tft.setTextColor(TFT_GREEN,TFT_BLACK);
tft.setTextFont(2);
tft.println("Groop");
// Test some print formatting functions
float fnumber = 123.45;
// Set the font colour to be blue with no background, set to font 2
tft.setTextColor(TFT_BLUE); tft.setTextFont(2);
tft.print("Float = "); tft.println(fnumber); // Print floating point number
tft.print("Binary = "); tft.println((int)fnumber, BIN); // Print as integer value in binary
tft.print("Hexadecimal = "); tft.println((int)fnumber, HEX); // Print as integer number in Hexadecimal
while(1);
}
@@ -0,0 +1,131 @@
/*
An example showing rainbow colours on a 1.8" TFT LCD screen
and to show a basic example of font use.
This examples uses the hardware SPI only. Non-hardware SPI
is just too slow (~8 times slower!)
Updated by Bodmer
Colours:
code color
0x0000 Black
0xFFFF White
0xBDF7 Light Gray
0x7BEF Dark Gray
0xF800 Red
0xFFE0 Yellow
0xFBE0 Orange
0x79E0 Brown
0x7E0 Green
0x7FF Cyan
0x1F Blue
0xF81F Pink
*/
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;
void setup(void) {
tft.init();
tft.setRotation(1);
tft.fillScreen(ST7735_BLACK);
targetTime = millis() + 1000;
}
void loop() {
if (targetTime < millis()) {
targetTime = millis()+10000;
for (int i = 0; i<160; i++) {
tft.drawFastVLine(i, 0, tft.height(), colour);
switch (state) {
case 0:
green +=2;
if (green == 64) {
green=63;
state = 1;
}
break;
case 1:
red--;
if (red == 255) {
red = 0;
state = 2;
}
break;
case 2:
blue ++;
if (blue == 32) {
blue=31;
state = 3;
}
break;
case 3:
green -=2;
if (green ==255) {
green=0;
state = 4;
}
break;
case 4:
red ++;
if (red == 32) {
red = 31;
state = 5;
}
break;
case 5:
blue --;
if (blue == 255) {
blue = 0;
state = 0;
}
break;
}
colour = red<<11 | green<<5 | blue;
}
// The standard ADAFruit font still works as berfore
tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Note these fonts do not plot the background colour
tft.setCursor (12, 5);
tft.print("Original ADAfruit font!");
// The new larger fonts do not use the .setCursor call, coords are embedded
tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Do not plot the background colour
// Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!)
tft.drawCentreString("Font size 2",80,14,2); // Draw text centre at position 80, 12 using font 2
//tft.drawCentreString("Font size 2",81,12,2); // Draw text centre at position 80, 12 using font 2
tft.drawCentreString("Font size 4",80,30,4); // Draw text centre at position 80, 24 using font 4
tft.drawCentreString("12.34",80,54,6); // Draw text centre at position 80, 24 using font 6
tft.drawCentreString("12.34 is in font size 6",80,92,2); // Draw text centre at position 80, 90 using font 2
// Note the x position is the top of the font!
// draw a floating point number
float pi = 3.14159; // Value to print
int precision = 3; // Number of digits after decimal point
int xpos = 50; // x position
int ypos = 110; // y position
int font = 2; // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : a p m
xpos+=tft.drawFloat(pi,precision,xpos,ypos,font); // Draw rounded number and return new xpos delta for next print position
tft.drawString(" is pi",xpos,ypos,font); // Continue printing from new x position
}
}
@@ -0,0 +1,727 @@
/*
Adapted from the Adafruit and Xark's PDQ graphicstest sketch.
This sketch uses the GLCD font only. Disable other fonts to make
the sketch fit in an UNO!
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
// These are used to get information about static SRAM and flash memory sizes
extern "C" char __data_start[]; // start of SRAM data
extern "C" char _end[]; // end of SRAM data (used to check amount of SRAM this program's variables use)
extern "C" char __data_load_end[]; // end of FLASH (used to check amount of Flash this program's code and data uses)
void setup()
{
Serial.begin(115200);
Serial.println(F("TFT 1.8\" SPI TFT Test! "));
tft.init(); // initialize LCD
}
// NOTE: This demo should run, but may look odd on 128x128 LCD (vs 128x160)
void loop(void)
{
Serial.print(F(__DATE__ " " __TIME__ " - Flash=0x"));
Serial.print((uint16_t)__data_load_end, HEX);
Serial.print(F(" RAM=0x"));
Serial.println((uint16_t)_end - (uint16_t)__data_start, HEX);
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);
tft.setRotation(1);
uint32_t usecText = testText();
Serial.print(F("Text "));
Serial.println(usecText);
delay(100);
tft.setRotation(0);
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.println(F("Bodmer's TFT_eSPI"));
tft.setTextSize(1);
tft.setTextColor(TFT_WHITE);
tft.print(F("SPI LCD on 328p"));
tft.setTextColor(TFT_YELLOW);
tft.print(F("@"));
tft.setTextColor(TFT_WHITE);
tft.print(F("16MHz"));
tft.setTextSize(1);
tft.setTextColor(tft.color565(0x80, 0x80, 0x80));
tft.print(F("Flash=0x"));
tft.print((uint16_t)__data_load_end, HEX);
tft.print(F(" RAM=0x"));
tft.print((uint16_t)_end - (uint16_t)__data_start, HEX);
tft.setTextColor(TFT_GREEN);
tft.print(F("Benchmark usec"));
tft.setTextColor(TFT_CYAN);
tft.print(F("HaD logo "));
tft.setTextColor(TFT_YELLOW);
printnice(usecHaD);
tft.setTextColor(TFT_CYAN);
tft.print(F("Clear "));
tft.setTextColor(TFT_YELLOW);
printnice(usecFillScreen);
tft.setTextColor(TFT_CYAN);
tft.print(F("Text "));
tft.setTextColor(TFT_YELLOW);
printnice(usecText);
tft.setTextColor(TFT_CYAN);
tft.print(F("Pixels "));
tft.setTextColor(TFT_YELLOW);
printnice(usecPixels);
tft.setTextColor(TFT_CYAN);
tft.print(F("Lines "));
tft.setTextColor(TFT_YELLOW);
printnice(usecLines);
tft.setTextColor(TFT_CYAN);
tft.print(F("H/V Lines "));
tft.setTextColor(TFT_YELLOW);
printnice(usecFastLines);
tft.setTextColor(TFT_CYAN);
tft.print(F("Rectangles "));
tft.setTextColor(TFT_YELLOW);
printnice(usecRects);
tft.setTextColor(TFT_CYAN);
tft.print(F("Rects-Fill "));
tft.setTextColor(TFT_YELLOW);
printnice(usecFilledRects);
tft.setTextColor(TFT_CYAN);
tft.print(F("Circles "));
tft.setTextColor(TFT_YELLOW);
printnice(usecCircles);
tft.setTextColor(TFT_CYAN);
tft.print(F("CircleFill "));
tft.setTextColor(TFT_YELLOW);
printnice(usecFilledCircles);
tft.setTextColor(TFT_CYAN);
tft.print(F("Triangles "));
tft.setTextColor(TFT_YELLOW);
printnice(usecTriangles);
tft.setTextColor(TFT_CYAN);
tft.print(F("Tris-Fill "));
tft.setTextColor(TFT_YELLOW);
printnice(usecFilledTrangles);
tft.setTextColor(TFT_CYAN);
tft.print(F("Rnd-Rects "));
tft.setTextColor(TFT_YELLOW);
printnice(usecRoundRects);
tft.setTextColor(TFT_CYAN);
tft.print(F("RRects-Fill"));
tft.setTextColor(TFT_YELLOW);
printnice(usedFilledRoundRects);
tft.setTextSize(1);
tft.println(F(""));
tft.setTextColor(TFT_GREEN);
tft.print(F("Benchmark Completed!"));
delay(15 * 1000L);
}
void printnice(int32_t v)
{
char str[32] = { 0 };
sprintf(str, "%lu", 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.print(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_128x160[] PROGMEM =
{
0x85, 0x91, 0x09, 0x4b, 0x09, 0x24, 0x0a, 0x47, 0x09, 0x27, 0x0a, 0x44, 0x0a, 0x29, 0x0a, 0x42,
0x0a, 0x2b, 0x0a, 0x41, 0x0a, 0x2c, 0x0a, 0x3e, 0x0b, 0x2f, 0x09, 0x3d, 0x09, 0x32, 0x08, 0x3c,
0x09, 0x33, 0x09, 0x3b, 0x08, 0x33, 0x0a, 0x3a, 0x0a, 0x31, 0x0b, 0x3a, 0x0c, 0x1d, 0x01, 0x10,
0x0d, 0x39, 0x0c, 0x1d, 0x01, 0x10, 0x0d, 0x39, 0x0d, 0x0f, 0x01, 0x0c, 0x03, 0x0d, 0x0e, 0x39,
0x0e, 0x0c, 0x03, 0x0c, 0x04, 0x0b, 0x0f, 0x39, 0x0f, 0x0a, 0x04, 0x0c, 0x05, 0x09, 0x10, 0x39,
0x10, 0x08, 0x05, 0x0c, 0x06, 0x07, 0x11, 0x39, 0x11, 0x06, 0x06, 0x0d, 0x07, 0x04, 0x13, 0x37,
0x12, 0x05, 0x07, 0x0d, 0x08, 0x02, 0x15, 0x34, 0x15, 0x03, 0x08, 0x0d, 0x20, 0x32, 0x20, 0x0e,
0x21, 0x31, 0x20, 0x0f, 0x21, 0x2e, 0x22, 0x10, 0x22, 0x2b, 0x22, 0x12, 0x22, 0x12, 0x05, 0x12,
0x22, 0x14, 0x22, 0x0c, 0x0f, 0x0c, 0x22, 0x16, 0x22, 0x08, 0x15, 0x08, 0x22, 0x18, 0x22, 0x05,
0x19, 0x05, 0x21, 0x1c, 0x1f, 0x04, 0x1c, 0x05, 0x1f, 0x1f, 0x1c, 0x04, 0x1e, 0x04, 0x1d, 0x2b,
0x11, 0x04, 0x21, 0x03, 0x12, 0x36, 0x0f, 0x03, 0x24, 0x03, 0x10, 0x38, 0x0d, 0x03, 0x26, 0x03,
0x0d, 0x3b, 0x0b, 0x03, 0x28, 0x03, 0x0b, 0x3d, 0x0a, 0x03, 0x29, 0x03, 0x09, 0x40, 0x07, 0x03,
0x2b, 0x03, 0x07, 0x42, 0x05, 0x03, 0x2c, 0x04, 0x04, 0x45, 0x04, 0x03, 0x2d, 0x03, 0x04, 0x46,
0x02, 0x03, 0x2e, 0x03, 0x03, 0x48, 0x01, 0x03, 0x2f, 0x03, 0x01, 0x4c, 0x31, 0x4e, 0x32, 0x4e,
0x33, 0x4c, 0x34, 0x4c, 0x34, 0x4c, 0x35, 0x4b, 0x35, 0x4a, 0x0e, 0x03, 0x14, 0x04, 0x0d, 0x4a,
0x0b, 0x09, 0x0e, 0x0a, 0x0a, 0x4a, 0x0a, 0x0b, 0x0c, 0x0c, 0x09, 0x4a, 0x09, 0x0d, 0x0a, 0x0e,
0x09, 0x49, 0x08, 0x0f, 0x09, 0x0e, 0x09, 0x49, 0x08, 0x0f, 0x09, 0x0f, 0x08, 0x49, 0x08, 0x0f,
0x09, 0x0f, 0x08, 0x49, 0x07, 0x0f, 0x0a, 0x0f, 0x08, 0x49, 0x07, 0x0f, 0x0b, 0x0e, 0x08, 0x49,
0x07, 0x0d, 0x0e, 0x0d, 0x08, 0x49, 0x07, 0x0b, 0x13, 0x0a, 0x08, 0x49, 0x08, 0x07, 0x18, 0x08,
0x08, 0x49, 0x08, 0x06, 0x1b, 0x06, 0x08, 0x49, 0x09, 0x04, 0x1c, 0x05, 0x08, 0x4a, 0x09, 0x04,
0x1d, 0x04, 0x08, 0x4a, 0x0a, 0x03, 0x1d, 0x03, 0x09, 0x4b, 0x19, 0x02, 0x1a, 0x4b, 0x19, 0x03,
0x19, 0x4b, 0x18, 0x04, 0x18, 0x4d, 0x17, 0x05, 0x17, 0x4a, 0x01, 0x02, 0x17, 0x05, 0x16, 0x4a,
0x02, 0x02, 0x17, 0x05, 0x16, 0x02, 0x03, 0x44, 0x03, 0x03, 0x16, 0x02, 0x01, 0x02, 0x16, 0x02,
0x03, 0x43, 0x05, 0x03, 0x15, 0x01, 0x03, 0x01, 0x15, 0x03, 0x04, 0x41, 0x06, 0x03, 0x15, 0x01,
0x03, 0x01, 0x14, 0x03, 0x07, 0x3d, 0x09, 0x03, 0x2d, 0x03, 0x08, 0x3b, 0x0a, 0x04, 0x2b, 0x03,
0x0a, 0x39, 0x0c, 0x03, 0x2a, 0x04, 0x0b, 0x37, 0x0e, 0x03, 0x28, 0x03, 0x0e, 0x2e, 0x04, 0x03,
0x10, 0x03, 0x27, 0x03, 0x10, 0x03, 0x03, 0x24, 0x19, 0x03, 0x26, 0x03, 0x1a, 0x1e, 0x1d, 0x03,
0x24, 0x03, 0x1e, 0x19, 0x20, 0x04, 0x21, 0x03, 0x20, 0x17, 0x22, 0x04, 0x1f, 0x03, 0x22, 0x15,
0x22, 0x04, 0x21, 0x04, 0x21, 0x13, 0x22, 0x05, 0x15, 0x01, 0x0b, 0x05, 0x21, 0x12, 0x21, 0x06,
0x15, 0x01, 0x0b, 0x06, 0x21, 0x10, 0x21, 0x07, 0x0a, 0x01, 0x0a, 0x01, 0x0b, 0x07, 0x21, 0x0e,
0x20, 0x0a, 0x09, 0x02, 0x09, 0x02, 0x09, 0x09, 0x20, 0x0e, 0x08, 0x02, 0x15, 0x0b, 0x08, 0x03,
0x08, 0x03, 0x08, 0x0b, 0x15, 0x03, 0x08, 0x0d, 0x07, 0x04, 0x13, 0x0d, 0x06, 0x05, 0x06, 0x06,
0x05, 0x0d, 0x14, 0x04, 0x07, 0x0c, 0x07, 0x06, 0x11, 0x38, 0x12, 0x06, 0x06, 0x0c, 0x06, 0x08,
0x10, 0x39, 0x10, 0x08, 0x05, 0x0c, 0x04, 0x0b, 0x0f, 0x39, 0x0f, 0x0a, 0x04, 0x0c, 0x03, 0x0d,
0x0e, 0x39, 0x0e, 0x0c, 0x03, 0x0c, 0x02, 0x0e, 0x0e, 0x39, 0x0d, 0x0f, 0x01, 0x0c, 0x01, 0x10,
0x0d, 0x39, 0x0d, 0x0f, 0x01, 0x1e, 0x0c, 0x39, 0x0c, 0x30, 0x0a, 0x3a, 0x0a, 0x33, 0x09, 0x3b,
0x08, 0x34, 0x09, 0x3b, 0x09, 0x32, 0x09, 0x3c, 0x0a, 0x2f, 0x0a, 0x3e, 0x0a, 0x2d, 0x0b, 0x3f,
0x0a, 0x2b, 0x0b, 0x41, 0x0a, 0x29, 0x0b, 0x43, 0x0a, 0x27, 0x0a, 0x46, 0x0a, 0x25, 0x0a, 0x49,
0x09, 0x23, 0x08, 0x4e, 0x08, 0x96, 0x12
};
tft.fillScreen(TFT_BLACK);
uint32_t start = micros_start();
for (int i = 0; i < 0x10; i++)
{
tft.setAddrWindow(0, 0, tft.width()-1, tft.height()-1);
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_128x160[0];
while (cmp < &HaD_128x160[sizeof(HaD_128x160)])
{
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;
}
}
uint32_t t = micros() - start;
tft.setTextColor(TFT_YELLOW);
tft.setCursor(0, 145);
tft.print(F(" http://hackaday.io/"));
tft.print(F(" Xark"));
delay(3 * 1000L);
return t;
}
uint32_t testFillScreen()
{
uint32_t start = micros_start();
for (uint8_t i = 0; i < 12; i++)
{
tft.fillScreen(TFT_WHITE);
tft.fillScreen(TFT_RED);
tft.fillScreen(TFT_GREEN);
tft.fillScreen(TFT_BLUE);
tft.fillScreen(TFT_BLACK);
}
return micros() - start;
}
uint32_t testText() {
tft.fillScreen(TFT_BLACK);
uint32_t start = micros_start();
tft.setCursor(0, 0);
tft.setTextColor(TFT_WHITE); tft.setTextSize(1);
tft.println(F("Hello World!"));
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.println(1234.56);
tft.setTextColor(TFT_RED);
tft.println(0xDEADBEEF, HEX);
tft.setTextColor(TFT_GREEN);
tft.setTextSize(2);
tft.println(F("Groop"));
tft.println(F("I implore thee,"));
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.setTextColor(TFT_MAGENTA);
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();
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));
}
}
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;
}
@@ -0,0 +1,299 @@
/*
Adapted from the Adafruit graphicstest sketch.
This sketch uses the GLCD font (font 1) only. Disable other fonts to make
the sketch fit in an UNO!
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_eSPI library folder.
If using an UNO or Mega (ATmega328 or ATmega2560 processor) then for best
performance use the F_AS_T option found in the User_Setup.h file in the
TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
Serial.print("Hello! ST7735 TFT Test");
// Use this initializer if you're using a 1.8" TFT
tft.init(); // initialize a ST7735S chip
Serial.println("Initialized");
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK);
time = millis() - time;
Serial.println(time, DEC);
delay(500);
// large block of text
tft.fillScreen(ST7735_BLACK);
testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST7735_WHITE);
delay(1000);
// tft print function!
tftPrintTest();
delay(4000);
// a single pixel
tft.drawPixel(tft.width()/2, tft.height()/2, ST7735_GREEN);
delay(500);
// line draw test
testlines(ST7735_YELLOW);
delay(500);
// optimized lines
testfastlines(ST7735_RED, ST7735_BLUE);
delay(500);
testdrawrects(ST7735_GREEN);
delay(500);
testfillrects(ST7735_YELLOW, ST7735_MAGENTA);
delay(500);
tft.fillScreen(ST7735_BLACK);
testfillcircles(10, ST7735_BLUE);
testdrawcircles(10, ST7735_WHITE);
delay(500);
testroundrects();
delay(500);
testtriangles();
delay(500);
mediabuttons();
delay(500);
Serial.println("done");
delay(1000);
}
void loop() {
tft.invertDisplay(true);
delay(500);
tft.invertDisplay(false);
delay(500);
}
void testlines(uint16_t color) {
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, 0, x, tft.height()-1, color);
}
for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, 0, tft.width()-1, y, color);
}
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
}
for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, 0, 0, y, color);
}
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(0, tft.height()-1, x, 0, color);
}
for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
}
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
}
for (int16_t y=0; y < tft.height(); y+=6) {
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
}
}
void testdrawtext(char *text, uint16_t color) {
tft.setCursor(0, 0);
tft.setTextColor(color);
tft.setTextWrap(true);
tft.print(text);
}
void testfastlines(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
for (int16_t y=0; y < tft.height(); y+=5) {
tft.drawFastHLine(0, y, tft.width(), color1);
}
for (int16_t x=0; x < tft.width(); x+=5) {
tft.drawFastVLine(x, 0, tft.height(), color2);
}
}
void testdrawrects(uint16_t color) {
tft.fillScreen(ST7735_BLACK);
for (int16_t x=0; x < tft.width(); x+=6) {
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
}
}
void testfillrects(uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
for (int16_t x=tft.width()-1; x > 6; x-=6) {
tft.fillRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color1);
tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color2);
}
}
void testfillcircles(uint8_t radius, uint16_t color) {
for (int16_t x=radius; x < tft.width(); x+=radius*2) {
for (int16_t y=radius; y < tft.height(); y+=radius*2) {
tft.fillCircle(x, y, radius, color);
}
}
}
void testdrawcircles(uint8_t radius, uint16_t color) {
for (int16_t x=0; x < tft.width()+radius; x+=radius*2) {
for (int16_t y=0; y < tft.height()+radius; y+=radius*2) {
tft.drawCircle(x, y, radius, color);
}
}
}
void testtriangles() {
tft.fillScreen(ST7735_BLACK);
int color = 0xF800;
int t;
int w = tft.width()/2;
int x = tft.height()-1;
int y = 0;
int z = tft.width();
for(t = 0 ; t <= 15; t+=1) {
tft.drawTriangle(w, y, y, x, z, x, color);
x-=4;
y+=4;
z-=4;
color+=100;
}
}
void testroundrects() {
tft.fillScreen(ST7735_BLACK);
int color = 100;
int i;
int t;
for(t = 0 ; t <= 4; t+=1) {
int x = 0;
int y = 0;
int w = tft.width()-2;
int h = tft.height()-2;
for(i = 0 ; i <= 16; i+=1) {
tft.drawRoundRect(x, y, w, h, 5, color);
x+=2;
y+=3;
w-=4;
h-=6;
color+=1100;
}
color+=100;
}
}
void tftPrintTest() {
tft.setTextWrap(false);
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 30);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(2);
tft.println("Hello World!");
tft.setTextColor(ST7735_GREEN);
tft.setTextSize(3);
tft.println("Hello World!");
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(4);
tft.print(1234.567);
delay(1500);
tft.setCursor(0, 0);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(0);
tft.println("Hello World!");
tft.setTextSize(1);
tft.setTextColor(ST7735_GREEN);
tft.print(p, 6);
tft.println(" Want pi?");
tft.println(" ");
tft.print(8675309, HEX); // print 8,675,309 out in HEX!
tft.println(" Print HEX!");
tft.println(" ");
tft.setTextColor(ST7735_WHITE);
tft.println("Sketch has been");
tft.println("running for: ");
tft.setTextColor(ST7735_MAGENTA);
tft.print(millis() / 1000);
tft.setTextColor(ST7735_WHITE);
tft.print(" seconds.");
}
void mediabuttons() {
// play
tft.fillScreen(ST7735_BLACK);
tft.fillRoundRect(25, 10, 78, 60, 8, ST7735_WHITE);
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_RED);
delay(500);
// pause
tft.fillRoundRect(25, 90, 78, 60, 8, ST7735_WHITE);
tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_GREEN);
tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_GREEN);
delay(500);
// play color
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_BLUE);
delay(50);
// pause color
tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_RED);
tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_RED);
// play color
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_GREEN);
}
@@ -0,0 +1,364 @@
// Demo based on:
// UTFT_Demo_320x240 by Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
/*
This sketch uses the GLCD and font 2 only. Disable other fonts to make
the sketch fit in an UNO!
Make sure all the required fonts are loaded by editting the
User_Setup.h file in the TFT_eSPI library folder.
The library uses the hardware SPI pins only:
For UNO, Nano, Micro Pro ATmega328 based processors
MOSI = pin 11, SCK = pin 13
For Mega:
MOSI = pin 51, SCK = pin 52
The pins used for the TFT chip select (CS) and Data/command (DC) and Reset (RST)
signal lines to the TFT must also be defined in the library User_Setup.h file.
Sugested TFT connections for UNO and Atmega328 based boards
sclk 13 // Don't change, this is the hardware SPI SCLK line
mosi 11 // Don't change, this is the hardware SPI MOSI line
cs 10 // Chip select for TFT display
dc 9 // Data/command line
rst 7 // Reset, you could connect this to the Arduino reset pin
Suggested TFT connections for the MEGA and ATmega2560 based boards
sclk 52 // Don't change, this is the hardware SPI SCLK line
mosi 51 // Don't change, this is the hardware SPI MOSI line
cs 47 // TFT chip select line
dc 48 // TFT data/command line
rst 44 // you could alternatively connect this to the Arduino reset
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
###### TO SELECT THE FONTS AND PINS YOU USE, SEE ABOVE ######
#########################################################################
*/
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>
TFT_eSPI myGLCD = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
#define DELAY 500
#define TFT_GREY 0x7BEF
#define TFT_W 160
#define TFT_H 128
unsigned long runTime = 0;
void setup()
{
randomSeed(analogRead(A0));
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
delay(10);
digitalWrite(7, HIGH);
// Setup the LCD
myGLCD.init();
myGLCD.setRotation(1);
}
void loop()
{
randomSeed(millis());
//randomSeed(1234); // This ensure test is repeatable with exact same draws each loop
int buf[TFT_W-2];
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, TFT_W-1, 14,TFT_RED);
myGLCD.fillRect(0, TFT_H-14, TFT_W-1, 14,TFT_GREY);
myGLCD.setTextColor(TFT_BLACK,TFT_RED);
myGLCD.drawCentreString("* TFT_S6D02A1 *", TFT_W/2, 4, 1);
myGLCD.setTextColor(TFT_YELLOW,TFT_GREY);
myGLCD.drawCentreString("Adapted by Bodmer", TFT_W/2, TFT_H-12,1);
myGLCD.drawRect(0, 14, TFT_W-1, TFT_H-28, TFT_BLUE);
// Draw crosshairs
myGLCD.drawLine(TFT_W/2-1, 15, TFT_W/2-1, TFT_H-16,TFT_BLUE);
myGLCD.drawLine(1, TFT_H/2-1, TFT_W-2, TFT_H/2-1,TFT_BLUE);
for (int i=9; i<TFT_W-1; i+=10)
myGLCD.drawLine(i, TFT_H/2-3, i, TFT_H/2+1,TFT_BLUE);
for (int i=19; i<TFT_H-20; i+=10)
myGLCD.drawLine(TFT_W/2-3, i, TFT_W/2+1, i,TFT_BLUE);
// Draw sin-, cos- and tan-lines
myGLCD.setTextColor(TFT_CYAN);
myGLCD.drawString("Sin", 5, 15,2);
for (int i=1; i<TFT_W-2; i++)
{
myGLCD.drawPixel(i,TFT_H/2-1+(sin(((i*2.26)*3.14)/180)*48),TFT_CYAN);
}
myGLCD.setTextColor(TFT_RED);
myGLCD.drawString("Cos", 5, 30,2);
for (int i=1; i<TFT_W-2; i++)
{
myGLCD.drawPixel(i,TFT_H/2-1+(cos(((i*2.26)*3.14)/180)*48),TFT_RED);
}
myGLCD.setTextColor(TFT_YELLOW);
myGLCD.drawString("Tan", 5, 45,2);
for (int i=1; i<TFT_W-2; i++)
{
myGLCD.drawPixel(i,TFT_H/2-1+(tan(((i*2.26)*3.14)/180)),TFT_YELLOW);
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK);
myGLCD.drawLine(TFT_W/2-1, 15, TFT_W/2-1, TFT_H-16,TFT_BLUE);
myGLCD.drawLine(1, TFT_H/2-1, TFT_W-2, TFT_H/2-1,TFT_BLUE);
int col = 0;
// Draw a moving sinewave
x=1;
for (int i=1; i<((TFT_W-3)*20); i++)
{
x++;
if (x==TFT_W-2)
x=1;
if (i>TFT_W-2)
{
if ((x==TFT_W/2-1)||(buf[x-1]==TFT_H/2-1))
col = TFT_BLUE;
else
myGLCD.drawPixel(x,buf[x-1],TFT_BLACK);
}
y=TFT_H/2 +(sin(((i*2.2)*3.14)/180)*(49-(i / 100)));
myGLCD.drawPixel(x,y,TFT_BLUE);
buf[x-1]=y;
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,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(30+(i*10), 20+(i*10), 30, 30,col);
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,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(TFT_W/2+20-(i*10), 20+(i*10), 30,30, 3,col);
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK);
// 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(45+(i*10),30+(i*10), 15,col);
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK);
// Draw some lines in a pattern
for (int i=15; i<TFT_H-16; i+=5)
{
myGLCD.drawLine(1, i, (i*1.44)-10, TFT_H-17,TFT_RED);
}
for (int i=TFT_H-17; i>15; i-=5)
{
myGLCD.drawLine(TFT_W-3, i, (i*1.44)-11, 15,TFT_RED);
}
for (int i=TFT_H-17; i>15; i-=5)
{
myGLCD.drawLine(1, i, TFT_W+11-(i*1.44), 15,TFT_CYAN);
}
for (int i=15; i<TFT_H-16; i+=5)
{
myGLCD.drawLine(TFT_W-3, i, TFT_W+10-(i*1.44), TFT_H-17,TFT_CYAN);
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK);
// Draw some random circles
for (int i=0; i<100; i++)
{
x=32+random(TFT_W-2-32-30);
y=45+random(TFT_H-19-45-30);
r=random(30);
myGLCD.drawCircle(x, y, r,random(0xFFFF));
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK);
// Draw some random rectangles
for (int i=0; i<100; i++)
{
x=2+random(TFT_W-4);
y=16+random(TFT_H-33);
x2=2+random(TFT_H-4);
y2=16+random(TFT_H-33);
if (x2<x) {
r=x;x=x2;x2=r;
}
if (y2<y) {
r=y;y=y2;y2=r;
}
myGLCD.drawRect(x, y, x2-x, y2-y,random(0xFFFF));
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK);
// Draw some random rounded rectangles
for (int i=0; i<100; i++)
{
x=2+random(TFT_W-4);
y=16+random(TFT_H-33);
x2=2+random(TFT_W-4);
y2=16+random(TFT_H-33);
// 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(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK);
//randomSeed(1234);
int colour = 0;
for (int i=0; i<100; i++)
{
x=2+random(TFT_W-4);
y=16+random(TFT_H-31);
x2=2+random(TFT_W-4);
y2=16+random(TFT_H-31);
colour=random(0xFFFF);
myGLCD.drawLine(x, y, x2, y2,colour);
}
delay(DELAY);
myGLCD.fillRect(1,15,TFT_W-3,TFT_H-31,TFT_BLACK);
// This test has been modified as it takes more time to calculate the random numbers
// 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+TFT_W/2-50,j+TFT_H/2-50,i+j);
}
delay(DELAY);
myGLCD.fillScreen(TFT_BLUE);
myGLCD.fillRoundRect(20, 20, TFT_W-40, TFT_H-60, 6,TFT_RED);
myGLCD.setTextColor(TFT_WHITE,TFT_RED);
myGLCD.drawCentreString("That's it!", TFT_W/2-1, 23,2);
myGLCD.drawCentreString("Restarting in a", TFT_W/2-1, 40,2);
myGLCD.drawCentreString("few seconds...", TFT_W/2-1, 57,2);
runTime = millis()-runTime;
myGLCD.setTextColor(TFT_GREEN,TFT_BLUE);
myGLCD.drawCentreString("Draw time: (msecs)", TFT_W/2, TFT_H-34,2);
myGLCD.drawNumber(runTime-11*DELAY, TFT_W/2-20, TFT_H-17,2);
delay (5000);
}