Initial commit
This commit is contained in:
147
T-Display-S3-main/example/TFT_Rainbow/TFT_Rainbow.ino
Normal file
147
T-Display-S3-main/example/TFT_Rainbow/TFT_Rainbow.ino
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
An example showing rainbow colours on a 1.8" TFT LCD screen
|
||||
and to show a basic example of font use.
|
||||
|
||||
Make sure all the display driver and pin connections are correct by
|
||||
editing the User_Setup.h file in the TFT_eSPI library folder.
|
||||
|
||||
Note that yield() or delay(0) must be called in long duration for/while
|
||||
loops to stop the ESP8266 watchdog triggering.
|
||||
|
||||
#########################################################################
|
||||
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
|
||||
#########################################################################
|
||||
*/
|
||||
|
||||
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
|
||||
#include <SPI.h>
|
||||
#include "pin_config.h"
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
|
||||
|
||||
unsigned long targetTime = 0;
|
||||
byte red = 31;
|
||||
byte green = 0;
|
||||
byte blue = 0;
|
||||
byte state = 0;
|
||||
unsigned int colour = red << 11;
|
||||
uint32_t runing = 0;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(PIN_POWER_ON, OUTPUT);
|
||||
digitalWrite(PIN_POWER_ON, HIGH);
|
||||
|
||||
tft.init();
|
||||
tft.setRotation(1);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
||||
|
||||
tft.fillScreen(TFT_RED); delay(1000);
|
||||
tft.fillScreen(TFT_GREEN); delay(1000);
|
||||
tft.fillScreen(TFT_BLUE); delay(1000);
|
||||
|
||||
targetTime = millis() + 1000;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if (millis() > runing) {
|
||||
Serial.print("Current running ");
|
||||
Serial.print(millis());
|
||||
Serial.println(" millis");
|
||||
runing = millis() + 1000;
|
||||
}
|
||||
if (targetTime < millis()) {
|
||||
targetTime = millis() + 10000;
|
||||
|
||||
// Colour changing state machine
|
||||
for (int i = 0; i < tft.width(); i++) {
|
||||
tft.drawFastVLine(i, 0, tft.height(), colour);
|
||||
switch (state) {
|
||||
case 0:
|
||||
green += 2;
|
||||
if (green == 64) {
|
||||
green = 63;
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
red--;
|
||||
if (red == 255) {
|
||||
red = 0;
|
||||
state = 2;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
blue ++;
|
||||
if (blue == 32) {
|
||||
blue = 31;
|
||||
state = 3;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
green -= 2;
|
||||
if (green == 255) {
|
||||
green = 0;
|
||||
state = 4;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
red ++;
|
||||
if (red == 32) {
|
||||
red = 31;
|
||||
state = 5;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
blue --;
|
||||
if (blue == 255) {
|
||||
blue = 0;
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
colour = red << 11 | green << 5 | blue;
|
||||
}
|
||||
|
||||
// The standard ADAFruit font still works as before
|
||||
tft.setTextColor(TFT_BLACK);
|
||||
tft.setCursor (12, 5);
|
||||
tft.print("Original ADAfruit font!");
|
||||
|
||||
// The new larger fonts do not use the .setCursor call, coords are embedded
|
||||
tft.setTextColor(TFT_BLACK, TFT_BLACK); // Do not plot the background colour
|
||||
|
||||
// Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!)
|
||||
tft.drawCentreString("Font size 2", 80, 14, 2); // Draw text centre at position 80, 12 using font 2
|
||||
|
||||
//tft.drawCentreString("Font size 2",81,12,2); // Draw text centre at position 80, 12 using font 2
|
||||
|
||||
tft.drawCentreString("Font size 4", 80, 30, 4); // Draw text centre at position 80, 24 using font 4
|
||||
|
||||
tft.drawCentreString("12.34", 80, 54, 6); // Draw text centre at position 80, 24 using font 6
|
||||
|
||||
tft.drawCentreString("12.34 is in font size 6", 80, 92, 2); // Draw text centre at position 80, 90 using font 2
|
||||
|
||||
// Note the x position is the top left of the font!
|
||||
|
||||
// draw a floating point number
|
||||
float pi = 3.14159; // Value to print
|
||||
int precision = 3; // Number of digits after decimal point
|
||||
int xpos = 50; // x position
|
||||
int ypos = 110; // y position
|
||||
int font = 2; // font number only 2,4,6,7 valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : a p m
|
||||
xpos += tft.drawFloat(pi, precision, xpos, ypos, font); // Draw rounded number and return new xpos delta for next print position
|
||||
tft.drawString(" is pi", xpos, ypos, font); // Continue printing from new x position
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
32
T-Display-S3-main/example/TFT_Rainbow/pin_config.h
Normal file
32
T-Display-S3-main/example/TFT_Rainbow/pin_config.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
/*ESP32S3*/
|
||||
#define PIN_LCD_BL 38
|
||||
|
||||
#define PIN_LCD_D0 39
|
||||
#define PIN_LCD_D1 40
|
||||
#define PIN_LCD_D2 41
|
||||
#define PIN_LCD_D3 42
|
||||
#define PIN_LCD_D4 45
|
||||
#define PIN_LCD_D5 46
|
||||
#define PIN_LCD_D6 47
|
||||
#define PIN_LCD_D7 48
|
||||
|
||||
#define PIN_POWER_ON 15
|
||||
|
||||
#define PIN_LCD_RES 5
|
||||
#define PIN_LCD_CS 6
|
||||
#define PIN_LCD_DC 7
|
||||
#define PIN_LCD_WR 8
|
||||
#define PIN_LCD_RD 9
|
||||
|
||||
#define PIN_BUTTON_1 0
|
||||
#define PIN_BUTTON_2 14
|
||||
#define PIN_BAT_VOLT 4
|
||||
|
||||
#define PIN_IIC_SCL 17
|
||||
#define PIN_IIC_SDA 18
|
||||
|
||||
#define PIN_TOUCH_INT 16
|
||||
#define PIN_TOUCH_RES 21
|
||||
Reference in New Issue
Block a user