成功截图
一、字体参考链接
https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fonts
二、代码参考链接
https://github.com/ZinggJM/GxEPD
建议使用其中的GxEPD_MinimumExample代码
三、我的时钟代码
GxEPD_MinimumExample.ino更改后的代码,代码很垃圾,大佬轻喷,接线方式请看代码中的标识
// GxEPD_MinimumExample by Jean-Marc Zingg
#include <GxEPD.h>
#include <WiFi.h>
#include "time.h"
// select the display class to use, only one, copy from GxEPD_Example
#include <GxGDE0213B1/GxGDE0213B1.h> // 2.13" b/w
#include <GxGDE0213B1/BitmapExamples.h>
//#include <GxGDEH0213B72/GxGDEH0213B72.h> // 2.13" b/w new panel
//#include <GxGDEH0213B73/GxGDEH0213B73.h> // 2.13" b/w newer panel
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <GxIO/GxIO.h>
#include GxEPD_BitmapExamples
// FreeFonts from Adafruit_GFX
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>
#include <Fonts/FreeSans24pt7b.h>
#include <Fonts/FreeSansBoldOblique24pt7b.h>
#include <Fonts/FreeSerifBoldItalic24pt7b.h>
// constructor for AVR Arduino, copy from GxEPD_Example else
GxIO_Class io(SPI, /*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16); // arbitrary selection of 17, 16
GxEPD_Class display(io, /*RST=*/ 16, /*BUSY=*/ 4); // arbitrary selection of (16), 4
const char* ssid = "Wifi";
const char* password = "*_passwd_*";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 28800;
const int daylightOffset_sec = 0;
void printLocalTime()
{
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
const int& sec = timeinfo.tm_sec;
Serial.println(sec);
Serial.println(&timeinfo, "%A, %Y-%m-%d %H:%M:%S");
}
#include "IMG_0001.h"
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println("setup");
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
//init and get the time
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
printLocalTime();
// one common reset for all displays
pinMode(16, OUTPUT);
digitalWrite(16, LOW);
delay(20);
digitalWrite(16, HIGH);
delay(20);
display.init(115200); // enable diagnostic output on Serial
display.fillScreen(GxEPD_WHITE);
//delay(2000);
//display.fillScreen(GxEPD_WHITE);
Serial.println("showBitmapExample GxEPD_WHITE");
//display.drawBitmap(BitmapExample1, sizeof(BitmapExample1));
// delay(2000);
display.drawExampleBitmap(gImage_cocacola, 20, 0, 85, 240, GxEPD_BLACK);
display.update();
delay(3000);
display.drawExampleBitmap(gImage_dog, 10, 50, 100, 150, GxEPD_BLACK);
display.update();
delay(3000);
//display.update();
//display.eraseDisplay();
// comment out next line to have no or minimal Adafruit_GFX code
//display.drawPaged(drawHelloWorld); // version for AVR using paged drawing, works also on other processors
}
void drawHelloWorld()
{
display.setTextColor(GxEPD_WHITE);
display.print("Hello World!");
}
void loop() {
//delay(1000);
showBitmapExample();
//delay(2000);
#if !defined(__AVR)
//drawCornerTest();
//showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
// showFont("FreeMonoBold12pt7b", &FreeMonoBold12pt7b);
//showFont("FreeMonoBold18pt7b", &FreeMonoBold18pt7b);
//showFont("FreeMonoBold24pt7b", &FreeMonoBold24pt7b);
#else
//display.drawCornerTest();
//delay(2000);
//display.drawPaged(showFontCallback);
#endif
//delay(10000);
};
#if defined(_GxGDE0213B1_H_)
void showBitmapExample()
{
Serial.println("drawBitmap");
//display.drawBitmap(BitmapExample1, sizeof(BitmapExample1));
//delay(2000);
//display.drawBitmap(BitmapExample2, sizeof(BitmapExample2));
//delay(5000);
#if !defined(__AVR)
// Serial.println("__AVR");
// display.drawBitmap(first, sizeof(first));
// delay(5000);
// display.drawBitmap(second, sizeof(second));
// delay(5000);
// display.drawBitmap(third, sizeof(third));
// delay(5000);
#endif
Serial.println("showBitmapExample GxEPD_WHITE");
// display.drawBitmap(BitmapExample1, sizeof(BitmapExample1));
// delay(2000);
// display.update();
//display.fillScreen(GxEPD_WHITE);
//display.update();
// display.drawExampleBitmap(BitmapExample1, 0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_BLACK);
//display.drawExampleBitmap(gImage_dog, x, y, 100, 200, GxEPD_BLACK);
//display.update();
Serial.println("updateEnd");
//delay(2000);
Serial.println("showBoat");
showBoat();
}
#endif
void showFont(const char name[], const GFXfont* f)
{
Serial.println("showFont GxEPD_WHITE");
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(f);
display.setCursor(0, 0);
display.println();
display.println(name);
display.println(" !\"#$%&'()*+,-./");
display.println("0123456789:;<=>?");
display.println("@ABCDEFGHIJKLMNO");
display.println("PQRSTUVWXYZ[\\]^_");
#if defined(HAS_RED_COLOR)
display.setTextColor(GxEPD_RED);
#endif
display.println("`abcdefghijklmno");
display.println("pqrstuvwxyz{|}~ ");
Serial.println("showFont update");
display.update();
delay(5000);
}
void showFontCallback()
{
const char* name = "FreeMonoBold9pt7b";
const GFXfont* f = &FreeMonoBold9pt7b;
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(f);
display.setCursor(0, 0);
display.println();
display.println(name);
display.println(" !\"#$%&'()*+,-./");
display.println("0123456789:;<=>?");
display.println("@ABCDEFGHIJKLMNO");
display.println("PQRSTUVWXYZ[\\]^_");
#if defined(HAS_RED_COLOR)
display.setTextColor(GxEPD_RED);
#endif
display.println("`abcdefghijklmno");
display.println("pqrstuvwxyz{|}~ ");
}
void drawCornerTest()
{
Serial.println("drawCornerTest Start");
display.drawCornerTest();
delay(5000);
uint8_t rotation = display.getRotation();
for (uint16_t r = 0; r < 4; r++)
{
display.setRotation(r);
display.fillScreen(GxEPD_WHITE);
display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
display.update();
delay(5000);
}
Serial.println("drawCornerTest ForEnd");
display.setRotation(rotation); // restore
}
#if defined(_GxGDEP015OC1_H_) || defined(_GxGDEH0154D67_H_) || defined(_GxGDE0213B1_H_) || defined(_GxGDEH0213B72_H_) || defined(_GxGDEH0213B73_H_)|| defined(_GxGDEH029A1_H_)
#include "IMG_0001.h"
void showBoat()
{
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
Serial.println("Failed to obtain time");
return;
}
const int& y = timeinfo.tm_year + 1900;
const int& m = timeinfo.tm_mon + 1;
const int& d = timeinfo.tm_mday;
const int& ho = timeinfo.tm_hour;
const int& mi = timeinfo.tm_min;
const int& se = timeinfo.tm_sec;
const int& w = timeinfo.tm_wday;
char wa[7][20]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
char wb[7][20]={"天","一","二","三","四","五","六"};
cha