Created
January 5, 2020 20:50
-
-
Save juanpabloaj/3212fb859749c3b456cc6fd86e5741f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mapping suggestion for ESP32, e.g. LOLIN32 D32 PRO | |
// BUSY -> 15 | |
// RST -> 2 | |
// DC -> 0 | |
// CS -> 5 | |
// CLK -> SCK(18) | |
// DIN -> MOSI(23) | |
// GND -> GND | |
// 3.3V -> 3.3V | |
// note: use explicit value for CS | |
//as SS is re-defined to TF_CS(4) in pins_arduino.h for Board: "LOLIN D32 PRO" | |
#define ENABLE_GxEPD2_GFX 0 | |
#include <GxEPD2_BW.h> | |
#include <GxEPD2_3C.h> | |
#include <Fonts/FreeMonoBold9pt7b.h> | |
//GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ 5, /*DC=*/ 0, /*RST=*/ 2, /*BUSY=*/ 15)); | |
// mapping suggestion for ESP32, e.g. TTGO T8 ESP32-WROVER | |
// BUSY -> 4, RST -> 0, DC -> 2, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V | |
// for use with Board: "ESP32 Dev Module": | |
GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ 5, /*DC=*/ 2, /*RST=*/ 0, /*BUSY=*/ 4)); | |
#define BUILTIN_LED 21 | |
void setup() { | |
pinMode(BUILTIN_LED, OUTPUT); | |
Serial.begin(115200); | |
Serial.println(); | |
Serial.println("setup"); | |
delay(100); | |
display.init(115200); | |
delay(1000); | |
helloWorld(); | |
delay(5000); | |
} | |
void loop() { | |
Serial.println("loop ..."); | |
blackScreen(); | |
digitalWrite(BUILTIN_LED, HIGH); | |
delay(5000); | |
helloWorld(); | |
digitalWrite(BUILTIN_LED, LOW); | |
delay(5000); | |
} | |
const char HelloWorld[] = "Hello World!"; | |
const char HelloArduino[] = "Hello Arduino!"; | |
const char HelloEpaper[] = "Hello E-Paper!"; | |
void helloWorld() | |
{ | |
Serial.println("helloWorld"); | |
display.setRotation(1); | |
display.setFont(&FreeMonoBold9pt7b); | |
display.setTextColor(GxEPD_BLACK); | |
int16_t tbx, tby; uint16_t tbw, tbh; | |
display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh); | |
// center bounding box by transposition of origin: | |
uint16_t x = ((display.width() - tbw) / 2) - tbx; | |
uint16_t y = ((display.height() - tbh) / 2) - tby; | |
display.setFullWindow(); | |
display.firstPage(); | |
do | |
{ | |
display.fillScreen(GxEPD_WHITE); | |
display.setCursor(x, y); | |
display.print(HelloWorld); | |
display.setCursor(0,0); | |
display.print(HelloEpaper); | |
} | |
while (display.nextPage()); | |
Serial.println("helloWorld done"); | |
} | |
void blackScreen() { | |
display.firstPage(); | |
do | |
{ | |
display.fillScreen(GxEPD_BLACK); | |
} | |
while (display.nextPage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment