Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MH-ET LIVE 1.54-inches E-Paper demo
#include <GxEPD.h>
#include <GxGDEP015OC1/GxGDEP015OC1.cpp>
#include <Fonts/OpenSansBold12pt7b.h>
#include <Fonts/OpenSansBold14pt7b.h>
#include <Fonts/OpenSansBold30pt7b.h>
#include <GxIO/GxIO_SPI/GxIO_SPI.cpp>
#include <GxIO/GxIO.cpp>
#include GxEPD_BitmapExamples
#include "qrcode.h"
GxIO_Class io(SPI, /*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2); // arbitrary selection of D3(=0), D4(=2), selected for default of GxEPD_Class
GxEPD_Class display(io /*RST=D4*/ /*BUSY=D2*/); // default selection of D4(=2), D2(=4)
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Display setup...");
display.init(115200); // enable diagnostic output on Serial
display.setRotation(0);
display.update();
Serial.println("Done");
pinMode(D0, WAKEUP_PULLUP);
}
void loop() {
weatherDemo();
drawPicture();
qrCard();
// Use this line if you need to save energy (e.g. battery application)
int seconds = 10;
ESP.deepSleep(seconds * 1000000);
}
void weatherDemo(){
float temp = 16.4;
int hum = 54;
float pres = 1010.5;
uint16_t line_y = 0;
uint16_t line_x = 0;
display.setTextColor(GxEPD_BLACK);
line_y = 50;
display.drawLine(0, line_y, 200, line_y, GxEPD_BLACK);
line_y = 135;
display.drawLine(0, line_y, 200, line_y, GxEPD_BLACK);
line_x = 100;
display.drawLine(line_x, 135, line_x, 200, GxEPD_BLACK);
display.setFont(&OpenSansBold12pt7b);
display.setCursor(10, 35);
display.print("clear sky");
display.setFont(&OpenSansBold14pt7b);
display.setCursor(155, 90);
display.print("C");
display.setCursor(173, 83);
display.print("o");
display.setFont(&OpenSansBold30pt7b);
display.setCursor(15, 115);
display.print(temp,1);
display.setFont(&OpenSansBold12pt7b);
display.setCursor(10, 160);
display.print("%");
display.setFont(&OpenSansBold14pt7b);
display.setCursor(10, 190);
display.print(hum);
display.setFont(&OpenSansBold12pt7b);
display.setCursor(110, 160);
display.print("hPa");
display.setFont(&OpenSansBold14pt7b);
display.setCursor(110, 190);
display.print(pres,1);
display.update();
delay(2000);
}
void drawPicture(){
display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE);
display.update();
display.drawExampleBitmap(BitmapExample1, 0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_BLACK);
display.update();
delay(2000);
}
void qrCard(){
display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE);
display.update();
// Start time
uint32_t dt = millis();
byte box_x = 1;
byte box_y = 1;
byte box_s = 6;
byte init_x = box_x;
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false);
// Create the QR code
QRCode qrcode;
uint8_t qrcodeData[qrcode_getBufferSize(4)];
qrcode_initText(&qrcode, qrcodeData, 4, 0, "https://www.youtube.com/channel/UCrynPq5AwTTXQr-Hv9_fzMA?sub_confirmation=1");
// Delta time
dt = millis() - dt;
Serial.print("QR Code Generation Time: ");
Serial.print(dt);
Serial.print("\n");
// Top quiet zone
Serial.print("\n\n\n\n");
for (uint8_t y = 0; y < qrcode.size; y++) {
// Left quiet zone
Serial.print(" ");
// Each horizontal module
for (uint8_t x = 0; x < qrcode.size; x++) {
// Print each module (UTF-8 \u2588 is a solid block)
//Serial.print(qrcode_getModule(&qrcode, x, y) ? "\u2588\u2588": " ");
if(qrcode_getModule(&qrcode, x, y)){
Serial.print("\u2588\u2588");
//Serial.println(py+ps);
display.fillRect(box_x, box_y, box_s, box_s, GxEPD_BLACK);
} else {
Serial.print(" ");
//Serial.println(py+ps);
display.fillRect(box_x, box_y, box_s, box_s, GxEPD_WHITE);
}
box_x = box_x + box_s;
}
Serial.print("\n");
display.updateWindow(0, box_y, 200, box_s, true);
box_y = box_y + box_s;
box_x = init_x;
}
//display.update();
// Bottom quiet zone
Serial.print("\n\n\n\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.