/*******************************************************************
Hello World for the ESP32 Cheap Yellow Display.
https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display
If you find what I do useful and would like to support me,
please consider becoming a sponsor on Github
https://github.com/sponsors/witnessmenow/
Written by Brian Lough
YouTube: https://www.youtube.com/brianlough
Twitter: https://twitter.com/witnessmenow
*******************************************************************/
// Make sure to copy the UserSetup.h file into the library as
// per the Github Instructions. The pins are defined in there.
// Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
// Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
// Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
// Note the following larger fonts are primarily numeric only!
// Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
// Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
// Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
/*
#include "User_Setup.h"
#include <TFT_eSPI.h>
// A library for interfacing with LCD displays
//
// Can be installed from the library manager (Search for "TFT_eSPI")
//https://github.com/Bodmer/TFT_eSPI
TFT_eSPI tft = TFT_eSPI();
void setup() {
Serial.begin(9600);
// Start the tft display and set it to black
tft.init();
Serial.println("tft.init");
tft.setRotation(1); //This is the display in landscape
Serial.println("rotate");
// Clear the screen before writing to it
tft.fillScreen(TFT_BLACK);
Serial.println("fillscreenBlack");
tft.setTextColor(TFT_WHITE, TFT_BLACK);
int x = 5;
int y = 10;
int fontNum = 1;
tft.drawString("Hello", x, y, fontNum); // Left Aligned
Serial.println("tft_hello");
x = 320 /2;
y += 16;
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.drawCentreString("World", x, y, fontNum);
Serial.println("tft_world");
}
void loop() {
// put your main code here, to run repeatedly:
}
*/
/*
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 "User_Setup.h"
#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
unsigned long targetTime = 0;
byte red = 31;
byte green = 0;
byte blue = 0;
byte state = 0;
unsigned int colour = red << 11;
void setup(void) {
Serial.begin(115200);
Serial.printf("HelloWorld\n");
tft.init();
tft.setRotation(1);
//tft.fillScreen(TFT_BLACK);
targetTime = millis() + 100;
}
void loop() {
/*
tft.fillScreen(TFT_RED);
Serial.printf("Red %d %d\n", TFT_RED, TFT_RED);
delay(1000);
tft.fillScreen(TFT_GREEN);
delay(1000);
tft.fillScreen(TFT_BLUE);
delay(1000);
tft.fillScreen(TFT_BLACK);
delay(1000);
tft.fillScreen(TFT_WHITE);
delay(1000);
tft.fillScreen(random(0x10000));
delay(1000);
*/
// LCD_Clear(0x0000);
//delay(2000);
// LCD_Clear(0xfffc);
//delay(2000);
if (targetTime < millis())
{
targetTime = millis() + 10000;
// Colour changing state machine
for (int i = 0; i < 320; i++) {
tft.drawFastVLine(i, 0, tft.height(), 0xFFFF - 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
Serial.printf("millis() %ld\n", millis());
//char* text = sprintf("foo %lu", millis());
tft.drawString(String("millis() ") + String(millis(), DEC), 160, 120, 4);
int analogValue = analogRead(34);
Serial.printf("Light() %ld\n", analogValue);
tft.drawString(String("Light() ") + String(analogValue, DEC), 160, 140, 4);
delay(500);
}
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1