Hello this is my first post on the forum. I've been pouring over other threads and youtube for an answer to no avail. Hopefully it's a pretty simple answer. Maybe @ZinggJM or someone else can help me.
context:
I'm building a small low-power module with a waveshare 2.13" (250x122) monochrome display that has the SSD1680 driver chip. It is connected to an Adafruit eInk Feather Friend, which is soldered onto an Adafruit Feather 328P. I chose this hardware because of it's very compact length x width size, and because I originally thought I'd be using the Adafruit ThinkInk library. That was until I discovered that their library doesn't support partial updates for this 2.13" display
, so I'm now using ZinggJM's GxEPD2 library.
The Hardware seems to work just fine using GxEPD2 library once I got my pin mapping sorted out.
I am an Industrial Designer by training and experience. I am pretty handy with electronics and self taught when it comes to programing. No computer science degree here FYI. I'm pretty good at implementing methods from libraries as long as I have a good explanation on what they do.
Issue:
So... My issue now is that while my paged display code and use of setPartialWindow() appear to be working just fine, the use of setPartialWindow() seems to create a pause in the program execution while the screen is refreshing. As such, reading my button pins is super delayed. I have to press and hold the buttons down, and depending on the timing, it will print to serial monitor which button is pressed. Somtimes it will print right away if I pressed the button just as the screen refresh was finishing. If not, the print to serial monitor will be delayed for 1 to 2 full seconds before I see it.
What I need:
What I need is for the buttons to be quickly responsive so I can write code for them to guide the user through a rudimentary GUI interface that I will be building.
My own speculation:
Is there something I'm missing here about setPartialWindow()? Is there some way to have it not bog down the rest of the program? I can imagine there might be some way to put the screen to sleep, or maybe change the rate of screen updating? Like just once per second. Even then waiting a full second for my button pressing to respond will be super annoying for the user.
I've tried fiddling around with hybernate(), or powerOff. But I can not get it to have the affect I want. Just ends up flickering the display. Maybe I'm inserting it in the wrong place?
Anyway, I'll stop speculating and wait for a response.
Thank you all in advance!
#include <Adafruit_GFX.h> // Core graphics library
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#if defined(__AVR)
#define MAX_DISPLAY_BUFFER_SIZE 800
#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
GxEPD2_BW<GxEPD2_213_B74, MAX_HEIGHT(GxEPD2_213_B74)> display(GxEPD2_213_B74(/*CS=*/ 9, /*DC=*/ 10, /*RST=8*/ -1, /*BUSY=7*/ -1)); // GDEM0213B74 122x250, SSD1680
#endif
#define upButton 3
#define downButton 2
#define checkButton A1
#define infoButton A0
void evenSlotTiming();//function that updates the
long vTime = 60000;//vTime starts at a value of 1 minute in milliseconds
void setup() {
display.init(115200); // default 10ms reset pulse, e.g. for bare panels with DESPI-C02
Serial.begin(9600);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b);
display.setRotation(3);
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(checkButton, INPUT_PULLUP);
pinMode(infoButton, INPUT_PULLUP);
display.setFullWindow();
display.firstPage();//This sets up the screen for the non-changing/updating graphics
do{
display.fillScreen(GxEPD_WHITE);
display.setCursor(20,30);
display.println("Next event in ");
}while(display.nextPage());
}//END SETUP
void loop() {
eventSlotTiming();//function that adds another hour to vTime each time it's run down to zero
int timeRemain = (vTime-millis())/1000;//as millis increases, this takes the difference between millis and vTime and converts it to seconds
display.setPartialWindow(165,15,80,20);
display.firstPage();
do{
display.fillScreen(GxEPD_WHITE);
display.drawRect(165,15,80,20,GxEPD_BLACK);
display.setCursor(175,30);
display.print(timeRemain);
display.setCursor (200,30);
display.print("sec");
}while(display.nextPage());
if(digitalRead(upButton)==LOW){
Serial.println("upButton is pressed");
}
if(digitalRead(downButton)==LOW){
Serial.println("downButton is pressed");
}
if(digitalRead(checkButton)==LOW){
Serial.println("checkButton is pressed");
}
if(digitalRead(infoButton)==LOW){
Serial.println("infoButton is pressed");
}
}//END LOOP
void eventSlotTiming(){
if(millis() >= vTime){
vTime = millis() + 60000;//Every minute, this resets vTime variable to one minute into the future
}
}
