First draft release
Not yet fully tested but seems to work OK!
This commit is contained in:
1 parent
357665d9b5
commit
e1b2959577
144 files changed
+94409
No files matched your search
@@ -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.
|
||||
*/
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user