I'm working on an Arduino project using an M5Stack Core2 AWS with an LCD display.
I can get the lower 3 pre-programmed buttons to work OK.
-
However for my project I need to occasionally add 2 more buttons on the screen (loaded on the bottom). Before I draw the buttons on the screen, the Text that I write is OK. Once I add the screen buttons, the text gets all screwed up. Changed to a VERY LARGE font and messes up badly and I can't seem to reset it to the correct size.
-
The other problem that I'm working to try to resolve is that when I'm writing text on the screen (For now, I'm using the top 2 lines, 16 Characters, TextSize=3. The problem is that every display update (I'm using M5.Lcd.clear()) the screen flickers. If I don't use the clear() screen, then the characters that are being overwritten end up OVERWRITING the previous values and not clearing the contents, so the characters OVERLAP each other as they change. The clear() also hides the screen buttons that I created.
I've been working with this for a long time and I can't find any examples that help either situation.
#include <M5Core2.h>
ButtonColors on_clrs = { RED, WHITE, WHITE };
ButtonColors off_clrs = { BLACK, WHITE, WHITE };
Button BtnL(10, 190, 60, 40, false, "", off_clrs, on_clrs, TL_DATUM); //Left
Button BtnR(250, 190, 60, 40, false, "", off_clrs, on_clrs, TL_DATUM); //Right
void setup() {
Serial.begin(115200);
M5.begin();
//Make sure the buttons are erased:
BtnL.erase(BLACK);
BtnR.erase(BLACK);
//Setup the Text on the screen.
M5.Lcd.setTextColor(YELLOW); // Set the font color to white.
M5.Lcd.setTextSize(3); // Set the font size (Large for now!).
M5.Lcd.clear();
M5.Lcd.display();
M5.Lcd.setCursor(0, 0); //(X,Y) where X is Horizontal and Y is Vertical
M5.Lcd.print(" 10 Second Loop. ");
M5.Lcd.setCursor(0, 35);
M5.Lcd.print(" TESTING");
delay(1500);
M5.Lcd.print(" ");
}
void loop() {
LcdPrint();
delay(5000); //Allow the screen to display, showing that it works.
//Create the two buttons.
Serial.println("Create...");
BtnL.setLabel("DEC");
BtnR.setLabel("INC");
M5.Buttons.draw();
//Loop and detect the buttons
unsigned long Timeit = millis();
do {
LcdPrint(); //Reprint the screen 1. To show the FONT Error 2. Show the Overwritten text (if I can fix Error #1)
M5.update();
if (BtnL.wasReleased()) Serial.print(" dec ");
if (BtnR.wasReleased()) Serial.print(" inc ");
delay(100);
} while (millis() < (Timeit + 10000));
//Erase the buttons...
Serial.println("");
Serial.println("ERASE...");
BtnL.erase(BLACK);
BtnR.erase(BLACK);
//Reprint the screen without the screen buttons.
LcdPrint();
delay(10000);
}
void LcdPrint() {
static int Count;
Count++;
String sCount = "Loop" + String(Count);
Serial.println(sCount);
M5.Lcd.clear(); // with this commented out, the Screen buttons don't erase!
//M5.Lcd.display();
M5.Lcd.setTextColor(RED); // Set the font color to white.
M5.Lcd.setTextSize(3); // Set the font size (Large for now!).
M5.Lcd.setCursor(0, 0);
M5.Lcd.print(" 10 First Loop. ");
M5.Lcd.setCursor(5, 35);
M5.Lcd.print(sCount);
}
I'm obviously missing something here, and I'd sure appreciate some help with this.
I tried to convert this to M5Unified.h but again, I can't find any examples of how to create the screen buttons.
Sir Michael