M5GFX icon indicating copy to clipboard operation
M5GFX copied to clipboard

How to use a button

Open Grandpa-G opened this issue 5 months ago • 6 comments

I am missing something. I am using the M5GFX button to create buttons. How do I know when it has been touched (CoreS2)? If I check isPressed, it is always false.

At the beginning, I have it defined

`#include <M5GFX.h>

M5GFX display;

LGFX_Button startBtn; `

startBtn.initButton(&display, 150, 122, 150, 150, TFT_RED, TFT_GREEN, TFT_BLACK, "START", 4, 4); startBtn.drawButton(); This is in my setup.

In my loop if (startBtn.justPressed()) { Serial.println("GET data"); collecting = true; } if (startBtn.isPressed()) { Serial.println("GET data pressed"); collecting = true; }

How do I get the start button to be recognized when it is touched?

Grandpa-G avatar Jul 06 '25 20:07 Grandpa-G

You can refer to the example in Tab5 of this page.https://docs.m5stack.com/en/arduino/m5tab5/touch

huamiaoXY avatar Jul 07 '25 02:07 huamiaoXY

The url goes to an empty page.

Grandpa-G avatar Jul 07 '25 02:07 Grandpa-G

The url goes to an empty page.

Please copy the website address and paste it to view.

huamiaoXY avatar Jul 07 '25 02:07 huamiaoXY

That showed an example. I will see if that works.

Grandpa-G avatar Jul 07 '25 02:07 Grandpa-G

That worked (very slow to compile) so I will try to work it into what I had.

Grandpa-G avatar Jul 07 '25 02:07 Grandpa-G

Hello, @Grandpa-G This just draws a button image. It expects the pressed state of the button to be set by user code via the press method. This function does not automatically get the touch state.

lovyan03 avatar Jul 07 '25 02:07 lovyan03