Skip to content

Commit

Permalink
feat: add examples for epaper
Browse files Browse the repository at this point in the history
  • Loading branch information
LynnL4 committed Feb 13, 2025
1 parent b942eb3 commit 9c9b619
Show file tree
Hide file tree
Showing 12 changed files with 3,512 additions and 597 deletions.
21 changes: 21 additions & 0 deletions examples/ePaper/Basic/Bitmap/Bitmap.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "TFT_eSPI.h"
#include "image.h"
EPaper epaper;
void setup()
{

epaper.begin();
epaper.fillScreen(TFT_WHITE);
epaper.update(); // update the display

// epaper.pushImage(0, 0, 800, 480, (uint16_t *)gImage_1);
// epaper.update();

epaper.update(0, 0, 800, 480, (uint16_t *)gImage_1);

}

void loop()
{
// put your main code here, to run repeatedly:
}
3,002 changes: 3,002 additions & 0 deletions examples/ePaper/Basic/Bitmap/image.h

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions examples/ePaper/Basic/Clock/Clock.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
An example analogue clock using a TFT LCD screen to show the time
use of some of the drawing commands with the library.
For a more accurate clock, it would be better to use the RTClib library.
But this is just a demo.
This sketch uses font 4 only.
Make sure all the display driver and pin connections are correct by
editing the User_Setup.h file in the TFT_eSPI library folder.
#########################################################################
###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
#########################################################################
Based on a sketch by Gilchrist 6/2/2014 1.0
*/

#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library

EPaper epaper = EPaper(); // Invoke custom library

float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0; // Saved H, M, S x & y multipliers
float sdeg = 0, mdeg = 0, hdeg = 0;
uint16_t osx = 120, osy = 120, omx = 120, omy = 120, ohx = 120, ohy = 120; // Saved H, M, S x & y coords
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
uint32_t targetTime = 0; // for next 1 second timeout

static uint8_t conv2d(const char *p); // Forward declaration needed for IDE 1.6.x
uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time

bool initial = 1;

void setup(void)
{
epaper.begin();
epaper.setRotation(0);

epaper.fillScreen(TFT_WHITE);

epaper.setTextColor(TFT_BLACK, TFT_WHITE); // Adding a background colour erases previous text automatically

// Draw clock face
epaper.fillCircle(120, 120, 118, TFT_BLACK);
epaper.fillCircle(120, 120, 110, TFT_WHITE);

// Draw 12 lines
for (int i = 0; i < 360; i += 30)
{
sx = cos((i - 90) * 0.0174532925);
sy = sin((i - 90) * 0.0174532925);
x0 = sx * 114 + 120;
yy0 = sy * 114 + 120;
x1 = sx * 100 + 120;
yy1 = sy * 100 + 120;

epaper.drawLine(x0, yy0, x1, yy1, TFT_BLACK);
}

// Draw 60 dots
for (int i = 0; i < 360; i += 6)
{
sx = cos((i - 90) * 0.0174532925);
sy = sin((i - 90) * 0.0174532925);
x0 = sx * 102 + 120;
yy0 = sy * 102 + 120;
// Draw minute markers
epaper.drawPixel(x0, yy0, TFT_BLACK);

// Draw main quadrant dots
if (i == 0 || i == 180)
epaper.fillCircle(x0, yy0, 2, TFT_BLACK);
if (i == 90 || i == 270)
epaper.fillCircle(x0, yy0, 2, TFT_BLACK);
}

epaper.fillCircle(120, 121, 3, TFT_BLACK);

// Draw text at position 120,260 using fonts 4
// Only font numbers 2,4,6,7 are valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : . - a p m
// Font 7 is a 7 segment font and only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : .
epaper.drawCentreString("Time flies", 120, 260, 4);

epaper.update();

targetTime = millis() + 1000;
}

void loop()
{
if (targetTime < millis())
{
targetTime += 1000;
ss++; // Advance second
if (ss == 60)
{
ss = 0;
mm++; // Advance minute
if (mm > 59)
{
mm = 0;
hh++; // Advance hour
if (hh > 23)
{
hh = 0;
}
}
}

// Pre-compute hand degrees, x & y coords for a fast screen update
sdeg = ss * 6; // 0-59 -> 0-354
mdeg = mm * 6 + sdeg * 0.01666667; // 0-59 -> 0-360 - includes seconds
hdeg = hh * 30 + mdeg * 0.0833333; // 0-11 -> 0-360 - includes minutes and seconds
hx = cos((hdeg - 90) * 0.0174532925);
hy = sin((hdeg - 90) * 0.0174532925);
mx = cos((mdeg - 90) * 0.0174532925);
my = sin((mdeg - 90) * 0.0174532925);
sx = cos((sdeg - 90) * 0.0174532925);
sy = sin((sdeg - 90) * 0.0174532925);

if (ss == 0 || initial)
{
initial = 0;
// Erase hour and minute hand positions every minute
epaper.drawLine(ohx, ohy, 120, 121, TFT_WHITE);
ohx = hx * 62 + 121;
ohy = hy * 62 + 121;
epaper.drawLine(omx, omy, 120, 121, TFT_WHITE);
omx = mx * 84 + 120;
omy = my * 84 + 121;
}

// Redraw new hand positions, hour and minute hands not erased here to avoid flicker
epaper.drawLine(osx, osy, 120, 121, TFT_WHITE);
osx = sx * 90 + 121;
osy = sy * 90 + 121;
epaper.drawLine(osx, osy, 120, 121, TFT_BLACK);
epaper.drawLine(ohx, ohy, 120, 121, TFT_BLACK);
epaper.drawLine(omx, omy, 120, 121, TFT_BLACK);
epaper.drawLine(osx, osy, 120, 121, TFT_BLACK);

epaper.fillCircle(120, 121, 3, TFT_BLACK);
epaper.update();
}
}

static uint8_t conv2d(const char *p)
{
uint8_t v = 0;
if ('0' <= *p && *p <= '9')
v = *p - '0';
return 10 * v + *++p - '0';
}
130 changes: 130 additions & 0 deletions examples/ePaper/Basic/Clock_Digital/Clock_Digital.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
An example digital clock using a TFT LCD screen to show the time.
Demonstrates use of the font printing routines. (Time updates but date does not.)
For a more accurate clock, it would be better to use the RTClib library.
But this is just a demo.
This examples uses the hardware SPI only. Non-hardware SPI
is just too slow (~8 times slower!)
Based on clock sketch by Gilchrist 6/2/2014 1.0
Updated by Bodmer
A few colour codes:
code color
0x0000 Black
0xFFFF White
0xBDF7 Light Gray
0x7BEF Dark Gray
0xF800 Red
0xFFE0 Yellow
0xFBE0 Orange
0x79E0 Brown
0x7E0 Green
0x7FF Cyan
0x1F Blue
0xF81F Pink
*/

#include <TFT_eSPI.h> // Graphics and font library for ST7735 driver chip
#include <SPI.h>

EPaper epaper = EPaper(); // Invoke library, pins defined in User_Setup.h

uint32_t targetTime = 0; // for next 1 second timeout

byte omm = 99;
bool initial = 1;
byte xcolon = 0;
unsigned int colour = 0;

static uint8_t conv2d(const char* p) {
uint8_t v = 0;
if ('0' <= *p && *p <= '9')
v = *p - '0';
return 10 * v + *++p - '0';
}

uint8_t hh=conv2d(__TIME__), mm=conv2d(__TIME__+3), ss=conv2d(__TIME__+6); // Get H, M, S from compile time

void setup(void) {
epaper.begin();
epaper.setRotation(1);
epaper.fillScreen(TFT_BLACK);

epaper.setTextColor(TFT_YELLOW, TFT_BLACK); // Note: the new fonts do not draw the background colour
epaper.update(); // update the display
targetTime = millis() + 1000;
}

void loop() {
if (targetTime < millis()) {
targetTime = millis()+1000;
ss++; // Advance second
if (ss==60) {
ss=0;
omm = mm;
mm++; // Advance minute
if(mm>59) {
mm=0;
hh++; // Advance hour
if (hh>23) {
hh=0;
}
}
}

if (ss==0 || initial) {
initial = 0;
epaper.setTextColor(TFT_GREEN, TFT_BLACK);
epaper.setCursor (8, 52);
epaper.print(__DATE__); // This uses the standard ADAFruit small font

epaper.setTextColor(TFT_BLUE, TFT_BLACK);
epaper.drawCentreString("It is windy",120,48,2); // Next size up font 2

//epaper.setTextColor(0xF81F, TFT_BLACK); // Pink
//epaper.drawCentreString("12.34",80,100,6); // Large font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 . : a p m
}

// Update digital time
byte xpos = 6;
byte ypos = 0;
if (omm != mm) { // Only redraw every minute to minimise flicker
// Uncomment ONE of the next 2 lines, using the ghost image demonstrates text overlay as time is drawn over it
epaper.setTextColor(TFT_BLACK, TFT_BLACK); // Leave a 7 segment ghost image, comment out next line!
//epaper.setTextColor(TFT_BLACK, TFT_BLACK); // Set font colour to black to wipe image
// Font 7 is to show a pseudo 7 segment display.
// Font 7 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : .
epaper.drawString("88:88",xpos,ypos,7); // Overwrite the text to clear it
epaper.setTextColor(0xFBE0); // Orange
omm = mm;

if (hh<10) xpos+= epaper.drawChar('0',xpos,ypos,7);
xpos+= epaper.drawNumber(hh,xpos,ypos,7);
xcolon=xpos;
xpos+= epaper.drawChar(':',xpos,ypos,7);
if (mm<10) xpos+= epaper.drawChar('0',xpos,ypos,7);
epaper.drawNumber(mm,xpos,ypos,7);
}

if (ss%2) { // Flash the colon
epaper.setTextColor(TFT_BLACK, TFT_BLACK);
xpos+= epaper.drawChar(':',xcolon,ypos,7);
epaper.setTextColor(0xFBE0, TFT_BLACK);
}
else {
epaper.drawChar(':',xcolon,ypos,7);
colour = random(0xFFFF);
// Erase the old text with a rectangle, the disadvantage of this method is increased display flicker
epaper.fillRect (0, 64, 160, 20, TFT_BLACK);
epaper.setTextColor(TFT_WHITE);
}
epaper.update(); // update the display
}
}



46 changes: 46 additions & 0 deletions examples/ePaper/Basic/Shape/Shape.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "TFT_eSPI.h"

EPaper epaper;
void setup()
{

epaper.begin();
epaper.fillScreen(TFT_WHITE);
epaper.update(); // update the display

for (int i = 0; i < epaper.height() / 80; i++)
{
epaper.setTextSize(i + 1);
epaper.drawString("Hello ePaper", 10, 80 + 60 * i);
epaper.update(); // update the display
}

// random rectangles
for (int i = 0; i < 10; i++)
{
epaper.fillRect(random(epaper.width()), random(epaper.height()), random(30), random(30), TFT_BLACK);
epaper.update(); // update the display
}

// random circles
for (int i = 0; i < 10; i++)
{
epaper.fillCircle(random(epaper.width()), random(epaper.height()), random(30), TFT_BLACK);
epaper.update(); // update the display
}

delay(2000);

for (int i = 0; i < epaper.width() / 80; i++)
{
// automatically wakes up, but you need to sleep again after drawing
epaper.fillRect(10 + 80 * i, 10, 40, 40, TFT_BLACK);
epaper.update();
}

}

void loop()
{
// put your main code here, to run repeatedly:
}
Loading

0 comments on commit 9c9b619

Please sign in to comment.