serial monitor compared to M5.Lcd.print



  • I have been struggling a little trying to get the lcd to print in similar ways to a Serial.print. For example, I was trying to simply show a 1 or 0 based on wasPressed()
    [CODE]
    #include <M5Stack.h>
    // the setup routine runs once when M5Stack starts up
    void setup() {
    Serial.begin(115200);
    // initialize the M5Stack object
    M5.begin();
    M5.Lcd.drawBitmap(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
    delay(500);
    M5.Lcd.fillScreen(BLACK);
    delay(500);
    delay(1000);
    }
    void loop(){

    bool ButtonState = (M5.BtnC.isPressed());
    M5.Lcd.setCursor(20, 20);
    M5.Lcd.print(ButtonState);//why does it only show first value and never updates
    Serial.print(ButtonState);
    M5.update();
    }
    [/CODE]
    In the serial monitor it updates as expected but on the M5 it only ever shows a 0. Why is that? I've seen in other examples there is a fillRect() function as shown below
    [CODE]
    #include <M5Stack.h>

    int T = 0;

    void setup() {
    m5.begin();
    // pinMode(servoPin, OUTPUT);
    M5.Lcd.setBrightness(200);
    M5.Lcd.setCursor(250, 215);
    M5.Lcd.printf("T");
    }

    void loop() {
    if (M5.BtnC.wasPressed())
    {
    T++;
    M5.Lcd.fillRect(180, 50, 70, 42, 0x00);
    M5.Lcd.setTextColor(0xfbe4);
    M5.Lcd.setTextSize(6);
    M5.Lcd.setCursor(180, 50);
    M5.Lcd.print(T);
    }
    m5.update();
    }
    [/CODE]
    Is M5.Lcd.fillRect() what enanbles the Lcd.print() to update. Is there a basic tutorial on using buttons to change Lcd.print() values.
    By the way the M5 is really a great device.



  • @jpilarski Hi, i agree the M5Stack is indeed a really great device !

    Regarding your query, you can review a list of command functions here: https://github.com/Kongduino/M5CheatSheet

    Also you can review the code from this excellent working menu system by Tom Such that uses the buttons for selection: https://github.com/tomsuch/M5Stack-SAM

    He also created a template program for making your own menu:
    https://github.com/tomsuch/M5StackSAM