I am programming a Waveshare 4.2 inch e-paper display using the epd4in2b_V2 sample as a base. I created a small rectangle to hold a value that I want to update periodically with a temperature. I looked through the .h and .cpp files to find a way to do this without a full screen refresh, but don't see a way. The DisplayFrame routine refreshes the entire display and it takes a long time with something like 10 flashes. I posted a simplified version of my code below. The Update_Count() routine is where I'm trying to update just the rectangle holding a number.
#include <SPI.h>
#include "epd4in2b_V2.h"
#include "imagedata.h"
#include "epdpaint.h"
#define COLORED 0
#define UNCOLORED 1
Epd epd;
unsigned char image[3000]; // how do I calculate what value I need?
Paint paint(image, 400, 24); // width should be the multiple of 8
void setup() {
Serial.begin(9600);
Epd epd;
if (epd.Init() != 0) {
Serial.print("e-Paper initialization failed");
return;
}
epd.ClearFrame(); // This clears the SRAM of the e-paper display
// unsigned char image[3000]; // how do I calculate what value I need?
// Paint paint(image, 400, 24); // width should be the multiple of 8
// Title
paint.SetWidth(400);
paint.SetHeight(24);
paint.Clear(UNCOLORED); // black text in white background
paint.DrawStringAt(50, 0, "This is the title", &Font24, COLORED);
epd.SetPartialWindowBlack(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());
// draw a box to hold a count
paint.SetWidth(41); // width of window
paint.SetHeight(31); // height of window
paint.Clear(UNCOLORED);
paint.DrawRectangle(0, 0, 40, 30, COLORED);
paint.DrawStringAt(10, 10, "T1", &Font16, COLORED);
epd.SetPartialWindowBlack(paint.GetImage(), 200, 80, paint.GetWidth(), paint.GetHeight());
/* This displays the data from the SRAM in e-Paper module */
epd.DisplayFrame(); // show the frame
/* This displays an image */
// epd.DisplayFrame(IMAGE_BLACK, IMAGE_RED);
/* Deep sleep */
epd.Sleep();
}
void Update_count(int ct) { // Add simple count to display
char b[5]; // create a char array
itoa(ct, b, 10); // convert the integer to char for DrawString function
paint.SetWidth(41); // set width of window
paint.SetHeight(31); // set height of window
paint.Clear(UNCOLORED); // clear the window
paint.DrawRectangle(0, 0, 40, 30, COLORED); // draw the rectangle
paint.DrawStringAt(10, 10, b, &Font16, COLORED); // draw the count number in the rectangle
Serial.println("updating display");
epd.SetPartialWindowBlack(paint.GetImage(), 200, 80, paint.GetWidth(), paint.GetHeight()); //where the origin is
epd.DisplayFrame(); // refresh the frame
}
void loop() {
for (int c1 = 0; c1 < 20; c1++) {
Serial.println(c1);
Update_count(c1);
delay(1000);
}