First init.
This commit is contained in:
384
libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST7735.cpp
Normal file
384
libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST7735.cpp
Normal file
@@ -0,0 +1,384 @@
|
||||
#include "Adafruit_ST7735.h"
|
||||
#include "Adafruit_ST77xx.h"
|
||||
|
||||
// CONSTRUCTORS ************************************************************
|
||||
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST7735 driver with software SPI
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param mosi SPI MOSI pin #
|
||||
@param sclk SPI Clock pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
Adafruit_ST7735::Adafruit_ST7735(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk,
|
||||
int8_t rst)
|
||||
: Adafruit_ST77xx(ST7735_TFTWIDTH_128, ST7735_TFTHEIGHT_160, cs, dc, mosi,
|
||||
sclk, rst) {}
|
||||
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST7735 driver with default hardware SPI
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
Adafruit_ST7735::Adafruit_ST7735(int8_t cs, int8_t dc, int8_t rst)
|
||||
: Adafruit_ST77xx(ST7735_TFTWIDTH_128, ST7735_TFTHEIGHT_160, cs, dc, rst) {}
|
||||
|
||||
#if !defined(ESP8266)
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST7735 driver with selectable hardware SPI
|
||||
@param spiClass Pointer to an SPI device to use (e.g. &SPI1)
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
Adafruit_ST7735::Adafruit_ST7735(SPIClass *spiClass, int8_t cs, int8_t dc,
|
||||
int8_t rst)
|
||||
: Adafruit_ST77xx(ST7735_TFTWIDTH_128, ST7735_TFTHEIGHT_160, spiClass, cs,
|
||||
dc, rst) {}
|
||||
#endif // end !ESP8266
|
||||
|
||||
// SCREEN INITIALIZATION ***************************************************
|
||||
|
||||
// Rather than a bazillion writecommand() and writedata() calls, screen
|
||||
// initialization commands and arguments are organized in these tables
|
||||
// stored in PROGMEM. The table may look bulky, but that's mostly the
|
||||
// formatting -- storage-wise this is hundreds of bytes more compact
|
||||
// than the equivalent code. Companion function follows.
|
||||
|
||||
// clang-format off
|
||||
static const uint8_t PROGMEM
|
||||
Bcmd[] = { // Init commands for 7735B screens
|
||||
18, // 18 commands in list:
|
||||
ST77XX_SWRESET, ST_CMD_DELAY, // 1: Software reset, no args, w/delay
|
||||
50, // 50 ms delay
|
||||
ST77XX_SLPOUT, ST_CMD_DELAY, // 2: Out of sleep mode, no args, w/delay
|
||||
255, // 255 = max (500 ms) delay
|
||||
ST77XX_COLMOD, 1+ST_CMD_DELAY, // 3: Set color mode, 1 arg + delay:
|
||||
0x05, // 16-bit color
|
||||
10, // 10 ms delay
|
||||
ST7735_FRMCTR1, 3+ST_CMD_DELAY, // 4: Frame rate control, 3 args + delay:
|
||||
0x00, // fastest refresh
|
||||
0x06, // 6 lines front porch
|
||||
0x03, // 3 lines back porch
|
||||
10, // 10 ms delay
|
||||
ST77XX_MADCTL, 1, // 5: Mem access ctl (directions), 1 arg:
|
||||
0x08, // Row/col addr, bottom-top refresh
|
||||
ST7735_DISSET5, 2, // 6: Display settings #5, 2 args:
|
||||
0x15, // 1 clk cycle nonoverlap, 2 cycle gate
|
||||
// rise, 3 cycle osc equalize
|
||||
0x02, // Fix on VTL
|
||||
ST7735_INVCTR, 1, // 7: Display inversion control, 1 arg:
|
||||
0x0, // Line inversion
|
||||
ST7735_PWCTR1, 2+ST_CMD_DELAY, // 8: Power control, 2 args + delay:
|
||||
0x02, // GVDD = 4.7V
|
||||
0x70, // 1.0uA
|
||||
10, // 10 ms delay
|
||||
ST7735_PWCTR2, 1, // 9: Power control, 1 arg, no delay:
|
||||
0x05, // VGH = 14.7V, VGL = -7.35V
|
||||
ST7735_PWCTR3, 2, // 10: Power control, 2 args, no delay:
|
||||
0x01, // Opamp current small
|
||||
0x02, // Boost frequency
|
||||
ST7735_VMCTR1, 2+ST_CMD_DELAY, // 11: Power control, 2 args + delay:
|
||||
0x3C, // VCOMH = 4V
|
||||
0x38, // VCOML = -1.1V
|
||||
10, // 10 ms delay
|
||||
ST7735_PWCTR6, 2, // 12: Power control, 2 args, no delay:
|
||||
0x11, 0x15,
|
||||
ST7735_GMCTRP1,16, // 13: Gamma Adjustments (pos. polarity), 16 args + delay:
|
||||
0x09, 0x16, 0x09, 0x20, // (Not entirely necessary, but provides
|
||||
0x21, 0x1B, 0x13, 0x19, // accurate colors)
|
||||
0x17, 0x15, 0x1E, 0x2B,
|
||||
0x04, 0x05, 0x02, 0x0E,
|
||||
ST7735_GMCTRN1,16+ST_CMD_DELAY, // 14: Gamma Adjustments (neg. polarity), 16 args + delay:
|
||||
0x0B, 0x14, 0x08, 0x1E, // (Not entirely necessary, but provides
|
||||
0x22, 0x1D, 0x18, 0x1E, // accurate colors)
|
||||
0x1B, 0x1A, 0x24, 0x2B,
|
||||
0x06, 0x06, 0x02, 0x0F,
|
||||
10, // 10 ms delay
|
||||
ST77XX_CASET, 4, // 15: Column addr set, 4 args, no delay:
|
||||
0x00, 0x02, // XSTART = 2
|
||||
0x00, 0x81, // XEND = 129
|
||||
ST77XX_RASET, 4, // 16: Row addr set, 4 args, no delay:
|
||||
0x00, 0x02, // XSTART = 1
|
||||
0x00, 0x81, // XEND = 160
|
||||
ST77XX_NORON, ST_CMD_DELAY, // 17: Normal display on, no args, w/delay
|
||||
10, // 10 ms delay
|
||||
ST77XX_DISPON, ST_CMD_DELAY, // 18: Main screen turn on, no args, delay
|
||||
255 }, // 255 = max (500 ms) delay
|
||||
|
||||
Rcmd1[] = { // 7735R init, part 1 (red or green tab)
|
||||
15, // 15 commands in list:
|
||||
ST77XX_SWRESET, ST_CMD_DELAY, // 1: Software reset, 0 args, w/delay
|
||||
150, // 150 ms delay
|
||||
ST77XX_SLPOUT, ST_CMD_DELAY, // 2: Out of sleep mode, 0 args, w/delay
|
||||
255, // 500 ms delay
|
||||
ST7735_FRMCTR1, 3, // 3: Framerate ctrl - normal mode, 3 arg:
|
||||
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
|
||||
ST7735_FRMCTR2, 3, // 4: Framerate ctrl - idle mode, 3 args:
|
||||
0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
|
||||
ST7735_FRMCTR3, 6, // 5: Framerate - partial mode, 6 args:
|
||||
0x01, 0x2C, 0x2D, // Dot inversion mode
|
||||
0x01, 0x2C, 0x2D, // Line inversion mode
|
||||
ST7735_INVCTR, 1, // 6: Display inversion ctrl, 1 arg:
|
||||
0x07, // No inversion
|
||||
ST7735_PWCTR1, 3, // 7: Power control, 3 args, no delay:
|
||||
0xA2,
|
||||
0x02, // -4.6V
|
||||
0x84, // AUTO mode
|
||||
ST7735_PWCTR2, 1, // 8: Power control, 1 arg, no delay:
|
||||
0xC5, // VGH25=2.4C VGSEL=-10 VGH=3 * AVDD
|
||||
ST7735_PWCTR3, 2, // 9: Power control, 2 args, no delay:
|
||||
0x0A, // Opamp current small
|
||||
0x00, // Boost frequency
|
||||
ST7735_PWCTR4, 2, // 10: Power control, 2 args, no delay:
|
||||
0x8A, // BCLK/2,
|
||||
0x2A, // opamp current small & medium low
|
||||
ST7735_PWCTR5, 2, // 11: Power control, 2 args, no delay:
|
||||
0x8A, 0xEE,
|
||||
ST7735_VMCTR1, 1, // 12: Power control, 1 arg, no delay:
|
||||
0x0E,
|
||||
ST77XX_INVOFF, 0, // 13: Don't invert display, no args
|
||||
ST77XX_MADCTL, 1, // 14: Mem access ctl (directions), 1 arg:
|
||||
0xC8, // row/col addr, bottom-top refresh
|
||||
ST77XX_COLMOD, 1, // 15: set color mode, 1 arg, no delay:
|
||||
0x05 }, // 16-bit color
|
||||
|
||||
Rcmd2green[] = { // 7735R init, part 2 (green tab only)
|
||||
2, // 2 commands in list:
|
||||
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
|
||||
0x00, 0x02, // XSTART = 0
|
||||
0x00, 0x7F+0x02, // XEND = 127
|
||||
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
|
||||
0x00, 0x01, // XSTART = 0
|
||||
0x00, 0x9F+0x01 }, // XEND = 159
|
||||
|
||||
Rcmd2red[] = { // 7735R init, part 2 (red tab only)
|
||||
2, // 2 commands in list:
|
||||
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x7F, // XEND = 127
|
||||
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x9F }, // XEND = 159
|
||||
|
||||
Rcmd2green144[] = { // 7735R init, part 2 (green 1.44 tab)
|
||||
2, // 2 commands in list:
|
||||
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x7F, // XEND = 127
|
||||
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x7F }, // XEND = 127
|
||||
|
||||
Rcmd2green160x80[] = { // 7735R init, part 2 (mini 160x80)
|
||||
2, // 2 commands in list:
|
||||
ST77XX_CASET, 4, // 1: Column addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x4F, // XEND = 79
|
||||
ST77XX_RASET, 4, // 2: Row addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x9F }, // XEND = 159
|
||||
|
||||
Rcmd2green160x80plugin[] = { // 7735R init, part 2 (mini 160x80 with plugin FPC)
|
||||
3, // 3 commands in list:
|
||||
ST77XX_INVON, 0, // 1: Display is inverted
|
||||
ST77XX_CASET, 4, // 2: Column addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x4F, // XEND = 79
|
||||
ST77XX_RASET, 4, // 3: Row addr set, 4 args, no delay:
|
||||
0x00, 0x00, // XSTART = 0
|
||||
0x00, 0x9F }, // XEND = 159
|
||||
|
||||
Rcmd3[] = { // 7735R init, part 3 (red or green tab)
|
||||
4, // 4 commands in list:
|
||||
ST7735_GMCTRP1, 16 , // 1: Gamma Adjustments (pos. polarity), 16 args + delay:
|
||||
0x02, 0x1c, 0x07, 0x12, // (Not entirely necessary, but provides
|
||||
0x37, 0x32, 0x29, 0x2d, // accurate colors)
|
||||
0x29, 0x25, 0x2B, 0x39,
|
||||
0x00, 0x01, 0x03, 0x10,
|
||||
ST7735_GMCTRN1, 16 , // 2: Gamma Adjustments (neg. polarity), 16 args + delay:
|
||||
0x03, 0x1d, 0x07, 0x06, // (Not entirely necessary, but provides
|
||||
0x2E, 0x2C, 0x29, 0x2D, // accurate colors)
|
||||
0x2E, 0x2E, 0x37, 0x3F,
|
||||
0x00, 0x00, 0x02, 0x10,
|
||||
ST77XX_NORON, ST_CMD_DELAY, // 3: Normal display on, no args, w/delay
|
||||
10, // 10 ms delay
|
||||
ST77XX_DISPON, ST_CMD_DELAY, // 4: Main screen turn on, no args w/delay
|
||||
100 }; // 100 ms delay
|
||||
|
||||
// clang-format on
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initialization code common to all ST7735B displays
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST7735::initB(void) {
|
||||
commonInit(Bcmd);
|
||||
setRotation(0);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initialization code common to all ST7735R displays
|
||||
@param options Tab color from adafruit purchase
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST7735::initR(uint8_t options) {
|
||||
commonInit(Rcmd1);
|
||||
if (options == INITR_GREENTAB) {
|
||||
displayInit(Rcmd2green);
|
||||
_colstart = 2;
|
||||
_rowstart = 1;
|
||||
} else if ((options == INITR_144GREENTAB) || (options == INITR_HALLOWING)) {
|
||||
_height = ST7735_TFTHEIGHT_128;
|
||||
_width = ST7735_TFTWIDTH_128;
|
||||
displayInit(Rcmd2green144);
|
||||
_colstart = 2;
|
||||
_rowstart = 3; // For default rotation 0
|
||||
} else if (options == INITR_MINI160x80) {
|
||||
_height = ST7735_TFTWIDTH_80;
|
||||
_width = ST7735_TFTHEIGHT_160;
|
||||
displayInit(Rcmd2green160x80);
|
||||
_colstart = 24;
|
||||
_rowstart = 0;
|
||||
} else if (options == INITR_MINI160x80_PLUGIN) {
|
||||
_height = ST7735_TFTWIDTH_80;
|
||||
_width = ST7735_TFTHEIGHT_160;
|
||||
displayInit(Rcmd2green160x80plugin);
|
||||
_colstart = 26;
|
||||
_rowstart = 1;
|
||||
invertOnCommand = ST77XX_INVOFF;
|
||||
invertOffCommand = ST77XX_INVON;
|
||||
} else {
|
||||
// colstart, rowstart left at default '0' values
|
||||
displayInit(Rcmd2red);
|
||||
}
|
||||
displayInit(Rcmd3);
|
||||
|
||||
// Black tab, change MADCTL color filter
|
||||
if ((options == INITR_BLACKTAB) || (options == INITR_MINI160x80)) {
|
||||
uint8_t data = 0xC0;
|
||||
sendCommand(ST77XX_MADCTL, &data, 1);
|
||||
}
|
||||
|
||||
if (options == INITR_HALLOWING) {
|
||||
// Hallowing is simply a 1.44" green tab upside-down:
|
||||
tabcolor = INITR_144GREENTAB;
|
||||
setRotation(2);
|
||||
} else {
|
||||
tabcolor = options;
|
||||
setRotation(0);
|
||||
}
|
||||
}
|
||||
|
||||
// OTHER FUNCTIONS *********************************************************
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set origin of (0,0) and orientation of TFT display
|
||||
@param m The index for rotation, from 0-3 inclusive
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST7735::setRotation(uint8_t m) {
|
||||
uint8_t madctl = 0;
|
||||
|
||||
rotation = m & 3; // can't be higher than 3
|
||||
|
||||
// For ST7735 with GREEN TAB (including HalloWing)...
|
||||
if ((tabcolor == INITR_144GREENTAB) || (tabcolor == INITR_HALLOWING)) {
|
||||
// ..._rowstart is 3 for rotations 0&1, 1 for rotations 2&3
|
||||
_rowstart = (rotation < 2) ? 3 : 1;
|
||||
}
|
||||
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) {
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB;
|
||||
} else {
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST7735_MADCTL_BGR;
|
||||
}
|
||||
|
||||
if (tabcolor == INITR_144GREENTAB) {
|
||||
_height = ST7735_TFTHEIGHT_128;
|
||||
_width = ST7735_TFTWIDTH_128;
|
||||
} else if (tabcolor == INITR_MINI160x80 ||
|
||||
tabcolor == INITR_MINI160x80_PLUGIN) {
|
||||
_height = ST7735_TFTHEIGHT_160;
|
||||
_width = ST7735_TFTWIDTH_80;
|
||||
} else {
|
||||
_height = ST7735_TFTHEIGHT_160;
|
||||
_width = ST7735_TFTWIDTH_128;
|
||||
}
|
||||
_xstart = _colstart;
|
||||
_ystart = _rowstart;
|
||||
break;
|
||||
case 1:
|
||||
if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) {
|
||||
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB;
|
||||
} else {
|
||||
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST7735_MADCTL_BGR;
|
||||
}
|
||||
|
||||
if (tabcolor == INITR_144GREENTAB) {
|
||||
_width = ST7735_TFTHEIGHT_128;
|
||||
_height = ST7735_TFTWIDTH_128;
|
||||
} else if (tabcolor == INITR_MINI160x80 ||
|
||||
tabcolor == INITR_MINI160x80_PLUGIN) {
|
||||
_width = ST7735_TFTHEIGHT_160;
|
||||
_height = ST7735_TFTWIDTH_80;
|
||||
} else {
|
||||
_width = ST7735_TFTHEIGHT_160;
|
||||
_height = ST7735_TFTWIDTH_128;
|
||||
}
|
||||
_ystart = _colstart;
|
||||
_xstart = _rowstart;
|
||||
break;
|
||||
case 2:
|
||||
if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) {
|
||||
madctl = ST77XX_MADCTL_RGB;
|
||||
} else {
|
||||
madctl = ST7735_MADCTL_BGR;
|
||||
}
|
||||
|
||||
if (tabcolor == INITR_144GREENTAB) {
|
||||
_height = ST7735_TFTHEIGHT_128;
|
||||
_width = ST7735_TFTWIDTH_128;
|
||||
} else if (tabcolor == INITR_MINI160x80 ||
|
||||
tabcolor == INITR_MINI160x80_PLUGIN) {
|
||||
_height = ST7735_TFTHEIGHT_160;
|
||||
_width = ST7735_TFTWIDTH_80;
|
||||
} else {
|
||||
_height = ST7735_TFTHEIGHT_160;
|
||||
_width = ST7735_TFTWIDTH_128;
|
||||
}
|
||||
_xstart = _colstart;
|
||||
_ystart = _rowstart;
|
||||
break;
|
||||
case 3:
|
||||
if ((tabcolor == INITR_BLACKTAB) || (tabcolor == INITR_MINI160x80)) {
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB;
|
||||
} else {
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST7735_MADCTL_BGR;
|
||||
}
|
||||
|
||||
if (tabcolor == INITR_144GREENTAB) {
|
||||
_width = ST7735_TFTHEIGHT_128;
|
||||
_height = ST7735_TFTWIDTH_128;
|
||||
} else if (tabcolor == INITR_MINI160x80 ||
|
||||
tabcolor == INITR_MINI160x80_PLUGIN) {
|
||||
_width = ST7735_TFTHEIGHT_160;
|
||||
_height = ST7735_TFTWIDTH_80;
|
||||
} else {
|
||||
_width = ST7735_TFTHEIGHT_160;
|
||||
_height = ST7735_TFTWIDTH_128;
|
||||
}
|
||||
_ystart = _colstart;
|
||||
_xstart = _rowstart;
|
||||
break;
|
||||
}
|
||||
|
||||
sendCommand(ST77XX_MADCTL, &madctl, 1);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#ifndef _ADAFRUIT_ST7735H_
|
||||
#define _ADAFRUIT_ST7735H_
|
||||
|
||||
#include "Adafruit_ST77xx.h"
|
||||
|
||||
// some flags for initR() :(
|
||||
#define INITR_GREENTAB 0x00
|
||||
#define INITR_REDTAB 0x01
|
||||
#define INITR_BLACKTAB 0x02
|
||||
#define INITR_18GREENTAB INITR_GREENTAB
|
||||
#define INITR_18REDTAB INITR_REDTAB
|
||||
#define INITR_18BLACKTAB INITR_BLACKTAB
|
||||
#define INITR_144GREENTAB 0x01
|
||||
#define INITR_MINI160x80 0x04
|
||||
#define INITR_HALLOWING 0x05
|
||||
#define INITR_MINI160x80_PLUGIN 0x06
|
||||
|
||||
// Some register settings
|
||||
#define ST7735_MADCTL_BGR 0x08
|
||||
#define ST7735_MADCTL_MH 0x04
|
||||
|
||||
#define ST7735_FRMCTR1 0xB1
|
||||
#define ST7735_FRMCTR2 0xB2
|
||||
#define ST7735_FRMCTR3 0xB3
|
||||
#define ST7735_INVCTR 0xB4
|
||||
#define ST7735_DISSET5 0xB6
|
||||
|
||||
#define ST7735_PWCTR1 0xC0
|
||||
#define ST7735_PWCTR2 0xC1
|
||||
#define ST7735_PWCTR3 0xC2
|
||||
#define ST7735_PWCTR4 0xC3
|
||||
#define ST7735_PWCTR5 0xC4
|
||||
#define ST7735_VMCTR1 0xC5
|
||||
|
||||
#define ST7735_PWCTR6 0xFC
|
||||
|
||||
#define ST7735_GMCTRP1 0xE0
|
||||
#define ST7735_GMCTRN1 0xE1
|
||||
|
||||
// Some ready-made 16-bit ('565') color settings:
|
||||
#define ST7735_BLACK ST77XX_BLACK
|
||||
#define ST7735_WHITE ST77XX_WHITE
|
||||
#define ST7735_RED ST77XX_RED
|
||||
#define ST7735_GREEN ST77XX_GREEN
|
||||
#define ST7735_BLUE ST77XX_BLUE
|
||||
#define ST7735_CYAN ST77XX_CYAN
|
||||
#define ST7735_MAGENTA ST77XX_MAGENTA
|
||||
#define ST7735_YELLOW ST77XX_YELLOW
|
||||
#define ST7735_ORANGE ST77XX_ORANGE
|
||||
|
||||
/// Subclass of ST77XX for ST7735B and ST7735R TFT Drivers:
|
||||
class Adafruit_ST7735 : public Adafruit_ST77xx {
|
||||
public:
|
||||
Adafruit_ST7735(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk, int8_t rst);
|
||||
Adafruit_ST7735(int8_t cs, int8_t dc, int8_t rst);
|
||||
#if !defined(ESP8266)
|
||||
Adafruit_ST7735(SPIClass *spiClass, int8_t cs, int8_t dc, int8_t rst);
|
||||
#endif // end !ESP8266
|
||||
|
||||
// Differences between displays (usu. identified by colored tab on
|
||||
// plastic overlay) are odd enough that we need to do this 'by hand':
|
||||
void initB(void); // for ST7735B displays
|
||||
void initR(uint8_t options = INITR_GREENTAB); // for ST7735R
|
||||
|
||||
void setRotation(uint8_t m);
|
||||
|
||||
private:
|
||||
uint8_t tabcolor;
|
||||
};
|
||||
|
||||
#endif // _ADAFRUIT_ST7735H_
|
||||
174
libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST7789.cpp
Normal file
174
libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST7789.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
#include "Adafruit_ST7789.h"
|
||||
#include "Adafruit_ST77xx.h"
|
||||
|
||||
// CONSTRUCTORS ************************************************************
|
||||
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST7789 driver with software SPI
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param mosi SPI MOSI pin #
|
||||
@param sclk SPI Clock pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
Adafruit_ST7789::Adafruit_ST7789(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk,
|
||||
int8_t rst)
|
||||
: Adafruit_ST77xx(240, 320, cs, dc, mosi, sclk, rst) {}
|
||||
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST7789 driver with hardware SPI
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
Adafruit_ST7789::Adafruit_ST7789(int8_t cs, int8_t dc, int8_t rst)
|
||||
: Adafruit_ST77xx(240, 320, cs, dc, rst) {}
|
||||
|
||||
#if !defined(ESP8266)
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST7789 driver with selectable hardware SPI
|
||||
@param spiClass Pointer to an SPI device to use (e.g. &SPI1)
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
Adafruit_ST7789::Adafruit_ST7789(SPIClass *spiClass, int8_t cs, int8_t dc,
|
||||
int8_t rst)
|
||||
: Adafruit_ST77xx(240, 320, spiClass, cs, dc, rst) {}
|
||||
#endif // end !ESP8266
|
||||
|
||||
// SCREEN INITIALIZATION ***************************************************
|
||||
|
||||
// Rather than a bazillion writecommand() and writedata() calls, screen
|
||||
// initialization commands and arguments are organized in these tables
|
||||
// stored in PROGMEM. The table may look bulky, but that's mostly the
|
||||
// formatting -- storage-wise this is hundreds of bytes more compact
|
||||
// than the equivalent code. Companion function follows.
|
||||
|
||||
// clang-format off
|
||||
|
||||
static const uint8_t PROGMEM
|
||||
generic_st7789[] = { // Init commands for 7789 screens
|
||||
9, // 9 commands in list:
|
||||
ST77XX_SWRESET, ST_CMD_DELAY, // 1: Software reset, no args, w/delay
|
||||
150, // ~150 ms delay
|
||||
ST77XX_SLPOUT , ST_CMD_DELAY, // 2: Out of sleep mode, no args, w/delay
|
||||
10, // 10 ms delay
|
||||
ST77XX_COLMOD , 1+ST_CMD_DELAY, // 3: Set color mode, 1 arg + delay:
|
||||
0x55, // 16-bit color
|
||||
10, // 10 ms delay
|
||||
ST77XX_MADCTL , 1, // 4: Mem access ctrl (directions), 1 arg:
|
||||
0x08, // Row/col addr, bottom-top refresh
|
||||
ST77XX_CASET , 4, // 5: Column addr set, 4 args, no delay:
|
||||
0x00,
|
||||
0, // XSTART = 0
|
||||
0,
|
||||
240, // XEND = 240
|
||||
ST77XX_RASET , 4, // 6: Row addr set, 4 args, no delay:
|
||||
0x00,
|
||||
0, // YSTART = 0
|
||||
320>>8,
|
||||
320&0xFF, // YEND = 320
|
||||
ST77XX_INVON , ST_CMD_DELAY, // 7: hack
|
||||
10,
|
||||
ST77XX_NORON , ST_CMD_DELAY, // 8: Normal display on, no args, w/delay
|
||||
10, // 10 ms delay
|
||||
ST77XX_DISPON , ST_CMD_DELAY, // 9: Main screen turn on, no args, delay
|
||||
10 }; // 10 ms delay
|
||||
|
||||
// clang-format on
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initialization code common to all ST7789 displays
|
||||
@param width Display width
|
||||
@param height Display height
|
||||
@param mode SPI data mode; one of SPI_MODE0, SPI_MODE1, SPI_MODE2
|
||||
or SPI_MODE3 (do NOT pass the numbers 0,1,2 or 3 -- use
|
||||
the defines only, the values are NOT the same!)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST7789::init(uint16_t width, uint16_t height, uint8_t mode) {
|
||||
// Save SPI data mode. commonInit() calls begin() (in Adafruit_ST77xx.cpp),
|
||||
// which in turn calls initSPI() (in Adafruit_SPITFT.cpp), passing it the
|
||||
// value of spiMode. It's done this way because begin() really should not
|
||||
// be modified at this point to accept an SPI mode -- it's a virtual
|
||||
// function required in every Adafruit_SPITFT subclass and would require
|
||||
// updating EVERY such library...whereas, at the moment, we know that
|
||||
// certain ST7789 displays are the only thing that may need a non-default
|
||||
// SPI mode, hence this roundabout approach...
|
||||
spiMode = mode;
|
||||
// (Might get added similarly to other display types as needed on a
|
||||
// case-by-case basis.)
|
||||
|
||||
commonInit(NULL);
|
||||
if (width == 240 && height == 240) {
|
||||
// 1.3", 1.54" displays (right justified)
|
||||
_rowstart = (320 - height);
|
||||
_rowstart2 = 0;
|
||||
_colstart = _colstart2 = (240 - width);
|
||||
} else if (width == 135 && height == 240) {
|
||||
// 1.14" display (centered, with odd size)
|
||||
_rowstart = _rowstart2 = (int)((320 - height) / 2);
|
||||
// This is the only device currently supported device that has different
|
||||
// values for _colstart & _colstart2. You must ensure that the extra
|
||||
// pixel lands in _colstart and not in _colstart2
|
||||
_colstart = (int)((240 - width + 1) / 2);
|
||||
_colstart2 = (int)((240 - width) / 2);
|
||||
} else {
|
||||
// 1.47", 1.69, 1.9", 2.0" displays (centered)
|
||||
_rowstart = _rowstart2 = (int)((320 - height) / 2);
|
||||
_colstart = _colstart2 = (int)((240 - width) / 2);
|
||||
}
|
||||
|
||||
windowWidth = width;
|
||||
windowHeight = height;
|
||||
|
||||
displayInit(generic_st7789);
|
||||
setRotation(0);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set origin of (0,0) and orientation of TFT display
|
||||
@param m The index for rotation, from 0-3 inclusive
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST7789::setRotation(uint8_t m) {
|
||||
uint8_t madctl = 0;
|
||||
|
||||
rotation = m & 3; // can't be higher than 3
|
||||
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB;
|
||||
_xstart = _colstart;
|
||||
_ystart = _rowstart;
|
||||
_width = windowWidth;
|
||||
_height = windowHeight;
|
||||
break;
|
||||
case 1:
|
||||
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB;
|
||||
_xstart = _rowstart;
|
||||
_ystart = _colstart2;
|
||||
_height = windowWidth;
|
||||
_width = windowHeight;
|
||||
break;
|
||||
case 2:
|
||||
madctl = ST77XX_MADCTL_RGB;
|
||||
_xstart = _colstart2;
|
||||
_ystart = _rowstart2;
|
||||
_width = windowWidth;
|
||||
_height = windowHeight;
|
||||
break;
|
||||
case 3:
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB;
|
||||
_xstart = _rowstart2;
|
||||
_ystart = _colstart;
|
||||
_height = windowWidth;
|
||||
_width = windowHeight;
|
||||
break;
|
||||
}
|
||||
|
||||
sendCommand(ST77XX_MADCTL, &madctl, 1);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef _ADAFRUIT_ST7789H_
|
||||
#define _ADAFRUIT_ST7789H_
|
||||
|
||||
#include "Adafruit_ST77xx.h"
|
||||
|
||||
/// Subclass of ST77XX type display for ST7789 TFT Driver
|
||||
class Adafruit_ST7789 : public Adafruit_ST77xx {
|
||||
public:
|
||||
Adafruit_ST7789(int8_t cs, int8_t dc, int8_t mosi, int8_t sclk,
|
||||
int8_t rst = -1);
|
||||
Adafruit_ST7789(int8_t cs, int8_t dc, int8_t rst);
|
||||
#if !defined(ESP8266)
|
||||
Adafruit_ST7789(SPIClass *spiClass, int8_t cs, int8_t dc, int8_t rst);
|
||||
#endif // end !ESP8266
|
||||
|
||||
void setRotation(uint8_t m);
|
||||
void init(uint16_t width, uint16_t height, uint8_t spiMode = SPI_MODE0);
|
||||
|
||||
protected:
|
||||
uint8_t _colstart2 = 0, ///< Offset from the right
|
||||
_rowstart2 = 0; ///< Offset from the bottom
|
||||
|
||||
private:
|
||||
uint16_t windowWidth;
|
||||
uint16_t windowHeight;
|
||||
};
|
||||
|
||||
#endif // _ADAFRUIT_ST7789H_
|
||||
361
libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST77xx.cpp
Normal file
361
libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST77xx.cpp
Normal file
@@ -0,0 +1,361 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the Adafruit 1.8" TFT Breakout w/SD card
|
||||
----> http://www.adafruit.com/products/358
|
||||
The 1.8" TFT shield
|
||||
----> https://www.adafruit.com/product/802
|
||||
The 1.44" TFT breakout
|
||||
----> https://www.adafruit.com/product/2088
|
||||
as well as Adafruit raw 1.8" TFT display
|
||||
----> http://www.adafruit.com/products/618
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional).
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#include "Adafruit_ST77xx.h"
|
||||
#include <limits.h>
|
||||
#if !defined(ARDUINO_STM32_FEATHER) && !defined(ARDUINO_UNOR4_WIFI)
|
||||
#if !defined(ARDUINO_UNOR4_MINIMA)
|
||||
#include "pins_arduino.h"
|
||||
#include "wiring_private.h"
|
||||
#endif
|
||||
#endif
|
||||
#include <SPI.h>
|
||||
|
||||
#define SPI_DEFAULT_FREQ 32000000 ///< Default SPI data clock frequency
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST77XX driver with software SPI
|
||||
@param w Display width in pixels at default rotation setting (0)
|
||||
@param h Display height in pixels at default rotation setting (0)
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param mosi SPI MOSI pin #
|
||||
@param sclk SPI Clock pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
@param miso SPI MISO pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Adafruit_ST77xx::Adafruit_ST77xx(uint16_t w, uint16_t h, int8_t cs, int8_t dc,
|
||||
int8_t mosi, int8_t sclk, int8_t rst,
|
||||
int8_t miso)
|
||||
: Adafruit_SPITFT(w, h, cs, dc, mosi, sclk, rst, miso) {}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST77XX driver with hardware SPI
|
||||
@param w Display width in pixels at default rotation setting (0)
|
||||
@param h Display height in pixels at default rotation setting (0)
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Adafruit_ST77xx::Adafruit_ST77xx(uint16_t w, uint16_t h, int8_t cs, int8_t dc,
|
||||
int8_t rst)
|
||||
: Adafruit_SPITFT(w, h, cs, dc, rst) {}
|
||||
|
||||
#if !defined(ESP8266)
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instantiate Adafruit ST77XX driver with selectable hardware SPI
|
||||
@param w Display width in pixels at default rotation setting (0)
|
||||
@param h Display height in pixels at default rotation setting (0)
|
||||
@param spiClass A pointer to an SPI device to use (e.g. &SPI1)
|
||||
@param cs Chip select pin #
|
||||
@param dc Data/Command pin #
|
||||
@param rst Reset pin # (optional, pass -1 if unused)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Adafruit_ST77xx::Adafruit_ST77xx(uint16_t w, uint16_t h, SPIClass *spiClass,
|
||||
int8_t cs, int8_t dc, int8_t rst)
|
||||
: Adafruit_SPITFT(w, h, spiClass, cs, dc, rst) {}
|
||||
#endif // end !ESP8266
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Companion code to the initiliazation tables. Reads and issues
|
||||
a series of LCD commands stored in PROGMEM byte array.
|
||||
@param addr Flash memory array with commands and data to send
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::displayInit(const uint8_t *addr) {
|
||||
|
||||
uint8_t numCommands, cmd, numArgs;
|
||||
uint16_t ms;
|
||||
|
||||
numCommands = pgm_read_byte(addr++); // Number of commands to follow
|
||||
while (numCommands--) { // For each command...
|
||||
cmd = pgm_read_byte(addr++); // Read command
|
||||
numArgs = pgm_read_byte(addr++); // Number of args to follow
|
||||
ms = numArgs & ST_CMD_DELAY; // If hibit set, delay follows args
|
||||
numArgs &= ~ST_CMD_DELAY; // Mask out delay bit
|
||||
sendCommand(cmd, addr, numArgs);
|
||||
addr += numArgs;
|
||||
|
||||
if (ms) {
|
||||
ms = pgm_read_byte(addr++); // Read post-command delay time (ms)
|
||||
if (ms == 255)
|
||||
ms = 500; // If 255, delay for 500 ms
|
||||
delay(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initialize ST77xx chip. Connects to the ST77XX over SPI and
|
||||
sends initialization procedure commands
|
||||
@param freq Desired SPI clock frequency
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::begin(uint32_t freq) {
|
||||
if (!freq) {
|
||||
freq = SPI_DEFAULT_FREQ;
|
||||
}
|
||||
_freq = freq;
|
||||
|
||||
invertOnCommand = ST77XX_INVON;
|
||||
invertOffCommand = ST77XX_INVOFF;
|
||||
|
||||
initSPI(freq, spiMode);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initialization code common to all ST77XX displays
|
||||
@param cmdList Flash memory array with commands and data to send
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::commonInit(const uint8_t *cmdList) {
|
||||
begin();
|
||||
|
||||
if (cmdList) {
|
||||
displayInit(cmdList);
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief SPI displays set an address window rectangle for blitting pixels
|
||||
@param x Top left corner x coordinate
|
||||
@param y Top left corner x coordinate
|
||||
@param w Width of window
|
||||
@param h Height of window
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::setAddrWindow(uint16_t x, uint16_t y, uint16_t w,
|
||||
uint16_t h) {
|
||||
x += _xstart;
|
||||
y += _ystart;
|
||||
uint32_t xa = ((uint32_t)x << 16) | (x + w - 1);
|
||||
uint32_t ya = ((uint32_t)y << 16) | (y + h - 1);
|
||||
|
||||
writeCommand(ST77XX_CASET); // Column addr set
|
||||
SPI_WRITE32(xa);
|
||||
|
||||
writeCommand(ST77XX_RASET); // Row addr set
|
||||
SPI_WRITE32(ya);
|
||||
|
||||
writeCommand(ST77XX_RAMWR); // write to RAM
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set origin of (0,0) and orientation of TFT display
|
||||
@param m The index for rotation, from 0-3 inclusive
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::setRotation(uint8_t m) {
|
||||
uint8_t madctl = 0;
|
||||
|
||||
rotation = m % 4; // can't be higher than 3
|
||||
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB;
|
||||
_xstart = _colstart;
|
||||
_ystart = _rowstart;
|
||||
break;
|
||||
case 1:
|
||||
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB;
|
||||
_ystart = _colstart;
|
||||
_xstart = _rowstart;
|
||||
break;
|
||||
case 2:
|
||||
madctl = ST77XX_MADCTL_RGB;
|
||||
_xstart = _colstart;
|
||||
_ystart = _rowstart;
|
||||
break;
|
||||
case 3:
|
||||
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB;
|
||||
_ystart = _colstart;
|
||||
_xstart = _rowstart;
|
||||
break;
|
||||
}
|
||||
|
||||
sendCommand(ST77XX_MADCTL, &madctl, 1);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Set origin of (0,0) of display with offsets
|
||||
@param col The offset from 0 for the column address
|
||||
@param row The offset from 0 for the row address
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::setColRowStart(int8_t col, int8_t row) {
|
||||
_colstart = col;
|
||||
_rowstart = row;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Change whether display is on or off
|
||||
@param enable True if you want the display ON, false OFF
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::enableDisplay(boolean enable) {
|
||||
sendCommand(enable ? ST77XX_DISPON : ST77XX_DISPOFF);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Change whether TE pin output is on or off
|
||||
@param enable True if you want the TE pin ON, false OFF
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::enableTearing(boolean enable) {
|
||||
sendCommand(enable ? ST77XX_TEON : ST77XX_TEOFF);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Change whether sleep mode is on or off
|
||||
@param enable True if you want sleep mode ON, false OFF
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_ST77xx::enableSleep(boolean enable) {
|
||||
sendCommand(enable ? ST77XX_SLPIN : ST77XX_SLPOUT);
|
||||
}
|
||||
|
||||
////////// stuff not actively being used, but kept for posterity
|
||||
/*
|
||||
|
||||
uint8_t Adafruit_ST77xx::spiread(void) {
|
||||
uint8_t r = 0;
|
||||
if (_sid > 0) {
|
||||
r = shiftIn(_sid, _sclk, MSBFIRST);
|
||||
} else {
|
||||
//SID_DDR &= ~_BV(SID);
|
||||
//int8_t i;
|
||||
//for (i=7; i>=0; i--) {
|
||||
// SCLK_PORT &= ~_BV(SCLK);
|
||||
// r <<= 1;
|
||||
// r |= (SID_PIN >> SID) & 0x1;
|
||||
// SCLK_PORT |= _BV(SCLK);
|
||||
//}
|
||||
//SID_DDR |= _BV(SID);
|
||||
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void Adafruit_ST77xx::dummyclock(void) {
|
||||
|
||||
if (_sid > 0) {
|
||||
digitalWrite(_sclk, LOW);
|
||||
digitalWrite(_sclk, HIGH);
|
||||
} else {
|
||||
// SCLK_PORT &= ~_BV(SCLK);
|
||||
//SCLK_PORT |= _BV(SCLK);
|
||||
}
|
||||
}
|
||||
uint8_t Adafruit_ST77xx::readdata(void) {
|
||||
*portOutputRegister(rsport) |= rspin;
|
||||
|
||||
*portOutputRegister(csport) &= ~ cspin;
|
||||
|
||||
uint8_t r = spiread();
|
||||
|
||||
*portOutputRegister(csport) |= cspin;
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
uint8_t Adafruit_ST77xx::readcommand8(uint8_t c) {
|
||||
digitalWrite(_rs, LOW);
|
||||
|
||||
*portOutputRegister(csport) &= ~ cspin;
|
||||
|
||||
spiwrite(c);
|
||||
|
||||
digitalWrite(_rs, HIGH);
|
||||
pinMode(_sid, INPUT); // input!
|
||||
digitalWrite(_sid, LOW); // low
|
||||
spiread();
|
||||
uint8_t r = spiread();
|
||||
|
||||
|
||||
*portOutputRegister(csport) |= cspin;
|
||||
|
||||
|
||||
pinMode(_sid, OUTPUT); // back to output
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
uint16_t Adafruit_ST77xx::readcommand16(uint8_t c) {
|
||||
digitalWrite(_rs, LOW);
|
||||
if (_cs)
|
||||
digitalWrite(_cs, LOW);
|
||||
|
||||
spiwrite(c);
|
||||
pinMode(_sid, INPUT); // input!
|
||||
uint16_t r = spiread();
|
||||
r <<= 8;
|
||||
r |= spiread();
|
||||
if (_cs)
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
pinMode(_sid, OUTPUT); // back to output
|
||||
return r;
|
||||
}
|
||||
|
||||
uint32_t Adafruit_ST77xx::readcommand32(uint8_t c) {
|
||||
digitalWrite(_rs, LOW);
|
||||
if (_cs)
|
||||
digitalWrite(_cs, LOW);
|
||||
spiwrite(c);
|
||||
pinMode(_sid, INPUT); // input!
|
||||
|
||||
dummyclock();
|
||||
dummyclock();
|
||||
|
||||
uint32_t r = spiread();
|
||||
r <<= 8;
|
||||
r |= spiread();
|
||||
r <<= 8;
|
||||
r |= spiread();
|
||||
r <<= 8;
|
||||
r |= spiread();
|
||||
if (_cs)
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
pinMode(_sid, OUTPUT); // back to output
|
||||
return r;
|
||||
}
|
||||
|
||||
*/
|
||||
117
libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST77xx.h
Normal file
117
libraries/Adafruit_ST7735_and_ST7789_Library/Adafruit_ST77xx.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the Adafruit 1.8" TFT Breakout w/SD card
|
||||
----> http://www.adafruit.com/products/358
|
||||
The 1.8" TFT shield
|
||||
----> https://www.adafruit.com/product/802
|
||||
The 1.44" TFT breakout
|
||||
----> https://www.adafruit.com/product/2088
|
||||
as well as Adafruit raw 1.8" TFT display
|
||||
----> http://www.adafruit.com/products/618
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional).
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef _ADAFRUIT_ST77XXH_
|
||||
#define _ADAFRUIT_ST77XXH_
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SPITFT.h>
|
||||
#include <Adafruit_SPITFT_Macros.h>
|
||||
|
||||
#define ST7735_TFTWIDTH_128 128 // for 1.44 and mini
|
||||
#define ST7735_TFTWIDTH_80 80 // for mini
|
||||
#define ST7735_TFTHEIGHT_128 128 // for 1.44" display
|
||||
#define ST7735_TFTHEIGHT_160 160 // for 1.8" and mini display
|
||||
|
||||
#define ST_CMD_DELAY 0x80 // special signifier for command lists
|
||||
|
||||
#define ST77XX_NOP 0x00
|
||||
#define ST77XX_SWRESET 0x01
|
||||
#define ST77XX_RDDID 0x04
|
||||
#define ST77XX_RDDST 0x09
|
||||
|
||||
#define ST77XX_SLPIN 0x10
|
||||
#define ST77XX_SLPOUT 0x11
|
||||
#define ST77XX_PTLON 0x12
|
||||
#define ST77XX_NORON 0x13
|
||||
|
||||
#define ST77XX_INVOFF 0x20
|
||||
#define ST77XX_INVON 0x21
|
||||
#define ST77XX_DISPOFF 0x28
|
||||
#define ST77XX_DISPON 0x29
|
||||
#define ST77XX_CASET 0x2A
|
||||
#define ST77XX_RASET 0x2B
|
||||
#define ST77XX_RAMWR 0x2C
|
||||
#define ST77XX_RAMRD 0x2E
|
||||
|
||||
#define ST77XX_PTLAR 0x30
|
||||
#define ST77XX_TEOFF 0x34
|
||||
#define ST77XX_TEON 0x35
|
||||
#define ST77XX_MADCTL 0x36
|
||||
#define ST77XX_COLMOD 0x3A
|
||||
|
||||
#define ST77XX_MADCTL_MY 0x80
|
||||
#define ST77XX_MADCTL_MX 0x40
|
||||
#define ST77XX_MADCTL_MV 0x20
|
||||
#define ST77XX_MADCTL_ML 0x10
|
||||
#define ST77XX_MADCTL_RGB 0x00
|
||||
|
||||
#define ST77XX_RDID1 0xDA
|
||||
#define ST77XX_RDID2 0xDB
|
||||
#define ST77XX_RDID3 0xDC
|
||||
#define ST77XX_RDID4 0xDD
|
||||
|
||||
// Some ready-made 16-bit ('565') color settings:
|
||||
#define ST77XX_BLACK 0x0000
|
||||
#define ST77XX_WHITE 0xFFFF
|
||||
#define ST77XX_RED 0xF800
|
||||
#define ST77XX_GREEN 0x07E0
|
||||
#define ST77XX_BLUE 0x001F
|
||||
#define ST77XX_CYAN 0x07FF
|
||||
#define ST77XX_MAGENTA 0xF81F
|
||||
#define ST77XX_YELLOW 0xFFE0
|
||||
#define ST77XX_ORANGE 0xFC00
|
||||
|
||||
/// Subclass of SPITFT for ST77xx displays (lots in common!)
|
||||
class Adafruit_ST77xx : public Adafruit_SPITFT {
|
||||
public:
|
||||
Adafruit_ST77xx(uint16_t w, uint16_t h, int8_t _CS, int8_t _DC, int8_t _MOSI,
|
||||
int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
|
||||
Adafruit_ST77xx(uint16_t w, uint16_t h, int8_t CS, int8_t RS,
|
||||
int8_t RST = -1);
|
||||
#if !defined(ESP8266)
|
||||
Adafruit_ST77xx(uint16_t w, uint16_t h, SPIClass *spiClass, int8_t CS,
|
||||
int8_t RS, int8_t RST = -1);
|
||||
#endif // end !ESP8266
|
||||
|
||||
void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
void setRotation(uint8_t r);
|
||||
void enableDisplay(boolean enable);
|
||||
void enableTearing(boolean enable);
|
||||
void enableSleep(boolean enable);
|
||||
|
||||
protected:
|
||||
uint8_t _colstart = 0, ///< Some displays need this changed to offset
|
||||
_rowstart = 0, ///< Some displays need this changed to offset
|
||||
spiMode = SPI_MODE0; ///< Certain display needs MODE3 instead
|
||||
|
||||
void begin(uint32_t freq = 0);
|
||||
void commonInit(const uint8_t *cmdList);
|
||||
void displayInit(const uint8_t *addr);
|
||||
void setColRowStart(int8_t col, int8_t row);
|
||||
};
|
||||
|
||||
#endif // _ADAFRUIT_ST77XXH_
|
||||
25
libraries/Adafruit_ST7735_and_ST7789_Library/README.txt
Normal file
25
libraries/Adafruit_ST7735_and_ST7789_Library/README.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the Adafruit 1.8" TFT Breakout w/SD card
|
||||
----> http://www.adafruit.com/products/358
|
||||
The 1.8" TFT shield
|
||||
----> https://www.adafruit.com/product/802
|
||||
The 1.44" TFT breakout
|
||||
----> https://www.adafruit.com/product/2088
|
||||
as well as Adafruit raw 1.8" TFT display
|
||||
----> http://www.adafruit.com/products/618
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional).
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution.
|
||||
|
||||
Recent Arduino IDE releases include the Library Manager for easy installation. Otherwise, to download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_ST7735. Confirm that the Adafruit_ST7735 folder contains Adafruit_ST7735.cpp, Adafruit_ST7735.h and related source files. Place the Adafruit_ST7735 library folder your ArduinoSketchFolder/Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE.
|
||||
|
||||
Also requires the Adafruit_GFX library for Arduino.
|
||||
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* This is an example sketch that shows how to toggle the display
|
||||
* on and off at runtime to avoid screen burn-in.
|
||||
*
|
||||
* The sketch also demonstrates how to erase a previous value by re-drawing the
|
||||
* older value in the screen background color prior to writing a new value in
|
||||
* the same location. This avoids the need to call fillScreen() to erase the
|
||||
* entire screen followed by a complete redraw of screen contents.
|
||||
*
|
||||
* Originally written by Phill Kelley. BSD license.
|
||||
* Adapted for ST77xx by Melissa LeBlanc-Williams
|
||||
*/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
|
||||
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
|
||||
#include <SPI.h>
|
||||
|
||||
#ifdef ADAFRUIT_HALLOWING
|
||||
#define TFT_CS 39 // Hallowing display control pins: chip select
|
||||
#define TFT_RST 37 // Display reset
|
||||
#define TFT_DC 38 // Display data/command select
|
||||
#define TFT_BACKLIGHT 7 // Display backlight pin
|
||||
|
||||
#elif defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
|
||||
#define TFT_CS 14
|
||||
#define TFT_RST 15
|
||||
#define TFT_DC 32
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define TFT_CS 4
|
||||
#define TFT_RST 16
|
||||
#define TFT_DC 5
|
||||
|
||||
#else
|
||||
// For the breakout board, you can use any 2 or 3 pins.
|
||||
// These pins will also work for the 1.8" TFT shield.
|
||||
#define TFT_CS 10
|
||||
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
|
||||
#define TFT_DC 8
|
||||
#endif
|
||||
|
||||
#define SerialDebugging true
|
||||
|
||||
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
|
||||
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
|
||||
// SCLK = pin 13. This is the fastest mode of operation and is required if
|
||||
// using the breakout board's microSD card.
|
||||
|
||||
// For 1.44" and 1.8" TFT with ST7735 (including HalloWing) use:
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// For 1.3", 1.54", and 2.0" TFT with ST7789:
|
||||
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
|
||||
// tradeoff being that performance is not as fast as hardware SPI above.
|
||||
//#define TFT_MOSI 11 // Data out
|
||||
//#define TFT_SCLK 13 // Clock out
|
||||
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
// connect a push button between ground and...
|
||||
const uint8_t Button_pin = 2;
|
||||
|
||||
// color definitions
|
||||
const uint16_t Display_Color_Black = 0x0000;
|
||||
const uint16_t Display_Color_Blue = 0x001F;
|
||||
const uint16_t Display_Color_Red = 0xF800;
|
||||
const uint16_t Display_Color_Green = 0x07E0;
|
||||
const uint16_t Display_Color_Cyan = 0x07FF;
|
||||
const uint16_t Display_Color_Magenta = 0xF81F;
|
||||
const uint16_t Display_Color_Yellow = 0xFFE0;
|
||||
const uint16_t Display_Color_White = 0xFFFF;
|
||||
|
||||
// The colors we actually want to use
|
||||
uint16_t Display_Text_Color = Display_Color_Black;
|
||||
uint16_t Display_Backround_Color = Display_Color_Blue;
|
||||
|
||||
// assume the display is off until configured in setup()
|
||||
bool isDisplayVisible = false;
|
||||
|
||||
// declare size of working string buffers. Basic strlen("d hh:mm:ss") = 10
|
||||
const size_t MaxString = 16;
|
||||
|
||||
// the string being displayed on the SSD1331 (initially empty)
|
||||
char oldTimeString[MaxString] = { 0 };
|
||||
|
||||
// the interrupt service routine affects this
|
||||
volatile bool isButtonPressed = false;
|
||||
|
||||
|
||||
// interrupt service routine
|
||||
void senseButtonPressed() {
|
||||
if (!isButtonPressed) {
|
||||
isButtonPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void displayUpTime() {
|
||||
|
||||
// calculate seconds, truncated to the nearest whole second
|
||||
unsigned long upSeconds = millis() / 1000;
|
||||
|
||||
// calculate days, truncated to nearest whole day
|
||||
unsigned long days = upSeconds / 86400;
|
||||
|
||||
// the remaining hhmmss are
|
||||
upSeconds = upSeconds % 86400;
|
||||
|
||||
// calculate hours, truncated to the nearest whole hour
|
||||
unsigned long hours = upSeconds / 3600;
|
||||
|
||||
// the remaining mmss are
|
||||
upSeconds = upSeconds % 3600;
|
||||
|
||||
// calculate minutes, truncated to the nearest whole minute
|
||||
unsigned long minutes = upSeconds / 60;
|
||||
|
||||
// the remaining ss are
|
||||
upSeconds = upSeconds % 60;
|
||||
|
||||
// allocate a buffer
|
||||
char newTimeString[MaxString] = { 0 };
|
||||
|
||||
// construct the string representation
|
||||
sprintf(
|
||||
newTimeString,
|
||||
"%lu %02lu:%02lu:%02lu",
|
||||
days, hours, minutes, upSeconds
|
||||
);
|
||||
|
||||
// has the time string changed since the last tft update?
|
||||
if (strcmp(newTimeString,oldTimeString) != 0) {
|
||||
|
||||
// yes! home the cursor
|
||||
tft.setCursor(0,0);
|
||||
|
||||
// change the text color to the background color
|
||||
tft.setTextColor(Display_Backround_Color);
|
||||
|
||||
// redraw the old value to erase
|
||||
tft.print(oldTimeString);
|
||||
|
||||
// home the cursor
|
||||
tft.setCursor(0,0);
|
||||
|
||||
// change the text color to foreground color
|
||||
tft.setTextColor(Display_Text_Color);
|
||||
|
||||
// draw the new time value
|
||||
tft.print(newTimeString);
|
||||
|
||||
// and remember the new value
|
||||
strcpy(oldTimeString,newTimeString);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
// button press pulls pin LOW so configure HIGH
|
||||
pinMode(Button_pin,INPUT_PULLUP);
|
||||
|
||||
// use an interrupt to sense when the button is pressed
|
||||
attachInterrupt(digitalPinToInterrupt(Button_pin), senseButtonPressed, FALLING);
|
||||
|
||||
#if (SerialDebugging)
|
||||
Serial.begin(115200); while (!Serial); Serial.println();
|
||||
#endif
|
||||
|
||||
// settling time
|
||||
delay(250);
|
||||
|
||||
// ignore any power-on-reboot garbage
|
||||
isButtonPressed = false;
|
||||
|
||||
#ifdef ADAFRUIT_HALLOWING
|
||||
// HalloWing is a special case. It uses a ST7735R display just like the
|
||||
// breakout board, but the orientation and backlight control are different.
|
||||
tft.initR(INITR_HALLOWING); // Initialize HalloWing-oriented screen
|
||||
pinMode(TFT_BACKLIGHT, OUTPUT);
|
||||
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
|
||||
#else
|
||||
// Use this initializer if using a 1.8" TFT screen:
|
||||
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.44" TFT:
|
||||
//tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab
|
||||
|
||||
// OR use this initializer (uncomment) if using a 0.96" 180x60 TFT:
|
||||
//tft.initR(INITR_MINI160x80); // Init ST7735S mini display
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.54" 240x240 TFT:
|
||||
//tft.init(240, 240); // Init ST7789 240x240
|
||||
|
||||
// OR use this initializer (uncomment) if using a 2.0" 320x240 TFT:
|
||||
//tft.init(240, 320); // Init ST7789 320x240
|
||||
|
||||
// SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
|
||||
// Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
|
||||
// may end up with a black screen some times, or all the time.
|
||||
//tft.setSPISpeed(40000000);
|
||||
#endif
|
||||
|
||||
// initialise the display
|
||||
tft.setFont();
|
||||
tft.fillScreen(Display_Backround_Color);
|
||||
tft.setTextColor(Display_Text_Color);
|
||||
tft.setTextSize(1);
|
||||
|
||||
// the display is now on
|
||||
isDisplayVisible = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
// unconditional display, regardless of whether display is visible
|
||||
displayUpTime();
|
||||
|
||||
// has the button been pressed?
|
||||
if (isButtonPressed) {
|
||||
|
||||
// yes! toggle display visibility
|
||||
isDisplayVisible = !isDisplayVisible;
|
||||
|
||||
// apply
|
||||
tft.enableDisplay(isDisplayVisible);
|
||||
|
||||
#if (SerialDebugging)
|
||||
Serial.print("button pressed @ ");
|
||||
Serial.print(millis());
|
||||
Serial.print(", display is now ");
|
||||
Serial.println((isDisplayVisible ? "ON" : "OFF"));
|
||||
#endif
|
||||
|
||||
// confirm button handled
|
||||
isButtonPressed = false;
|
||||
|
||||
}
|
||||
|
||||
// no need to be in too much of a hurry
|
||||
delay(100);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the Adafruit 1.8" TFT Breakout w/SD card
|
||||
----> http://www.adafruit.com/products/358
|
||||
The 1.8" TFT shield
|
||||
----> https://www.adafruit.com/product/802
|
||||
The 1.44" TFT breakout
|
||||
----> https://www.adafruit.com/product/2088
|
||||
The 1.14" TFT breakout
|
||||
----> https://www.adafruit.com/product/4383
|
||||
The 1.3" TFT breakout
|
||||
----> https://www.adafruit.com/product/4313
|
||||
The 1.54" TFT breakout
|
||||
----> https://www.adafruit.com/product/3787
|
||||
The 1.69" TFT breakout
|
||||
----> https://www.adafruit.com/product/5206
|
||||
The 2.0" TFT breakout
|
||||
----> https://www.adafruit.com/product/4311
|
||||
as well as Adafruit raw 1.8" TFT display
|
||||
----> http://www.adafruit.com/products/618
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional).
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
|
||||
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
|
||||
#include <SPI.h>
|
||||
|
||||
#if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
|
||||
#define TFT_CS 14
|
||||
#define TFT_RST 15
|
||||
#define TFT_DC 32
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define TFT_CS 4
|
||||
#define TFT_RST 16
|
||||
#define TFT_DC 5
|
||||
|
||||
#else
|
||||
// For the breakout board, you can use any 2 or 3 pins.
|
||||
// These pins will also work for the 1.8" TFT shield.
|
||||
#define TFT_CS 10
|
||||
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
|
||||
#define TFT_DC 8
|
||||
#endif
|
||||
|
||||
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
|
||||
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
|
||||
// SCLK = pin 13. This is the fastest mode of operation and is required if
|
||||
// using the breakout board's microSD card.
|
||||
|
||||
// For 1.44" and 1.8" TFT with ST7735 use:
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// For 1.14", 1.3", 1.54", 1.69", and 2.0" TFT with ST7789:
|
||||
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
|
||||
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
|
||||
// tradeoff being that performance is not as fast as hardware SPI above.
|
||||
//#define TFT_MOSI 11 // Data out
|
||||
//#define TFT_SCLK 13 // Clock out
|
||||
|
||||
// For ST7735-based displays, we will use this call
|
||||
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
// OR for the ST7789-based displays, we will use this call
|
||||
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print(F("Hello! ST77xx TFT Test"));
|
||||
|
||||
// Use this initializer if using a 1.8" TFT screen:
|
||||
tft.initR(INITR_BLACKTAB); // Init ST7735S chip, black tab
|
||||
|
||||
// OR use this initializer if using a 1.8" TFT screen with offset such as WaveShare:
|
||||
// tft.initR(INITR_GREENTAB); // Init ST7735S chip, green tab
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.44" TFT:
|
||||
//tft.initR(INITR_144GREENTAB); // Init ST7735R chip, green tab
|
||||
|
||||
// OR use this initializer (uncomment) if using a 0.96" 160x80 TFT:
|
||||
//tft.initR(INITR_MINI160x80); // Init ST7735S mini display
|
||||
// OR use this initializer (uncomment) if using a 0.96" 160x80 TFT with
|
||||
// plug-in FPC (if you see the display is inverted!)
|
||||
//tft.initR(INITR_MINI160x80_PLUGIN); // Init ST7735S mini display
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT:
|
||||
//tft.init(240, 240); // Init ST7789 240x240
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.69" 280x240 TFT:
|
||||
//tft.init(240, 280); // Init ST7789 280x240
|
||||
|
||||
// OR use this initializer (uncomment) if using a 2.0" 320x240 TFT:
|
||||
//tft.init(240, 320); // Init ST7789 320x240
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.14" 240x135 TFT:
|
||||
//tft.init(135, 240); // Init ST7789 240x135
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.47" 172x320 TFT:
|
||||
//tft.init(172, 320); // Init ST7789 172x320
|
||||
|
||||
// SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
|
||||
// Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
|
||||
// may end up with a black screen some times, or all the time.
|
||||
//tft.setSPISpeed(40000000);
|
||||
|
||||
Serial.println(F("Initialized"));
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
// large block of text
|
||||
tft.fillScreen(ST77XX_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. ", ST77XX_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(4000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST77XX_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST77XX_RED, ST77XX_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
testfillcircles(10, ST77XX_BLUE);
|
||||
testdrawcircles(10, ST77XX_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(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, 0, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_BLACK);
|
||||
uint16_t 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++) {
|
||||
tft.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
uint16_t 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(ST77XX_BLACK);
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_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(ST77XX_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
|
||||
delay(500);
|
||||
// pause
|
||||
tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the Adafruit ESP32-S2 TFT Feather
|
||||
----> http://www.adafruit.com/products/5300
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
|
||||
#include <SPI.h>
|
||||
|
||||
// Use dedicated hardware SPI pins
|
||||
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print(F("Hello! Feather TFT Test"));
|
||||
|
||||
// turn on backlite
|
||||
pinMode(TFT_BACKLITE, OUTPUT);
|
||||
digitalWrite(TFT_BACKLITE, HIGH);
|
||||
|
||||
// turn on the TFT / I2C power supply
|
||||
pinMode(TFT_I2C_POWER, OUTPUT);
|
||||
digitalWrite(TFT_I2C_POWER, HIGH);
|
||||
delay(10);
|
||||
|
||||
// initialize TFT
|
||||
tft.init(135, 240); // Init ST7789 240x135
|
||||
tft.setRotation(3);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
|
||||
Serial.println(F("Initialized"));
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
// large block of text
|
||||
tft.fillScreen(ST77XX_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. ",
|
||||
ST77XX_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(4000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width() / 2, tft.height() / 2, ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST77XX_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST77XX_RED, ST77XX_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
testfillcircles(10, ST77XX_BLUE);
|
||||
testdrawcircles(10, ST77XX_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(ST77XX_BLACK);
|
||||
for (int16_t x = 0; x < tft.width(); x += 6) {
|
||||
tft.drawLine(0, 0, x, tft.height() - 1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y = 0; y < tft.height(); y += 6) {
|
||||
tft.drawLine(0, 0, tft.width() - 1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x = 0; x < tft.width(); x += 6) {
|
||||
tft.drawLine(tft.width() - 1, 0, x, tft.height() - 1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y = 0; y < tft.height(); y += 6) {
|
||||
tft.drawLine(tft.width() - 1, 0, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x = 0; x < tft.width(); x += 6) {
|
||||
tft.drawLine(0, tft.height() - 1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y = 0; y < tft.height(); y += 6) {
|
||||
tft.drawLine(0, tft.height() - 1, tft.width() - 1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x = 0; x < tft.width(); x += 6) {
|
||||
tft.drawLine(tft.width() - 1, tft.height() - 1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y = 0; y < tft.height(); y += 6) {
|
||||
tft.drawLine(tft.width() - 1, tft.height() - 1, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_BLACK);
|
||||
uint16_t 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++) {
|
||||
tft.drawTriangle(w, y, y, x, z, x, color);
|
||||
x -= 4;
|
||||
y += 4;
|
||||
z -= 4;
|
||||
color += 100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
uint16_t 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(ST77XX_BLACK);
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_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(ST77XX_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.fillRoundRect(25, 5, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillTriangle(42, 12, 42, 60, 90, 40, ST77XX_RED);
|
||||
delay(500);
|
||||
// pause
|
||||
tft.fillRoundRect(25, 70, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillRoundRect(39, 78, 20, 45, 5, ST77XX_GREEN);
|
||||
tft.fillRoundRect(69, 78, 20, 45, 5, ST77XX_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(42, 12, 42, 60, 90, 40, ST77XX_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 78, 20, 45, 5, ST77XX_RED);
|
||||
tft.fillRoundRect(69, 78, 20, 45, 5, ST77XX_RED);
|
||||
// play color
|
||||
tft.fillTriangle(42, 12, 42, 60, 90, 40, ST77XX_GREEN);
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the HalloWing M0 Express
|
||||
----> http://www.adafruit.com/products/3900
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
|
||||
#include <SPI.h>
|
||||
|
||||
#define TFT_CS 39 // Hallowing display control pins: chip select
|
||||
#define TFT_RST 37 // Display reset
|
||||
#define TFT_DC 38 // Display data/command select
|
||||
#define TFT_BACKLIGHT 7 // Display backlight pin
|
||||
|
||||
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
|
||||
// to each board and not reassignable.
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
|
||||
// tradeoff being that performance is not as fast as hardware SPI above.
|
||||
//#define TFT_MOSI 29 // Data out
|
||||
//#define TFT_SCLK 30 // Clock out
|
||||
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print(F("Hello! HalloWing TFT Test"));
|
||||
|
||||
pinMode(TFT_BACKLIGHT, OUTPUT);
|
||||
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
|
||||
|
||||
tft.initR(INITR_HALLOWING); // Initialize HalloWing-oriented screen
|
||||
|
||||
Serial.println(F("Initialized"));
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
// large block of text
|
||||
tft.fillScreen(ST77XX_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. ", ST77XX_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(4000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST77XX_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST77XX_RED, ST77XX_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
testfillcircles(10, ST77XX_BLUE);
|
||||
testdrawcircles(10, ST77XX_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(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, 0, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_BLACK);
|
||||
uint16_t 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++) {
|
||||
tft.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
uint16_t 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(ST77XX_BLACK);
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_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(ST77XX_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
|
||||
delay(500);
|
||||
// pause
|
||||
tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the HalloWing M4 Express
|
||||
----> http://www.adafruit.com/products/4300
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
|
||||
#include <SPI.h>
|
||||
|
||||
#define TFT_CS 44 // HalloWing M4 display control pins: chip select
|
||||
#define TFT_RST 46 // Display reset
|
||||
#define TFT_DC 45 // Display data/command select
|
||||
#define TFT_BACKLIGHT 47 // Display backlight pin
|
||||
|
||||
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
|
||||
// to each board and not reassignable.
|
||||
Adafruit_ST7789 tft = Adafruit_ST7789(&SPI1, TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
|
||||
// tradeoff being that performance is not as fast as hardware SPI above.
|
||||
//#define TFT_MOSI 41 // Data out
|
||||
//#define TFT_SCLK 42 // Clock out
|
||||
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print(F("Hello! HalloWing TFT Test"));
|
||||
|
||||
pinMode(TFT_BACKLIGHT, OUTPUT);
|
||||
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
|
||||
|
||||
tft.init(240, 240); // Initialize ST7789 screen
|
||||
|
||||
Serial.println(F("Initialized"));
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
// large block of text
|
||||
tft.fillScreen(ST77XX_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. ", ST77XX_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(4000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST77XX_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST77XX_RED, ST77XX_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
testfillcircles(10, ST77XX_BLUE);
|
||||
testdrawcircles(10, ST77XX_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(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, 0, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_BLACK);
|
||||
uint16_t 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++) {
|
||||
tft.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
uint16_t 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(ST77XX_BLACK);
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_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(ST77XX_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
|
||||
delay(500);
|
||||
// pause
|
||||
tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the following products with integrated displays
|
||||
The PyBadge
|
||||
----> http://www.adafruit.com/products/4200
|
||||
The PyGamer
|
||||
----> http://www.adafruit.com/products/4242
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
|
||||
#include <SPI.h>
|
||||
|
||||
#define TFT_CS 44 // PyBadge/PyGamer display control pins: chip select
|
||||
#define TFT_RST 46 // Display reset
|
||||
#define TFT_DC 45 // Display data/command select
|
||||
#define TFT_BACKLIGHT 47 // Display backlight pin
|
||||
|
||||
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
|
||||
// to each board and not reassignable.
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(&SPI1, TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
|
||||
// tradeoff being that performance is not as fast as hardware SPI above.
|
||||
//#define TFT_MOSI 41 // Data out
|
||||
//#define TFT_SCLK 42 // Clock out
|
||||
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print(F("Hello! PyBadge/PyGamer TFT Test"));
|
||||
|
||||
pinMode(TFT_BACKLIGHT, OUTPUT);
|
||||
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
|
||||
|
||||
tft.initR(INITR_BLACKTAB); // Initialize ST7735R screen
|
||||
tft.setRotation(1);
|
||||
|
||||
Serial.println(F("Initialized"));
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
// large block of text
|
||||
tft.fillScreen(ST77XX_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. ", ST77XX_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(4000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST77XX_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST77XX_RED, ST77XX_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
testfillcircles(10, ST77XX_BLUE);
|
||||
testdrawcircles(10, ST77XX_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(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, 0, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_BLACK);
|
||||
uint16_t 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++) {
|
||||
tft.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
uint16_t 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(ST77XX_BLACK);
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_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(ST77XX_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
|
||||
delay(500);
|
||||
// pause
|
||||
tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
This example works with the 1.14" TFT breakout
|
||||
----> https://www.adafruit.com/product/4383
|
||||
The 1.3" TFT breakout
|
||||
----> https://www.adafruit.com/product/4313
|
||||
The 1.47" TFT breakout
|
||||
----> https://www.adafruit.com/product/5393
|
||||
The 1.54" TFT breakout
|
||||
----> https://www.adafruit.com/product/3787
|
||||
The 1.69" TFT breakout
|
||||
----> https://www.adafruit.com/product/5206
|
||||
The 1.9" TFT breakout
|
||||
----> https://www.adafruit.com/product/5394
|
||||
The 2.0" TFT breakout
|
||||
----> https://www.adafruit.com/product/4311
|
||||
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional).
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
|
||||
#include <SPI.h>
|
||||
|
||||
#if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
|
||||
#define TFT_CS 14
|
||||
#define TFT_RST 15
|
||||
#define TFT_DC 32
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define TFT_CS 4
|
||||
#define TFT_RST 16
|
||||
#define TFT_DC 5
|
||||
|
||||
#else
|
||||
// For the breakout board, you can use any 2 or 3 pins.
|
||||
// These pins will also work for the 1.8" TFT shield.
|
||||
#define TFT_CS 10
|
||||
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
|
||||
#define TFT_DC 8
|
||||
#endif
|
||||
|
||||
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
|
||||
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
|
||||
// SCLK = pin 13. This is the fastest mode of operation and is required if
|
||||
// using the breakout board's microSD card.
|
||||
|
||||
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
|
||||
// tradeoff being that performance is not as fast as hardware SPI above.
|
||||
//#define TFT_MOSI 11 // Data out
|
||||
//#define TFT_SCLK 13 // Clock out
|
||||
|
||||
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print(F("Hello! ST77xx TFT Test"));
|
||||
|
||||
// Use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT:
|
||||
tft.init(240, 240); // Init ST7789 240x240
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.69" 280x240 TFT:
|
||||
//tft.init(240, 280); // Init ST7789 280x240
|
||||
|
||||
// OR use this initializer (uncomment) if using a 2.0" 320x240 TFT:
|
||||
//tft.init(240, 320); // Init ST7789 320x240
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.14" 240x135 TFT:
|
||||
//tft.init(135, 240); // Init ST7789 240x135
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.47" 172x320 TFT:
|
||||
//tft.init(172, 320); // Init ST7789 172x320
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.9" 170x320 TFT:
|
||||
//tft.init(170, 320); // Init ST7789 170x320
|
||||
|
||||
// SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
|
||||
// Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
|
||||
// may end up with a black screen some times, or all the time.
|
||||
//tft.setSPISpeed(40000000);
|
||||
Serial.println(F("Initialized"));
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
// large block of text
|
||||
tft.fillScreen(ST77XX_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. ", ST77XX_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(4000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST77XX_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST77XX_RED, ST77XX_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
testfillcircles(10, ST77XX_BLUE);
|
||||
testdrawcircles(10, ST77XX_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(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, 0, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_BLACK);
|
||||
uint16_t 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++) {
|
||||
tft.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
uint16_t 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(ST77XX_BLACK);
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_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(ST77XX_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
|
||||
delay(500);
|
||||
// pause
|
||||
tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
/**************************************************************************
|
||||
This is a library for several Adafruit displays based on ST77* drivers.
|
||||
|
||||
Works with the Adafruit TFT Gizmo
|
||||
----> http://www.adafruit.com/products/4367
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams.
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
**************************************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
|
||||
#include <SPI.h>
|
||||
|
||||
// Because of the limited number of pins available on the Circuit Playground Boards
|
||||
// Software SPI is used
|
||||
#define TFT_CS 0
|
||||
#define TFT_RST -1 // Or set to -1 and connect to Arduino RESET pin
|
||||
#define TFT_DC 1
|
||||
#define TFT_BACKLIGHT PIN_A3 // Display backlight pin
|
||||
|
||||
// You will need to use Adafruit's CircuitPlayground Express Board Definition
|
||||
// for Gizmos rather than the Arduino version since there are additional SPI
|
||||
// ports exposed.
|
||||
#if (SPI_INTERFACES_COUNT == 1)
|
||||
SPIClass* spi = &SPI;
|
||||
#else
|
||||
SPIClass* spi = &SPI1;
|
||||
#endif
|
||||
|
||||
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
|
||||
// to each board and not reassignable.
|
||||
Adafruit_ST7789 tft = Adafruit_ST7789(spi, TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// OPTION 2 lets you interface the display using ANY TWO or THREE PINS,
|
||||
// tradeoff being that performance is not as fast as hardware SPI above.
|
||||
//#define TFT_MOSI PIN_WIRE_SDA // Data out
|
||||
//#define TFT_SCLK PIN_WIRE_SCL // Clock out
|
||||
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print(F("Hello! Gizmo TFT Test"));
|
||||
|
||||
tft.init(240, 240); // Init ST7789 240x240
|
||||
tft.setRotation(2);
|
||||
|
||||
Serial.println(F("Initialized"));
|
||||
|
||||
pinMode(TFT_BACKLIGHT, OUTPUT);
|
||||
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
// large block of text
|
||||
tft.fillScreen(ST77XX_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. ", ST77XX_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(4000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST77XX_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST77XX_RED, ST77XX_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
testfillcircles(10, ST77XX_BLUE);
|
||||
testdrawcircles(10, ST77XX_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(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, 0, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, 0, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(0, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
|
||||
delay(0);
|
||||
}
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.width(); x+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
|
||||
delay(0);
|
||||
}
|
||||
for (int16_t y=0; y < tft.height(); y+=6) {
|
||||
tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
|
||||
delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_BLACK);
|
||||
uint16_t 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++) {
|
||||
tft.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
uint16_t 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(ST77XX_BLACK);
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_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(ST77XX_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED);
|
||||
delay(500);
|
||||
// pause
|
||||
tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
|
||||
// play color
|
||||
tft.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN);
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_ST7735.h>
|
||||
#include <Adafruit_ST7789.h>
|
||||
#include "Adafruit_miniTFTWing.h"
|
||||
|
||||
Adafruit_miniTFTWing ss;
|
||||
#define TFT_RST -1 // we use the seesaw for resetting to save a pin
|
||||
|
||||
#ifdef ESP8266
|
||||
#define TFT_CS 0
|
||||
#define TFT_DC 15
|
||||
#elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
|
||||
#define TFT_CS 15
|
||||
#define TFT_DC 33
|
||||
#elif defined(TEENSYDUINO)
|
||||
#define TFT_DC 10
|
||||
#define TFT_CS 4
|
||||
#elif defined(ARDUINO_STM32_FEATHER)
|
||||
#define TFT_DC PB4
|
||||
#define TFT_CS PA15
|
||||
#elif defined(ARDUINO_NRF52832_FEATHER) /* BSP 0.6.5 and higher! */
|
||||
#define TFT_DC 11
|
||||
#define TFT_CS 31
|
||||
#elif defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR)
|
||||
#define TFT_DC P5_4
|
||||
#define TFT_CS P5_3
|
||||
#else
|
||||
// Anything else, defaults!
|
||||
#define TFT_CS 5
|
||||
#define TFT_DC 6
|
||||
#endif
|
||||
|
||||
Adafruit_ST7789 tft_7789 = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
|
||||
Adafruit_ST7735 tft_7735 = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// we'll assign it later
|
||||
Adafruit_ST77xx *tft = NULL;
|
||||
uint32_t version;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
while (!Serial) delay(10); // Wait until serial console is opened
|
||||
|
||||
if (!ss.begin()) {
|
||||
Serial.println("seesaw couldn't be found!");
|
||||
while(1);
|
||||
}
|
||||
|
||||
version = ((ss.getVersion() >> 16) & 0xFFFF);
|
||||
Serial.print("Version: "); Serial.println(version);
|
||||
if (version == 3322) {
|
||||
Serial.println("Version 2 TFT FeatherWing found");
|
||||
|
||||
} else {
|
||||
Serial.println("Version 1 TFT FeatherWing found");
|
||||
}
|
||||
|
||||
ss.tftReset(); // reset the display
|
||||
ss.setBacklight(TFTWING_BACKLIGHT_ON); // turn off the backlight
|
||||
|
||||
if (version == 3322) {
|
||||
tft_7789.init(135, 240);
|
||||
tft = &tft_7789;
|
||||
} else {
|
||||
tft_7735.initR(INITR_MINI160x80); // initialize a ST7735S chip, mini display
|
||||
tft = &tft_7735;
|
||||
}
|
||||
tft->setRotation(1);
|
||||
Serial.println("TFT initialized");
|
||||
|
||||
tft->fillScreen(ST77XX_RED);
|
||||
delay(100);
|
||||
tft->fillScreen(ST77XX_GREEN);
|
||||
delay(100);
|
||||
tft->fillScreen(ST77XX_BLUE);
|
||||
delay(100);
|
||||
tft->fillScreen(ST77XX_BLACK);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(10);
|
||||
|
||||
uint32_t buttons = ss.readButtons();
|
||||
//Serial.println(buttons, BIN);
|
||||
|
||||
uint16_t color;
|
||||
|
||||
color = ST77XX_BLACK;
|
||||
if (! (buttons & TFTWING_BUTTON_LEFT)) {
|
||||
Serial.println("LEFT");
|
||||
color = ST77XX_WHITE;
|
||||
}
|
||||
if (version == 3322) {
|
||||
tft->fillTriangle(200, 45, 200, 85, 220, 65, color);
|
||||
} else {
|
||||
tft->fillTriangle(150, 30, 150, 50, 160, 40, color);
|
||||
}
|
||||
|
||||
color = ST77XX_BLACK;
|
||||
if (! (buttons & TFTWING_BUTTON_RIGHT)) {
|
||||
Serial.println("RIGHT");
|
||||
color = ST77XX_WHITE;
|
||||
}
|
||||
if (version == 3322) {
|
||||
tft->fillTriangle(120, 45, 120, 85, 100, 65, color);
|
||||
} else {
|
||||
tft->fillTriangle(120, 30, 120, 50, 110, 40, color);
|
||||
}
|
||||
|
||||
color = ST77XX_BLACK;
|
||||
if (! (buttons & TFTWING_BUTTON_DOWN)) {
|
||||
Serial.println("DOWN");
|
||||
color = ST77XX_WHITE;
|
||||
}
|
||||
if (version == 3322) {
|
||||
tft->fillTriangle(140, 25, 180, 25, 160, 10, color);
|
||||
} else {
|
||||
tft->fillTriangle(125, 26, 145, 26, 135, 16, color);
|
||||
}
|
||||
|
||||
color = ST77XX_BLACK;
|
||||
if (! (buttons & TFTWING_BUTTON_UP)) {
|
||||
Serial.println("UP");
|
||||
color = ST77XX_WHITE;
|
||||
}
|
||||
if (version == 3322) {
|
||||
tft->fillTriangle(140, 100, 180, 100, 160, 120, color);
|
||||
} else {
|
||||
tft->fillTriangle(125, 53, 145, 53, 135, 63, color);
|
||||
}
|
||||
|
||||
color = ST77XX_BLACK;
|
||||
if (! (buttons & TFTWING_BUTTON_A)) {
|
||||
Serial.println("A");
|
||||
color = ST7735_GREEN;
|
||||
}
|
||||
if (version == 3322) {
|
||||
tft->fillCircle(40, 100, 20, color);
|
||||
} else {
|
||||
tft->fillCircle(30, 57, 10, color);
|
||||
}
|
||||
|
||||
color = ST77XX_BLACK;
|
||||
if (! (buttons & TFTWING_BUTTON_B)) {
|
||||
Serial.println("B");
|
||||
color = ST77XX_YELLOW;
|
||||
}
|
||||
if (version == 3322) {
|
||||
tft->fillCircle(40, 30, 20, color);
|
||||
} else {
|
||||
tft->fillCircle(30, 18, 10, color);
|
||||
}
|
||||
|
||||
color = ST77XX_BLACK;
|
||||
if (! (buttons & TFTWING_BUTTON_SELECT)) {
|
||||
Serial.println("SELECT");
|
||||
color = ST77XX_RED;
|
||||
}
|
||||
if (version == 3322) {
|
||||
tft->fillCircle(160, 65, 20, color);
|
||||
} else {
|
||||
tft->fillCircle(80, 40, 7, color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
/***************************************************
|
||||
This is a library for the Adafruit 0.96" Mini TFT Featherwing
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
|
||||
#include "Adafruit_miniTFTWing.h"
|
||||
|
||||
Adafruit_miniTFTWing ss;
|
||||
#define TFT_RST -1 // we use the seesaw for resetting to save a pin
|
||||
|
||||
|
||||
#ifdef ESP8266
|
||||
#define TFT_CS 0
|
||||
#define TFT_DC 15
|
||||
#elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
|
||||
#define TFT_CS 15
|
||||
#define TFT_DC 33
|
||||
#elif defined(TEENSYDUINO)
|
||||
#define TFT_DC 10
|
||||
#define TFT_CS 4
|
||||
#elif defined(ARDUINO_STM32_FEATHER)
|
||||
#define TFT_DC PB4
|
||||
#define TFT_CS PA15
|
||||
#elif defined(ARDUINO_NRF52832_FEATHER) /* BSP 0.6.5 and higher! */
|
||||
#define TFT_DC 11
|
||||
#define TFT_CS 31
|
||||
#elif defined(ARDUINO_MAX32620FTHR) || defined(ARDUINO_MAX32630FTHR)
|
||||
#define TFT_DC P5_4
|
||||
#define TFT_CS P5_3
|
||||
#else
|
||||
// Anything else, defaults!
|
||||
#define TFT_CS 5
|
||||
#define TFT_DC 6
|
||||
#endif
|
||||
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
|
||||
float p = 3.1415926;
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.print("Hello! ST77xx TFT Test");
|
||||
|
||||
if (!ss.begin()) {
|
||||
Serial.println("seesaw init error!");
|
||||
while(1);
|
||||
}
|
||||
else Serial.println("seesaw started");
|
||||
|
||||
ss.tftReset();
|
||||
ss.setBacklight(0x0); //set the backlight fully on
|
||||
|
||||
// Use this initializer (uncomment) if you're using a 0.96" 180x60 TFT
|
||||
tft.initR(INITR_MINI160x80); // initialize a ST7735S chip, mini display
|
||||
|
||||
tft.setRotation(3);
|
||||
|
||||
Serial.println("Initialized");
|
||||
|
||||
uint16_t time = millis();
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
time = millis() - time;
|
||||
|
||||
Serial.println(time, DEC);
|
||||
delay(500);
|
||||
|
||||
// large block of text
|
||||
tft.fillScreen(ST77XX_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. ", ST77XX_WHITE);
|
||||
delay(1000);
|
||||
|
||||
// tft print function!
|
||||
tftPrintTest();
|
||||
delay(1000);
|
||||
|
||||
// a single pixel
|
||||
tft.drawPixel(tft.width()/2, tft.height()/2, ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
// line draw test
|
||||
testlines(ST77XX_YELLOW);
|
||||
delay(500);
|
||||
|
||||
// optimized lines
|
||||
testfastlines(ST77XX_RED, ST77XX_BLUE);
|
||||
delay(500);
|
||||
|
||||
testdrawrects(ST77XX_GREEN);
|
||||
delay(500);
|
||||
|
||||
testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA);
|
||||
delay(500);
|
||||
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
testfillcircles(10, ST77XX_BLUE);
|
||||
testdrawcircles(10, ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_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(ST77XX_BLACK);
|
||||
for (int16_t x=0; x < tft.height(); 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(ST77XX_BLACK);
|
||||
for (int16_t x=tft.height()-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(ST77XX_BLACK);
|
||||
uint16_t 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++) {
|
||||
tft.drawTriangle(w, y, y, x, z, x, color);
|
||||
x-=4;
|
||||
y+=4;
|
||||
z-=4;
|
||||
color+=100;
|
||||
}
|
||||
}
|
||||
|
||||
void testroundrects() {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
uint16_t color = 100;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int w = tft.width()-2;
|
||||
int h = tft.height()-2;
|
||||
while ((w > 10) && (h > 10)) {
|
||||
tft.drawRoundRect(x, y, w, h, 5, color);
|
||||
x+=2;
|
||||
y+=3;
|
||||
w-=4;
|
||||
h-=6;
|
||||
color+=1100;
|
||||
}
|
||||
}
|
||||
|
||||
void tftPrintTest() {
|
||||
tft.setTextWrap(false);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
delay(1500);
|
||||
tft.setCursor(0, 0);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setTextSize(0);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_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(ST77XX_WHITE);
|
||||
tft.println("Sketch has been");
|
||||
tft.println("running for: ");
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.print(millis() / 1000);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print(" seconds.");
|
||||
}
|
||||
|
||||
void mediabuttons() {
|
||||
// play
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
tft.fillRoundRect(0, 10, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillTriangle(17, 20, 17, 60, 65, 40, ST77XX_RED);
|
||||
delay(500);
|
||||
// pause
|
||||
tft.fillRoundRect(82, 10, 78, 60, 8, ST77XX_WHITE);
|
||||
tft.fillRoundRect(96, 18, 20, 45, 5, ST77XX_GREEN);
|
||||
tft.fillRoundRect(127, 18, 20, 45, 5, ST77XX_GREEN);
|
||||
delay(500);
|
||||
// play color
|
||||
tft.fillTriangle(17, 20, 17, 60, 65, 40, ST77XX_BLUE);
|
||||
delay(50);
|
||||
// pause color
|
||||
tft.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED);
|
||||
tft.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED);
|
||||
// play color
|
||||
tft.fillTriangle(17, 20, 17, 60, 65, 40, ST77XX_GREEN);
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
/***************************************************
|
||||
This is a library for the Adafruit 1.8" SPI display.
|
||||
|
||||
This library works with the Adafruit 1.8" TFT Breakout w/SD card
|
||||
----> http://www.adafruit.com/products/358
|
||||
The 1.8" TFT shield
|
||||
----> https://www.adafruit.com/product/802
|
||||
The 1.44" TFT breakout
|
||||
----> https://www.adafruit.com/product/2088
|
||||
The 1.14" TFT breakout
|
||||
----> https://www.adafruit.com/product/4383
|
||||
The 1.3" TFT breakout
|
||||
----> https://www.adafruit.com/product/4313
|
||||
The 1.54" TFT breakout
|
||||
----> https://www.adafruit.com/product/3787
|
||||
The 2.0" TFT breakout
|
||||
----> https://www.adafruit.com/product/4311
|
||||
as well as Adafruit raw 1.8" TFT display
|
||||
----> http://www.adafruit.com/products/618
|
||||
|
||||
This also works with many of the products with integrated displays
|
||||
|
||||
The HalloWing M0 Express
|
||||
----> http://www.adafruit.com/products/3900
|
||||
The PyBadge
|
||||
----> http://www.adafruit.com/products/4200
|
||||
The PyGamer
|
||||
----> http://www.adafruit.com/products/4242
|
||||
The HalloWing M4 Express
|
||||
----> http://www.adafruit.com/products/4300
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 or 5 pins are required to
|
||||
interface (RST is optional)
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h> // Core graphics library
|
||||
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
|
||||
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
|
||||
#include <SPI.h>
|
||||
|
||||
// For the breakout, you can use any 2 or 3 pins
|
||||
// These pins will also work for the 1.8" TFT shield
|
||||
#ifdef ADAFRUIT_HALLOWING
|
||||
#define TFT_CS 39 // Hallowing display control pins: chip select
|
||||
#define TFT_RST 37 // Display reset
|
||||
#define TFT_DC 38 // Display data/command select
|
||||
#define TFT_BACKLIGHT 7 // Display backlight pin
|
||||
|
||||
#elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || defined(ADAFRUIT_PYGAMER_M4_EXPRESS) || defined(ADAFRUIT_HALLOWING_M4_EXPRESS)
|
||||
#define TFT_CS 44 // PyBadge/PyGamer display control pins: chip select
|
||||
#define TFT_RST 46 // Display reset
|
||||
#define TFT_DC 45 // Display data/command select
|
||||
#define TFT_BACKLIGHT 47 // Display backlight pin
|
||||
|
||||
#elif defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
|
||||
#define TFT_CS 14
|
||||
#define TFT_RST 15
|
||||
#define TFT_DC 32
|
||||
|
||||
#elif defined(ESP8266)
|
||||
#define TFT_CS 4
|
||||
#define TFT_RST 16
|
||||
#define TFT_DC 5
|
||||
//
|
||||
#else
|
||||
// For the breakout board, you can use any 2 or 3 pins.
|
||||
// These pins will also work for the 1.8" TFT shield.
|
||||
#define TFT_CS 10
|
||||
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
|
||||
#define TFT_DC 8
|
||||
#endif
|
||||
|
||||
// Option 1 (recommended): must use the hardware SPI pins
|
||||
// (for UNO that's sclk = 13 and sid = 11) and pin 10 must be
|
||||
// an output. This is much faster - also required if you want
|
||||
// to use the microSD card (see the image drawing example)
|
||||
#if defined(ADAFRUIT_HALLOWING_M4_EXPRESS)
|
||||
// For Hallowing M4 Express
|
||||
Adafruit_ST7789 tft = Adafruit_ST7789(&SPI1, TFT_CS, TFT_DC, TFT_RST);
|
||||
#elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || defined(ADAFRUIT_PYGAMER_M4_EXPRESS)
|
||||
// For PyBadge and PyGamer
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(&SPI1, TFT_CS, TFT_DC, TFT_RST);
|
||||
#else
|
||||
// For 1.44" and 1.8" TFT with ST7735 (including HalloWing) use:
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
// For 1.14", 1.3", 1.54", and 2.0" TFT with ST7789:
|
||||
//Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
|
||||
#endif
|
||||
|
||||
// Option 2: use any pins but a little slower!
|
||||
//#define TFT_SCLK 13 // set these to be whatever pins you like!
|
||||
//#define TFT_MOSI 11 // set these to be whatever pins you like!
|
||||
//Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
Serial.print("Hello! Adafruit ST77XX rotation test");
|
||||
|
||||
#ifdef ADAFRUIT_HALLOWING_M4_EXPRESS
|
||||
// HalloWing M4 is a special case. It uses a ST7789 display just like the
|
||||
// breakout board, but the orientation and backlight control are different.
|
||||
tft.init(240, 240); // Initialize ST7789 screen
|
||||
pinMode(TFT_BACKLIGHT, OUTPUT);
|
||||
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
|
||||
|
||||
#elif ADAFRUIT_HALLOWING
|
||||
// HalloWing is a special case. It uses a ST7735R display just like the
|
||||
// breakout board, but the orientation and backlight control are different.
|
||||
tft.initR(INITR_HALLOWING); // Initialize HalloWing-oriented screen
|
||||
pinMode(TFT_BACKLIGHT, OUTPUT);
|
||||
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
|
||||
|
||||
#elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || defined(ADAFRUIT_PYGAMER_M4_EXPRESS)
|
||||
tft.initR(INITR_BLACKTAB); // Initialize ST7735R screen
|
||||
tft.setRotation(1);
|
||||
pinMode(TFT_BACKLIGHT, OUTPUT);
|
||||
digitalWrite(TFT_BACKLIGHT, HIGH); // Backlight on
|
||||
|
||||
#else
|
||||
// Use this initializer if you're using a 1.8" TFT
|
||||
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
|
||||
|
||||
// Use this initializer (uncomment) if you're using a 1.44" TFT
|
||||
//tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab
|
||||
|
||||
// Use this initializer (uncomment) if you're using a 0.96" 180x60 TFT
|
||||
//tft.initR(INITR_MINI160x80); // initialize a ST7735S chip, mini display
|
||||
|
||||
// Use this initializer (uncomment) if you're using a 1.54" 240x240 TFT
|
||||
//tft.init(240, 240); // initialize a ST7789 chip, 240x240 pixels
|
||||
|
||||
// OR use this initializer (uncomment) if using a 2.0" 320x240 TFT:
|
||||
//tft.init(240, 320); // Init ST7789 320x240
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.14" 240x135 TFT:
|
||||
//tft.init(135, 240); // Init ST7789 240x135
|
||||
|
||||
// OR use this initializer (uncomment) if using a 1.47" 174x320 TFT:
|
||||
//tft.init(174, 320); // Init ST7789 174x320
|
||||
|
||||
// SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
|
||||
// Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
|
||||
// may end up with a black screen some times, or all the time.
|
||||
//tft.setSPISpeed(40000000);
|
||||
#endif
|
||||
|
||||
Serial.println("init");
|
||||
|
||||
tft.setTextWrap(false); // Allow text to run off right edge
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
|
||||
Serial.println("This is a test of the rotation capabilities of the TFT library!");
|
||||
Serial.println("Press <SEND> (or type a character) to advance");
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
rotateLine();
|
||||
rotateText();
|
||||
rotatePixel();
|
||||
rotateFastline();
|
||||
rotateDrawrect();
|
||||
rotateFillrect();
|
||||
rotateDrawcircle();
|
||||
rotateFillcircle();
|
||||
rotateTriangle();
|
||||
rotateFillTriangle();
|
||||
rotateRoundRect();
|
||||
rotateFillRoundRect();
|
||||
rotateChar();
|
||||
rotateString();
|
||||
}
|
||||
|
||||
void rotateText() {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.setCursor(0, 30);
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setTextSize(1);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setTextSize(3);
|
||||
tft.println("Hello World!");
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setTextSize(4);
|
||||
tft.print(1234.567);
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateFillcircle(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.fillCircle(10, 30, 10, ST77XX_YELLOW);
|
||||
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateDrawcircle(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.drawCircle(10, 30, 10, ST77XX_YELLOW);
|
||||
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateFillrect(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.fillRect(10, 20, 10, 20, ST77XX_GREEN);
|
||||
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateDrawrect(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.drawRect(10, 20, 10, 20, ST77XX_GREEN);
|
||||
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateFastline(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.drawFastHLine(0, 20, tft.width(), ST77XX_RED);
|
||||
tft.drawFastVLine(20, 0, tft.height(), ST77XX_BLUE);
|
||||
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateLine(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, ST77XX_RED);
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotatePixel(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.drawPixel(10,20, ST77XX_WHITE);
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateTriangle(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.drawTriangle(20, 10, 10, 30, 30, 30, ST77XX_GREEN);
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateFillTriangle(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.fillTriangle(20, 10, 10, 30, 30, 30, ST77XX_RED);
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateRoundRect(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.drawRoundRect(20, 10, 25, 15, 5, ST77XX_BLUE);
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateFillRoundRect(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.fillRoundRect(20, 10, 25, 15, 5, ST77XX_CYAN);
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateChar(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.drawChar(25, 15, 'A', ST77XX_WHITE, ST77XX_WHITE, 1);
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
|
||||
void rotateString(void) {
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
Serial.println(tft.getRotation(), DEC);
|
||||
|
||||
tft.setCursor(8, 25);
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.print("Adafruit Industries");
|
||||
while (!Serial.available());
|
||||
Serial.read(); Serial.read(); Serial.read();
|
||||
|
||||
tft.setRotation(tft.getRotation()+1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
/***************************************************
|
||||
This is an example sketch for the Adafruit 1.8" TFT shield with joystick
|
||||
This example is for the Seesaw version
|
||||
----> http://www.adafruit.com/products/802
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 pins are required to
|
||||
interface
|
||||
One pin is also needed for the joystick, we use analog 3
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_ST7735.h>
|
||||
// Be sure to install Adafruit seesaw library!
|
||||
#include <Adafruit_seesaw.h>
|
||||
#include <Adafruit_TFTShield18.h>
|
||||
|
||||
Adafruit_TFTShield18 ss;
|
||||
|
||||
|
||||
// TFT display and SD card will share the hardware SPI interface.
|
||||
// Hardware SPI pins are specific to the Arduino board type and
|
||||
// cannot be remapped to alternate pins. For Arduino Uno,
|
||||
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
|
||||
#define SD_CS 4 // Chip select line for SD card on Shield
|
||||
#define TFT_CS 10 // Chip select line for TFT display on Shield
|
||||
#define TFT_DC 8 // Data/command line for TFT on Shield
|
||||
#define TFT_RST -1 // Reset line for TFT is handled by seesaw!
|
||||
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
|
||||
// start by disabling both SD and TFT
|
||||
pinMode(TFT_CS, OUTPUT);
|
||||
digitalWrite(TFT_CS, HIGH);
|
||||
pinMode(SD_CS, OUTPUT);
|
||||
digitalWrite(SD_CS, HIGH);
|
||||
|
||||
// Start seesaw helper chip
|
||||
if (!ss.begin()){
|
||||
Serial.println("seesaw could not be initialized!");
|
||||
while(1);
|
||||
}
|
||||
Serial.println("seesaw started");
|
||||
Serial.print("Version: "); Serial.println(ss.getVersion(), HEX);
|
||||
|
||||
// Start set the backlight off
|
||||
ss.setBacklight(TFTSHIELD_BACKLIGHT_OFF);
|
||||
// Reset the TFT
|
||||
ss.tftReset();
|
||||
|
||||
// Initialize 1.8" TFT
|
||||
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
|
||||
|
||||
Serial.println("TFT OK!");
|
||||
tft.fillScreen(ST77XX_CYAN);
|
||||
|
||||
Serial.print("Initializing SD card...");
|
||||
if (!SD.begin(SD_CS)) {
|
||||
Serial.println("failed!");
|
||||
} else {
|
||||
Serial.println("OK!");
|
||||
File root = SD.open("/");
|
||||
printDirectory(root, 0);
|
||||
root.close();
|
||||
bmpDraw("/parrot.bmp", 0, 0);
|
||||
}
|
||||
|
||||
// Set backlight on fully
|
||||
// ss.setBacklight(TFTSHIELD_BACKLIGHT_ON);
|
||||
// Or you can set the backlight one third on
|
||||
// ss.setBacklight(TFTSHIELD_BACKLIGHT_ON / 3);
|
||||
// Or dim it up
|
||||
for (int32_t i=TFTSHIELD_BACKLIGHT_OFF; i<TFTSHIELD_BACKLIGHT_ON; i+=100) {
|
||||
ss.setBacklight(i);
|
||||
delay(1);
|
||||
}
|
||||
delay(100);
|
||||
tft.fillScreen(ST77XX_RED);
|
||||
delay(100);
|
||||
tft.fillScreen(ST77XX_GREEN);
|
||||
delay(100);
|
||||
tft.fillScreen(ST77XX_BLUE);
|
||||
delay(100);
|
||||
tft.fillScreen(ST77XX_BLACK);
|
||||
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(ST77XX_WHITE);
|
||||
tft.setCursor(0, 0);
|
||||
tft.print("Press all the buttons");
|
||||
}
|
||||
|
||||
|
||||
uint8_t buttonhistory = 0;
|
||||
|
||||
void loop() {
|
||||
uint32_t buttons = ss.readButtons();
|
||||
tft.setTextSize(3);
|
||||
if(! (buttons & TFTSHIELD_BUTTON_DOWN)){
|
||||
tft.setTextColor(ST77XX_RED);
|
||||
tft.setCursor(0, 10);
|
||||
tft.print("Down ");
|
||||
buttonhistory |= 1;
|
||||
}
|
||||
if(! (buttons & TFTSHIELD_BUTTON_LEFT)){
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setCursor(0, 35);
|
||||
tft.print("Left ");
|
||||
buttonhistory |= 2;
|
||||
}
|
||||
if(! (buttons & TFTSHIELD_BUTTON_UP)){
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setCursor(0, 60);
|
||||
tft.print("Up");
|
||||
buttonhistory |= 4;
|
||||
}
|
||||
if(! (buttons & TFTSHIELD_BUTTON_RIGHT)){
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setCursor(0, 85);
|
||||
tft.print("Right");
|
||||
buttonhistory |= 8;
|
||||
}
|
||||
if(! (buttons & TFTSHIELD_BUTTON_1)){
|
||||
tft.setTextColor(ST77XX_BLUE);
|
||||
tft.setCursor(0, 140);
|
||||
tft.print("1");
|
||||
buttonhistory |= 16;
|
||||
}
|
||||
if(! (buttons & TFTSHIELD_BUTTON_2)){
|
||||
tft.setTextColor(ST77XX_GREEN);
|
||||
tft.setCursor(50, 140);
|
||||
tft.print("2");
|
||||
buttonhistory |= 32;
|
||||
}
|
||||
if(! (buttons & TFTSHIELD_BUTTON_3)){
|
||||
tft.setTextColor(ST77XX_YELLOW);
|
||||
tft.setCursor(100, 140);
|
||||
tft.print("3");
|
||||
buttonhistory |= 64;
|
||||
}
|
||||
if (! (buttons & TFTSHIELD_BUTTON_IN)) {
|
||||
tft.setTextColor(ST77XX_MAGENTA);
|
||||
tft.setCursor(0, 110);
|
||||
tft.print("SELECT");
|
||||
}
|
||||
if (buttonhistory == 0x7F) {
|
||||
bmpDraw("/parrot.bmp", 0, 0);
|
||||
while (1) {
|
||||
tft.invertDisplay(true);
|
||||
delay(500);
|
||||
tft.invertDisplay(false);
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// This function opens a Windows Bitmap (BMP) file and
|
||||
// displays it at the given coordinates. It's sped up
|
||||
// by reading many pixels worth of data at a time
|
||||
// (rather than pixel by pixel). Increasing the buffer
|
||||
// size takes more of the Arduino's precious RAM but
|
||||
// makes loading a little faster. 20 pixels seems a
|
||||
// good balance.
|
||||
|
||||
#define BUFFPIXEL 20
|
||||
|
||||
void bmpDraw(char *filename, uint8_t x, uint16_t y) {
|
||||
|
||||
File bmpFile;
|
||||
int bmpWidth, bmpHeight; // W+H in pixels
|
||||
uint8_t bmpDepth; // Bit depth (currently must be 24)
|
||||
uint32_t bmpImageoffset; // Start of image data in file
|
||||
uint32_t rowSize; // Not always = bmpWidth; may have padding
|
||||
uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
|
||||
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
|
||||
boolean goodBmp = false; // Set to true on valid header parse
|
||||
boolean flip = true; // BMP is stored bottom-to-top
|
||||
int w, h, row, col;
|
||||
uint8_t r, g, b;
|
||||
uint32_t pos = 0, startTime = millis();
|
||||
|
||||
if((x >= tft.width()) || (y >= tft.height())) return;
|
||||
|
||||
Serial.println();
|
||||
Serial.print(F("Loading image '"));
|
||||
Serial.print(filename);
|
||||
Serial.println('\'');
|
||||
|
||||
// Open requested file on SD card
|
||||
if ((bmpFile = SD.open(filename)) == NULL) {
|
||||
Serial.print(F("File not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse BMP header
|
||||
if(read16(bmpFile) == 0x4D42) { // BMP signature
|
||||
Serial.print(F("File size: ")); Serial.println(read32(bmpFile));
|
||||
(void)read32(bmpFile); // Read & ignore creator bytes
|
||||
bmpImageoffset = read32(bmpFile); // Start of image data
|
||||
Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
|
||||
// Read DIB header
|
||||
Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
|
||||
bmpWidth = read32(bmpFile);
|
||||
bmpHeight = read32(bmpFile);
|
||||
if(read16(bmpFile) == 1) { // # planes -- must be '1'
|
||||
bmpDepth = read16(bmpFile); // bits per pixel
|
||||
Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
|
||||
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
|
||||
|
||||
goodBmp = true; // Supported BMP format -- proceed!
|
||||
Serial.print(F("Image size: "));
|
||||
Serial.print(bmpWidth);
|
||||
Serial.print('x');
|
||||
Serial.println(bmpHeight);
|
||||
|
||||
// BMP rows are padded (if needed) to 4-byte boundary
|
||||
rowSize = (bmpWidth * 3 + 3) & ~3;
|
||||
|
||||
// If bmpHeight is negative, image is in top-down order.
|
||||
// This is not canon but has been observed in the wild.
|
||||
if(bmpHeight < 0) {
|
||||
bmpHeight = -bmpHeight;
|
||||
flip = false;
|
||||
}
|
||||
|
||||
// Crop area to be loaded
|
||||
w = bmpWidth;
|
||||
h = bmpHeight;
|
||||
if((x+w-1) >= tft.width()) w = tft.width() - x;
|
||||
if((y+h-1) >= tft.height()) h = tft.height() - y;
|
||||
|
||||
// Set TFT address window to clipped image bounds
|
||||
tft.startWrite();
|
||||
tft.setAddrWindow(x, y, w, h);
|
||||
|
||||
for (row=0; row<h; row++) { // For each scanline...
|
||||
|
||||
// Seek to start of scan line. It might seem labor-
|
||||
// intensive to be doing this on every line, but this
|
||||
// method covers a lot of gritty details like cropping
|
||||
// and scanline padding. Also, the seek only takes
|
||||
// place if the file position actually needs to change
|
||||
// (avoids a lot of cluster math in SD library).
|
||||
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
|
||||
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
|
||||
else // Bitmap is stored top-to-bottom
|
||||
pos = bmpImageoffset + row * rowSize;
|
||||
if(bmpFile.position() != pos) { // Need seek?
|
||||
tft.endWrite();
|
||||
bmpFile.seek(pos);
|
||||
buffidx = sizeof(sdbuffer); // Force buffer reload
|
||||
}
|
||||
|
||||
for (col=0; col<w; col++) { // For each pixel...
|
||||
// Time to read more pixel data?
|
||||
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
||||
bmpFile.read(sdbuffer, sizeof(sdbuffer));
|
||||
buffidx = 0; // Set index to beginning
|
||||
tft.startWrite();
|
||||
}
|
||||
|
||||
// Convert pixel from BMP to TFT format, push to display
|
||||
b = sdbuffer[buffidx++];
|
||||
g = sdbuffer[buffidx++];
|
||||
r = sdbuffer[buffidx++];
|
||||
tft.pushColor(tft.color565(r,g,b));
|
||||
} // end pixel
|
||||
} // end scanline
|
||||
tft.endWrite();
|
||||
Serial.print(F("Loaded in "));
|
||||
Serial.print(millis() - startTime);
|
||||
Serial.println(" ms");
|
||||
} // end goodBmp
|
||||
}
|
||||
}
|
||||
|
||||
bmpFile.close();
|
||||
if(!goodBmp) Serial.println(F("BMP format not recognized."));
|
||||
}
|
||||
|
||||
|
||||
// These read 16- and 32-bit types from the SD card file.
|
||||
// BMP data is stored little-endian, Arduino is little-endian too.
|
||||
// May need to reverse subscript order if porting elsewhere.
|
||||
|
||||
uint16_t read16(File f) {
|
||||
uint16_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
((uint8_t *)&result)[1] = f.read(); // MSB
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t read32(File f) {
|
||||
uint32_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
((uint8_t *)&result)[1] = f.read();
|
||||
((uint8_t *)&result)[2] = f.read();
|
||||
((uint8_t *)&result)[3] = f.read(); // MSB
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void printDirectory(File dir, int numTabs) {
|
||||
while (true) {
|
||||
|
||||
File entry = dir.openNextFile();
|
||||
if (! entry) {
|
||||
// no more files
|
||||
break;
|
||||
}
|
||||
for (uint8_t i = 0; i < numTabs; i++) {
|
||||
Serial.print('\t');
|
||||
}
|
||||
Serial.print(entry.name());
|
||||
if (entry.isDirectory()) {
|
||||
Serial.println("/");
|
||||
printDirectory(entry, numTabs + 1);
|
||||
} else {
|
||||
// files have sizes, directories do not
|
||||
Serial.print("\t\t");
|
||||
Serial.println(entry.size(), DEC);
|
||||
}
|
||||
entry.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
/***************************************************
|
||||
This is an example sketch for the Adafruit 1.8" TFT shield with joystick
|
||||
----> http://www.adafruit.com/products/802
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
These displays use SPI to communicate, 4 pins are required to
|
||||
interface
|
||||
One pin is also needed for the joystick, we use analog 3
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
MIT license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_ST7735.h>
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#if defined(__SAM3X8E__)
|
||||
#undef __FlashStringHelper::F(string_literal)
|
||||
#define F(string_literal) string_literal
|
||||
#endif
|
||||
|
||||
// TFT display and SD card will share the hardware SPI interface.
|
||||
// Hardware SPI pins are specific to the Arduino board type and
|
||||
// cannot be remapped to alternate pins. For Arduino Uno,
|
||||
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
|
||||
#define SD_CS 4 // Chip select line for SD card
|
||||
#define TFT_CS 10 // Chip select line for TFT display
|
||||
#define TFT_DC 8 // Data/command line for TFT
|
||||
#define TFT_RST -1 // Reset line for TFT (or connect to +5V)
|
||||
|
||||
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
|
||||
|
||||
#define BUTTON_NONE 0
|
||||
#define BUTTON_DOWN 1
|
||||
#define BUTTON_RIGHT 2
|
||||
#define BUTTON_SELECT 3
|
||||
#define BUTTON_UP 4
|
||||
#define BUTTON_LEFT 5
|
||||
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
|
||||
// Initialize 1.8" TFT
|
||||
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
|
||||
|
||||
Serial.println("OK!");
|
||||
tft.fillScreen(ST7735_BLACK);
|
||||
}
|
||||
|
||||
|
||||
uint8_t readButton(void) {
|
||||
float a = analogRead(3);
|
||||
|
||||
a *= 5.0;
|
||||
a /= 1024.0;
|
||||
|
||||
Serial.print("Button read analog = ");
|
||||
Serial.println(a);
|
||||
if (a < 0.2) return BUTTON_DOWN;
|
||||
if (a < 1.0) return BUTTON_RIGHT;
|
||||
if (a < 1.5) return BUTTON_SELECT;
|
||||
if (a < 2.0) return BUTTON_UP;
|
||||
if (a < 3.2) return BUTTON_LEFT;
|
||||
else return BUTTON_NONE;
|
||||
}
|
||||
|
||||
uint8_t buttonhistory = 0;
|
||||
|
||||
void loop() {
|
||||
uint8_t b = readButton();
|
||||
tft.setTextSize(3);
|
||||
if (b == BUTTON_DOWN) {
|
||||
tft.setTextColor(ST7735_RED);
|
||||
tft.setCursor(0, 10);
|
||||
tft.print("Down ");
|
||||
buttonhistory |= 1;
|
||||
}
|
||||
if (b == BUTTON_LEFT) {
|
||||
tft.setTextColor(ST7735_YELLOW);
|
||||
tft.setCursor(0, 35);
|
||||
tft.print("Left ");
|
||||
buttonhistory |= 2;
|
||||
}
|
||||
if (b == BUTTON_UP) {
|
||||
tft.setTextColor(ST7735_GREEN);
|
||||
tft.setCursor(0, 60);
|
||||
tft.print("Up");
|
||||
buttonhistory |= 4;
|
||||
}
|
||||
if (b == BUTTON_RIGHT) {
|
||||
tft.setTextColor(ST7735_BLUE);
|
||||
tft.setCursor(0, 85);
|
||||
tft.print("Right");
|
||||
buttonhistory |= 8;
|
||||
}
|
||||
if ((b == BUTTON_SELECT) && (buttonhistory == 0xF)) {
|
||||
tft.setTextColor(ST7735_MAGENTA);
|
||||
tft.setCursor(0, 110);
|
||||
tft.print("SELECT");
|
||||
buttonhistory |= 8;
|
||||
delay(2000);
|
||||
Serial.print("Initializing SD card...");
|
||||
if (!SD.begin(SD_CS)) {
|
||||
Serial.println("failed!");
|
||||
return;
|
||||
}
|
||||
bmpDraw("parrot.bmp", 0, 0);
|
||||
while (1);
|
||||
}
|
||||
delay(100);
|
||||
}
|
||||
|
||||
// This function opens a Windows Bitmap (BMP) file and
|
||||
// displays it at the given coordinates. It's sped up
|
||||
// by reading many pixels worth of data at a time
|
||||
// (rather than pixel by pixel). Increasing the buffer
|
||||
// size takes more of the Arduino's precious RAM but
|
||||
// makes loading a little faster. 20 pixels seems a
|
||||
// good balance.
|
||||
|
||||
#define BUFFPIXEL 20
|
||||
|
||||
void bmpDraw(char *filename, uint8_t x, uint8_t y) {
|
||||
|
||||
File bmpFile;
|
||||
int bmpWidth, bmpHeight; // W+H in pixels
|
||||
uint8_t bmpDepth; // Bit depth (currently must be 24)
|
||||
uint32_t bmpImageoffset; // Start of image data in file
|
||||
uint32_t rowSize; // Not always = bmpWidth; may have padding
|
||||
uint8_t sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
|
||||
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer
|
||||
boolean goodBmp = false; // Set to true on valid header parse
|
||||
boolean flip = true; // BMP is stored bottom-to-top
|
||||
int w, h, row, col;
|
||||
uint8_t r, g, b;
|
||||
uint32_t pos = 0, startTime = millis();
|
||||
|
||||
if((x >= tft.width()) || (y >= tft.height())) return;
|
||||
|
||||
Serial.println();
|
||||
Serial.print("Loading image '");
|
||||
Serial.print(filename);
|
||||
Serial.println('\'');
|
||||
|
||||
// Open requested file on SD card
|
||||
if ((bmpFile = SD.open(filename)) == NULL) {
|
||||
Serial.print("File not found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse BMP header
|
||||
if(read16(bmpFile) == 0x4D42) { // BMP signature
|
||||
Serial.print("File size: "); Serial.println(read32(bmpFile));
|
||||
(void)read32(bmpFile); // Read & ignore creator bytes
|
||||
bmpImageoffset = read32(bmpFile); // Start of image data
|
||||
Serial.print("Image Offset: "); Serial.println(bmpImageoffset, DEC);
|
||||
// Read DIB header
|
||||
Serial.print("Header size: "); Serial.println(read32(bmpFile));
|
||||
bmpWidth = read32(bmpFile);
|
||||
bmpHeight = read32(bmpFile);
|
||||
if(read16(bmpFile) == 1) { // # planes -- must be '1'
|
||||
bmpDepth = read16(bmpFile); // bits per pixel
|
||||
Serial.print("Bit Depth: "); Serial.println(bmpDepth);
|
||||
if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
|
||||
|
||||
goodBmp = true; // Supported BMP format -- proceed!
|
||||
Serial.print("Image size: ");
|
||||
Serial.print(bmpWidth);
|
||||
Serial.print('x');
|
||||
Serial.println(bmpHeight);
|
||||
|
||||
// BMP rows are padded (if needed) to 4-byte boundary
|
||||
rowSize = (bmpWidth * 3 + 3) & ~3;
|
||||
|
||||
// If bmpHeight is negative, image is in top-down order.
|
||||
// This is not canon but has been observed in the wild.
|
||||
if(bmpHeight < 0) {
|
||||
bmpHeight = -bmpHeight;
|
||||
flip = false;
|
||||
}
|
||||
|
||||
// Crop area to be loaded
|
||||
w = bmpWidth;
|
||||
h = bmpHeight;
|
||||
if((x+w-1) >= tft.width()) w = tft.width() - x;
|
||||
if((y+h-1) >= tft.height()) h = tft.height() - y;
|
||||
|
||||
// Set TFT address window to clipped image bounds
|
||||
tft.startWrite();
|
||||
tft.setAddrWindow(x, y, w, h);
|
||||
|
||||
for (row=0; row<h; row++) { // For each scanline...
|
||||
|
||||
// Seek to start of scan line. It might seem labor-
|
||||
// intensive to be doing this on every line, but this
|
||||
// method covers a lot of gritty details like cropping
|
||||
// and scanline padding. Also, the seek only takes
|
||||
// place if the file position actually needs to change
|
||||
// (avoids a lot of cluster math in SD library).
|
||||
if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
|
||||
pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
|
||||
else // Bitmap is stored top-to-bottom
|
||||
pos = bmpImageoffset + row * rowSize;
|
||||
if(bmpFile.position() != pos) { // Need seek?
|
||||
tft.endWrite();
|
||||
bmpFile.seek(pos);
|
||||
buffidx = sizeof(sdbuffer); // Force buffer reload
|
||||
}
|
||||
|
||||
for (col=0; col<w; col++) { // For each pixel...
|
||||
// Time to read more pixel data?
|
||||
if (buffidx >= sizeof(sdbuffer)) { // Indeed
|
||||
bmpFile.read(sdbuffer, sizeof(sdbuffer));
|
||||
buffidx = 0; // Set index to beginning
|
||||
tft.startWrite();
|
||||
}
|
||||
|
||||
// Convert pixel from BMP to TFT format, push to display
|
||||
b = sdbuffer[buffidx++];
|
||||
g = sdbuffer[buffidx++];
|
||||
r = sdbuffer[buffidx++];
|
||||
tft.pushColor(tft.color565(r,g,b));
|
||||
} // end pixel
|
||||
} // end scanline
|
||||
tft.endWrite();
|
||||
Serial.print("Loaded in ");
|
||||
Serial.print(millis() - startTime);
|
||||
Serial.println(" ms");
|
||||
} // end goodBmp
|
||||
}
|
||||
}
|
||||
|
||||
bmpFile.close();
|
||||
if(!goodBmp) Serial.println("BMP format not recognized.");
|
||||
}
|
||||
|
||||
// These read 16- and 32-bit types from the SD card file.
|
||||
// BMP data is stored little-endian, Arduino is little-endian too.
|
||||
// May need to reverse subscript order if porting elsewhere.
|
||||
|
||||
uint16_t read16(File f) {
|
||||
uint16_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
((uint8_t *)&result)[1] = f.read(); // MSB
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t read32(File f) {
|
||||
uint32_t result;
|
||||
((uint8_t *)&result)[0] = f.read(); // LSB
|
||||
((uint8_t *)&result)[1] = f.read();
|
||||
((uint8_t *)&result)[2] = f.read();
|
||||
((uint8_t *)&result)[3] = f.read(); // MSB
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
name=Adafruit ST7735 and ST7789 Library
|
||||
version=1.10.4
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=This is a library for the Adafruit ST7735 and ST7789 SPI displays.
|
||||
paragraph=This is a library for the Adafruit ST7735 and ST7789 SPI displays.
|
||||
category=Display
|
||||
url=https://github.com/adafruit/Adafruit-ST7735-Library
|
||||
architectures=*
|
||||
depends=Adafruit GFX Library, Adafruit seesaw Library, SD
|
||||
Reference in New Issue
Block a user