44 */
55#include < M5Unified.h>
66#include < gob_unifiedButton.hpp>
7+ #include " esp_random.h"
78
89goblib::UnifiedButton unifiedButton; // gob_unifiedButton instance
910
1011void setup ()
1112{
1213 M5.begin ();
13- unifiedButton.begin (&M5.Display , goblib::UnifiedButton:: appearance_t ::custom );
14+ unifiedButton.begin (&M5.Display );
1415 M5.Display .clear (TFT_DARKGREEN);
1516
1617 // Customize buttons
@@ -32,33 +33,42 @@ void setup()
3233 btnC->initButtonUL (unifiedButton.gfx (),
3334 M5.Display .width ()/2 , M5.Display .height ()/4 , M5.Display .width ()/2 , M5.Display .height ()*3 /4 ,
3435 TFT_CYAN, TFT_MAGENTA, TFT_RED, " CCC" , 3 .0f , 3 .0f );
35-
3636}
3737
3838void loop ()
3939{
40+ bool force{};
41+
4042 M5.update ();
4143 unifiedButton.update ();
4244
43- // Core/Core2/CoreS3 Can work with common code.
44- if (M5. BtnA . wasHold ())
45- {
46- M5_LOGI ( " A button was hold " ) ;
47- }
48- else if (M5. BtnA . wasClicked () )
45+ auto btnA = unifiedButton. getButtonA ();
46+ auto btnB = unifiedButton. getButtonB ();
47+
48+ static bool pa{} ;
49+ bool ba = M5. BtnA . isPressed ();
50+ if (pa != ba )
4951 {
50- M5_LOGI (" A button was clicked" );
52+ M5_LOGI (" A button was changed" );
53+ btnA->setLabelText (M5.BtnA .isPressed () ? " Pressed" : " Released" );
54+ force = true ;
5155 }
56+ pa = ba;
5257
53- if (M5.BtnB .pressedFor ( 1000 ))
58+ if (M5.BtnB .wasClicked ( ))
5459 {
55- M5_LOGI (" B button pressed for 1000 ms" );
60+ M5_LOGI (" B button was clicked" );
61+ uint16_t clr = esp_random () & 0xFFFF ;
62+ btnB->setOutlineColor (clr);
63+ btnB->setFillColor (clr ^ 0xFFFF );
64+ btnB->setTextColor (clr ^ 0xFF00 );
65+ force = true ;
5666 }
5767
5868 if (M5.BtnC .wasReleased ())
5969 {
6070 M5_LOGI (" C button was released" );
6171 }
6272
63- unifiedButton.draw ();
73+ unifiedButton.draw (force /* Force drawing to immediately reflect changes to LGFX_Button if true */ );
6474}
0 commit comments