mirror of
https://github.com/Bodmer/TFT_eSPI.git
synced 2025-08-06 14:14:44 +02:00
Examples menu now based on resolution
Reference to particular drivers in examples have been removed as multiple display drivers are now supported. Tabs replaced by spaces in header file by file editor. RPi TFT with write strobe SPI clock rate dropped to 20MHz (display cannot cope with new high rate siWriteBlock() function)
This commit is contained in:
48
TFT_eSPI.h
48
TFT_eSPI.h
@@ -87,7 +87,7 @@
|
||||
#else
|
||||
#if defined (ESP32) || defined (D0_USED_FOR_CS)
|
||||
#define CS_L digitalWrite(TFT_CS, LOW)
|
||||
#define CS_H digitalWrite(TFT_CS, HIGH)
|
||||
#define CS_H digitalWrite(TFT_CS, HIGH)
|
||||
#else
|
||||
#define CS_L GPOC=cspinmask
|
||||
#define CS_H GPOS=cspinmask
|
||||
@@ -97,7 +97,7 @@
|
||||
#ifdef TFT_WR
|
||||
#if defined (ESP32)
|
||||
#define WR_L digitalWrite(TFT_WR, LOW)
|
||||
#define WR_H digitalWrite(TFT_WR, HIGH)
|
||||
#define WR_H digitalWrite(TFT_WR, HIGH)
|
||||
#else
|
||||
#define WR_L GPOC=wrpinmask
|
||||
#define WR_H GPOS=wrpinmask
|
||||
@@ -228,11 +228,11 @@ swap_coord(T& a, T& b) { T t = a; a = b; b = t; }
|
||||
// Stores pointer to font character image address table, width table and height
|
||||
|
||||
typedef struct {
|
||||
const uint8_t *chartbl;
|
||||
const uint8_t *widthtbl;
|
||||
uint8_t height;
|
||||
uint8_t baseline;
|
||||
} fontinfo;
|
||||
const uint8_t *chartbl;
|
||||
const uint8_t *widthtbl;
|
||||
uint8_t height;
|
||||
uint8_t baseline;
|
||||
} fontinfo;
|
||||
|
||||
// Now fill the structure
|
||||
const PROGMEM fontinfo fontdata [] = {
|
||||
@@ -357,14 +357,14 @@ class TFT_eSPI : public Print {
|
||||
uint16_t readPixel(int32_t x0, int32_t y0);
|
||||
|
||||
// The next functions can be used as a pair to copy screen blocks (or horizontal/vertical lines) to another location
|
||||
// Read a block of pixels to a data buffer, buffer is 16 bit and the array size must be at least w * h
|
||||
// Read a block of pixels to a data buffer, buffer is 16 bit and the array size must be at least w * h
|
||||
void readRect(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint16_t *data);
|
||||
// Write a block of pixels to the screen
|
||||
// Write a block of pixels to the screen
|
||||
void pushRect(uint32_t x0, uint32_t y0, uint32_t w, uint32_t h, uint16_t *data);
|
||||
|
||||
// This next function has been used successfully to dump the TFT screen to a PC for documentation purposes
|
||||
// It reads a screen area and returns the RGB 8 bit colour values of each pixel
|
||||
// Set w and h to 1 to read 1 pixel's colour. The data buffer must be at least w * h * 3 bytes
|
||||
// This next function has been used successfully to dump the TFT screen to a PC for documentation purposes
|
||||
// It reads a screen area and returns the RGB 8 bit colour values of each pixel
|
||||
// Set w and h to 1 to read 1 pixel's colour. The data buffer must be at least w * h * 3 bytes
|
||||
void readRectRGB(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_t *data);
|
||||
|
||||
uint8_t getRotation(void);
|
||||
@@ -373,30 +373,30 @@ class TFT_eSPI : public Print {
|
||||
color565(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
int16_t drawChar(unsigned int uniCode, int x, int y, int font),
|
||||
drawChar(unsigned int uniCode, int x, int y),
|
||||
drawChar(unsigned int uniCode, int x, int y),
|
||||
drawNumber(long long_num,int poX, int poY, int font),
|
||||
drawNumber(long long_num,int poX, int poY),
|
||||
drawNumber(long long_num,int poX, int poY),
|
||||
drawFloat(float floatNumber,int decimal,int poX, int poY, int font),
|
||||
drawFloat(float floatNumber,int decimal,int poX, int poY),
|
||||
|
||||
// Handle char arrays
|
||||
|
||||
// Handle char arrays
|
||||
drawString(const char *string, int poX, int poY, int font),
|
||||
drawString(const char *string, int poX, int poY),
|
||||
drawCentreString(const char *string, int dX, int poY, int font), // Deprecated, use setTextDatum() and drawString()
|
||||
drawRightString(const char *string, int dX, int poY, int font), // Deprecated, use setTextDatum() and drawString()
|
||||
|
||||
// Handle String type
|
||||
drawString(const String& string, int poX, int poY, int font),
|
||||
drawString(const String& string, int poX, int poY),
|
||||
// Handle String type
|
||||
drawString(const String& string, int poX, int poY, int font),
|
||||
drawString(const String& string, int poX, int poY),
|
||||
drawCentreString(const String& string, int dX, int poY, int font), // Deprecated, use setTextDatum() and drawString()
|
||||
drawRightString(const String& string, int dX, int poY, int font); // Deprecated, use setTextDatum() and drawString()
|
||||
|
||||
|
||||
int16_t height(void),
|
||||
width(void),
|
||||
textWidth(const char *string, int font),
|
||||
textWidth(const char *string),
|
||||
textWidth(const String& string, int font),
|
||||
textWidth(const String& string),
|
||||
textWidth(const char *string),
|
||||
textWidth(const String& string, int font),
|
||||
textWidth(const String& string),
|
||||
fontHeight(int16_t font);
|
||||
|
||||
void setAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye);
|
||||
@@ -409,7 +409,7 @@ inline void spi_begin() __attribute__((always_inline));
|
||||
inline void spi_end() __attribute__((always_inline));
|
||||
|
||||
void readAddrWindow(int32_t xs, int32_t ys, int32_t xe, int32_t ye);
|
||||
|
||||
|
||||
uint8_t tabcolor,
|
||||
colstart = 0, rowstart = 0; // some ST7735 displays need this changed
|
||||
|
||||
|
@@ -144,8 +144,8 @@
|
||||
// #define SPI_FREQUENCY 1000000
|
||||
// #define SPI_FREQUENCY 5000000
|
||||
// #define SPI_FREQUENCY 10000000
|
||||
// #define SPI_FREQUENCY 20000000
|
||||
#define SPI_FREQUENCY 27000000 // Actually sets it to 26.67MHz = 80/3
|
||||
#define SPI_FREQUENCY 20000000
|
||||
// #define SPI_FREQUENCY 27000000 // Actually sets it to 26.67MHz = 80/3
|
||||
// #define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS
|
||||
// #define SPI_FREQUENCY 80000000
|
||||
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
||||
|
||||
#define ST7735_GREY 0xBDF7
|
||||
#define TFT_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;
|
||||
@@ -38,12 +38,12 @@ 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
|
||||
tft.fillScreen(TFT_GREY);
|
||||
tft.setTextColor(TFT_GREEN, TFT_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);
|
||||
tft.fillCircle(64, 64, 61, TFT_BLUE);
|
||||
tft.fillCircle(64, 64, 57, TFT_BLACK);
|
||||
|
||||
// Draw 12 lines
|
||||
for(int i = 0; i<360; i+= 30) {
|
||||
@@ -54,7 +54,7 @@ void setup(void) {
|
||||
x1 = sx*50+64;
|
||||
yy1 = sy*50+64;
|
||||
|
||||
tft.drawLine(x0, yy0, x1, yy1, ST7735_BLUE);
|
||||
tft.drawLine(x0, yy0, x1, yy1, TFT_BLUE);
|
||||
}
|
||||
|
||||
// Draw 60 dots
|
||||
@@ -64,14 +64,14 @@ void setup(void) {
|
||||
x0 = sx*53+64;
|
||||
yy0 = sy*53+64;
|
||||
|
||||
tft.drawPixel(x0, yy0, ST7735_BLUE);
|
||||
if(i==0 || i==180) tft.fillCircle(x0, yy0, 1, ST7735_CYAN);
|
||||
if(i==0 || i==180) tft.fillCircle(x0+1, yy0, 1, ST7735_CYAN);
|
||||
if(i==90 || i==270) tft.fillCircle(x0, yy0, 1, ST7735_CYAN);
|
||||
if(i==90 || i==270) tft.fillCircle(x0+1, yy0, 1, ST7735_CYAN);
|
||||
tft.drawPixel(x0, yy0, TFT_BLUE);
|
||||
if(i==0 || i==180) tft.fillCircle(x0, yy0, 1, TFT_CYAN);
|
||||
if(i==0 || i==180) tft.fillCircle(x0+1, yy0, 1, TFT_CYAN);
|
||||
if(i==90 || i==270) tft.fillCircle(x0, yy0, 1, TFT_CYAN);
|
||||
if(i==90 || i==270) tft.fillCircle(x0+1, yy0, 1, TFT_CYAN);
|
||||
}
|
||||
|
||||
tft.fillCircle(65, 65, 3, ST7735_RED);
|
||||
tft.fillCircle(65, 65, 3, TFT_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
|
||||
@@ -111,23 +111,23 @@ void loop() {
|
||||
if (ss==0 || initial) {
|
||||
initial = 0;
|
||||
// Erase hour and minute hand positions every minute
|
||||
tft.drawLine(ohx, ohy, 65, 65, ST7735_BLACK);
|
||||
tft.drawLine(ohx, ohy, 65, 65, TFT_BLACK);
|
||||
ohx = hx*33+65;
|
||||
ohy = hy*33+65;
|
||||
tft.drawLine(omx, omy, 65, 65, ST7735_BLACK);
|
||||
tft.drawLine(omx, omy, 65, 65, TFT_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);
|
||||
tft.drawLine(osx, osy, 65, 65, TFT_BLACK);
|
||||
tft.drawLine(ohx, ohy, 65, 65, TFT_WHITE);
|
||||
tft.drawLine(omx, omy, 65, 65, TFT_WHITE);
|
||||
osx = sx*47+65;
|
||||
osy = sy*47+65;
|
||||
tft.drawLine(osx, osy, 65, 65, ST7735_RED);
|
||||
tft.drawLine(osx, osy, 65, 65, TFT_RED);
|
||||
|
||||
tft.fillCircle(65, 65, 3, ST7735_RED);
|
||||
tft.fillCircle(65, 65, 3, TFT_RED);
|
||||
}
|
||||
}
|
||||
|
@@ -52,9 +52,9 @@ uint8_t hh=conv2d(__TIME__), mm=conv2d(__TIME__+3), ss=conv2d(__TIME__+6); // G
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); // Note: the new fonts do not draw the background colour
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK); // Note: the new fonts do not draw the background colour
|
||||
|
||||
targetTime = millis() + 1000;
|
||||
}
|
||||
@@ -78,14 +78,14 @@ void loop() {
|
||||
|
||||
if (ss==0 || initial) {
|
||||
initial = 0;
|
||||
tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
|
||||
tft.setTextColor(TFT_GREEN, TFT_BLACK);
|
||||
tft.setCursor (8, 52);
|
||||
tft.print(__DATE__); // This uses the standard ADAFruit small font
|
||||
|
||||
tft.setTextColor(ST7735_BLUE, ST7735_BLACK);
|
||||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
tft.drawCentreString("It is windy",120,48,2); // Next size up font 2
|
||||
|
||||
//tft.setTextColor(0xF81F, ST7735_BLACK); // Pink
|
||||
//tft.setTextColor(0xF81F, TFT_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
|
||||
}
|
||||
|
||||
@@ -94,12 +94,12 @@ void loop() {
|
||||
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 black to wipe image
|
||||
tft.setTextColor(0x39C4, TFT_BLACK); // Leave a 7 segment ghost image, comment out next line!
|
||||
//tft.setTextColor(TFT_BLACK, TFT_BLACK); // Set font colour to black to wipe image
|
||||
// Font 7 is to show a pseudo 7 segment display.
|
||||
// Font 7 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : .
|
||||
tft.drawString("88:88",xpos,ypos,7); // Overwrite the text to clear it
|
||||
tft.setTextColor(0xFBE0, ST7735_BLACK); // Orange
|
||||
tft.setTextColor(0xFBE0, TFT_BLACK); // Orange
|
||||
omm = mm;
|
||||
|
||||
if (hh<10) xpos+= tft.drawChar('0',xpos,ypos,7);
|
||||
@@ -111,15 +111,15 @@ void loop() {
|
||||
}
|
||||
|
||||
if (ss%2) { // Flash the colon
|
||||
tft.setTextColor(0x39C4, ST7735_BLACK);
|
||||
tft.setTextColor(0x39C4, TFT_BLACK);
|
||||
xpos+= tft.drawChar(':',xcolon,ypos,7);
|
||||
tft.setTextColor(0xFBE0, ST7735_BLACK);
|
||||
tft.setTextColor(0xFBE0, TFT_BLACK);
|
||||
}
|
||||
else {
|
||||
tft.drawChar(':',xcolon,ypos,7);
|
||||
colour = random(0xFFFF);
|
||||
// Erase the old text with a rectangle, the disadvantage of this method is increased display flicker
|
||||
tft.fillRect (0, 64, 160, 20, ST7735_BLACK);
|
||||
tft.fillRect (0, 64, 160, 20, TFT_BLACK);
|
||||
tft.setTextColor(colour);
|
||||
tft.drawRightString("Colour",75,64,4); // Right justified string drawing to x position 75
|
||||
String scolour = String(colour,HEX);
|
@@ -15,8 +15,8 @@
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
|
||||
|
||||
#define ST7735_GREY 0x5AEB
|
||||
#define ST7735_ORANGE 0xFD20 /* 255, 165, 0 */
|
||||
#define TFT_GREY 0x5AEB
|
||||
#define TFT_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
|
||||
@@ -33,7 +33,7 @@ void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(3);
|
||||
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
analogMeter(); // Draw analogue meter
|
||||
|
||||
@@ -63,10 +63,10 @@ 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.fillRect(0, 0, M_SIZE*239, M_SIZE*131, TFT_GREY);
|
||||
tft.fillRect(1, M_SIZE*3, M_SIZE*234, M_SIZE*125, TFT_WHITE);
|
||||
|
||||
tft.setTextColor(ST7735_BLACK); // Text colour
|
||||
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) {
|
||||
@@ -91,20 +91,20 @@ void analogMeter()
|
||||
|
||||
// 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);
|
||||
// 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, ST7735_GREEN);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, ST7735_GREEN);
|
||||
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, ST7735_ORANGE);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, ST7735_ORANGE);
|
||||
tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_ORANGE);
|
||||
tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_ORANGE);
|
||||
}
|
||||
|
||||
// Short scale tick length
|
||||
@@ -117,7 +117,7 @@ void analogMeter()
|
||||
y1 = sy * M_SIZE*100 + M_SIZE*150;
|
||||
|
||||
// Draw tick
|
||||
tft.drawLine(x0, y0, x1, y1, ST7735_BLACK);
|
||||
tft.drawLine(x0, y0, x1, y1, TFT_BLACK);
|
||||
|
||||
// Check if labels should be drawn, with position tweaks
|
||||
if (i % 25 == 0) {
|
||||
@@ -139,12 +139,12 @@ void analogMeter()
|
||||
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);
|
||||
if (i < 50) tft.drawLine(x0, y0, x1, y1, TFT_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
|
||||
tft.drawRect(1, M_SIZE*3, M_SIZE*236, M_SIZE*126, TFT_BLACK); // Draw bezel line
|
||||
|
||||
plotNeedle(0, 0); // Put meter needle at 0
|
||||
}
|
||||
@@ -158,7 +158,7 @@ void analogMeter()
|
||||
// #########################################################################
|
||||
void plotNeedle(int value, byte ms_delay)
|
||||
{
|
||||
tft.setTextColor(ST7735_BLACK, ST7735_WHITE);
|
||||
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
||||
char buf[8]; dtostrf(value, 4, 0, buf);
|
||||
tft.drawRightString(buf, 33, M_SIZE*(119 - 20), 2);
|
||||
|
||||
@@ -181,12 +181,12 @@ void plotNeedle(int value, byte ms_delay)
|
||||
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);
|
||||
tft.drawLine(M_SIZE*(120 + 24 * ltx) - 1, M_SIZE*(150 - 24), osx - 1, osy, TFT_WHITE);
|
||||
tft.drawLine(M_SIZE*(120 + 24 * ltx), M_SIZE*(150 - 24), osx, osy, TFT_WHITE);
|
||||
tft.drawLine(M_SIZE*(120 + 24 * ltx) + 1, M_SIZE*(150 - 24), osx + 1, osy, TFT_WHITE);
|
||||
|
||||
// Re-plot text under needle
|
||||
tft.setTextColor(ST7735_BLACK, ST7735_WHITE);
|
||||
tft.setTextColor(TFT_BLACK, TFT_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
|
||||
@@ -196,9 +196,9 @@ void plotNeedle(int value, byte ms_delay)
|
||||
|
||||
// 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);
|
||||
tft.drawLine(M_SIZE*(120 + 24 * ltx) - 1, M_SIZE*(150 - 24), osx - 1, osy, TFT_RED);
|
||||
tft.drawLine(M_SIZE*(120 + 24 * ltx), M_SIZE*(150 - 24), osx, osy, TFT_MAGENTA);
|
||||
tft.drawLine(M_SIZE*(120 + 24 * ltx) + 1, M_SIZE*(150 - 24), 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;
|
@@ -28,7 +28,7 @@ unsigned int colour = red << 11;
|
||||
void setup(void) {
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
targetTime = millis() + 1000;
|
||||
}
|
||||
@@ -89,12 +89,12 @@ void loop() {
|
||||
}
|
||||
|
||||
// The standard ADAFruit font still works as before
|
||||
tft.setTextColor(ST7735_BLACK);
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.setCursor (12, 5);
|
||||
tft.print("Original ADAfruit font!");
|
||||
|
||||
// The new larger fonts do not use the .setCursor call, coords are embedded
|
||||
tft.setTextColor(ST7735_BLACK, ST7735_BLACK); // Do not plot the background colour
|
||||
tft.setTextColor(TFT_BLACK, 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", 80, 14, 2); // Draw text centre at position 80, 12 using font 2
|
@@ -33,15 +33,15 @@ void setup(void) {
|
||||
Serial.println("Initialized");
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_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);
|
||||
tft.fillScreen(TFT_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. ", TFT_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
@@ -49,26 +49,26 @@ void setup(void) {
|
||||
delay(4000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, ST7735_GREEN);
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, TFT_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST7735_YELLOW);
|
||||
testlines(TFT_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST7735_RED, ST7735_BLUE);
|
||||
testfastlines(TFT_RED, TFT_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST7735_GREEN);
|
||||
testdrawrects(TFT_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST7735_YELLOW, ST7735_MAGENTA);
|
||||
testfillrects(TFT_YELLOW, TFT_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
testfillcircles(10, ST7735_BLUE);
|
||||
testdrawcircles(10, ST7735_WHITE);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
testfillcircles(10, TFT_BLUE);
|
||||
testdrawcircles(10, TFT_WHITE);
|
||||
delay(500);
|
||||
|
||||
testroundrects();
|
||||
@@ -92,7 +92,7 @@ void loop() {
|
||||
}
|
||||
|
||||
void testlines(uint16_t color) {
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, 0, x, tft.height()-1, color);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ void testlines(uint16_t color) {
|
||||
tft.drawLine(0, 0, tft.width()-1, y, color);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
|
||||
}
|
||||
@@ -108,7 +108,7 @@ void testlines(uint16_t color) {
|
||||
tft.drawLine(tft.width()-1, 0, 0, y, color);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, tft.height()-1, x, 0, color);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ void testlines(uint16_t color) {
|
||||
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ void testdrawtext(char *text, uint16_t color) {
|
||||
}
|
||||
|
||||
void testfastlines(uint16_t color1, uint16_t color2) {
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
for (int16_t y=0; y < tft.height(); y+=5) {
|
||||
tft.drawFastHLine(0, y, tft.width(), color1);
|
||||
}
|
||||
@@ -143,14 +143,14 @@ void testfastlines(uint16_t color1, uint16_t color2) {
|
||||
}
|
||||
|
||||
void testdrawrects(uint16_t color) {
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_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);
|
||||
tft.fillScreen(TFT_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);
|
||||
@@ -174,7 +174,7 @@ void testdrawcircles(uint8_t radius, uint16_t color) {
|
||||
}
|
||||
|
||||
void testtriangles() {
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
int color = 0xF800;
|
||||
int t;
|
||||
int w = tft.width()/2;
|
||||
@@ -191,7 +191,7 @@ void testtriangles() {
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
int color = 100;
|
||||
int i;
|
||||
int t;
|
||||
@@ -214,61 +214,61 @@ void testroundrects() {
|
||||
|
||||
void tftPrintTest() {
|
||||
tft.setTextWrap(false);
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST7735_RED);
|
||||
tft.setTextColor(TFT_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST7735_YELLOW);
|
||||
tft.setTextColor(TFT_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST7735_GREEN);
|
||||
tft.setTextColor(TFT_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST7735_BLUE);
|
||||
tft.setTextColor(TFT_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
tft.setTextColor(ST7735_WHITE);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST7735_GREEN);
|
||||
tft.setTextColor(TFT_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.setTextColor(TFT_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST7735_MAGENTA);
|
||||
tft.setTextColor(TFT_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST7735_WHITE);
|
||||
tft.setTextColor(TFT_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);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.fillRoundRect(25, 10, 78, 60, 8, TFT_WHITE);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, TFT_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);
|
||||
tft.fillRoundRect(25, 90, 78, 60, 8, TFT_WHITE);
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, TFT_GREEN);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, TFT_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_BLUE);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, TFT_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_RED);
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, TFT_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, TFT_RED);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_GREEN);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, TFT_GREEN);
|
||||
}
|
||||
|
Reference in New Issue
Block a user