System

Class names: M5

begin()

Function:

Initialize LCD; Initialize SD card; Clear serial buffer, set serial baud rate to 115200; Initialize I2C; Set MBus mode; Initialize Axp power management chip; Initialize touch screen function; Initialize RTC

Syntax:

void begin(bool LCDEnable = true, bool SDEnable = true, bool SerialEnable = true, bool I2CEnable = false, mbus_mode_t mode = kMBusModeOutput)

Definition:

void M5Core2::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, bool I2CEnable, mbus_mode_t mode) {
  // Correct init once
  if (isInited == true) {
    return;
  } else {
    isInited = true;
  }

  // UART
  if (SerialEnable == true) {
    Serial.begin(115200);
    Serial.flush();
    delay(50);
    Serial.print("M5Core2 initializing...");
  }

  // I2C init
  if (I2CEnable == true) {
    Wire.begin(32, 33);
  }

  Axp.begin(mode);

  // LCD INIT
  if (LCDEnable == true) {
    Lcd.begin();
  }

  // Touch init
  Touch.begin();  // Touch begin after AXP begin. (Reset at the start of AXP)

  // TF Card
  if (SDEnable == true) {
    SD.begin(TFCARD_CS_PIN, SPI, 40000000);
  }

  // TONE
  if (SerialEnable == true) {
    Serial.println("OK");
  }

  Rtc.begin();
}

Definition:

#include <M5Core2.h>

void setup() {
  M5.begin();
}

update()

Function:

Read the status of the keys

Syntax:

void update()

Definition:

void M5Core2::update() {
  Touch.update();
  Buttons.update();
  yield();
}

Example:

#include <M5Core2.h>

void setup() {
  M5.begin();
}

void loop() {
  M5.update();
}

shutdown()

Function 1:

To turn off the power and start it again, you need to wake up with the PWR button

void shutdown()

Function 2:

Turn off the power, and according to the number of seconds of delay passed in, wake up the device through RTC after the delay is over

int shutdown( int seconds )

Function 3:

Turn off the power, pass in the RTC time structure with a specified time point, and wake up the device through RTC when it meets the hrs, minutes, and seconds of that time.

int shutdown( const RTC_TimeTypeDef &RTC_TimeStruct)

Function 4:

Turn off the power, pass in the RTC time structure specified for a certain point in time, and wake up the device by RTC when the week, day, and time of that point in time match at the same time. int shutdown( const RTC_DateTypeDef &RTC_DateStruct, const RTC_TimeTypeDef &RTC_TimeStruct);

int shutdown( const RTC_DateTypeDef &RTC_DateStruct, const RTC_TimeTypeDef &RTC_TimeStruct)

Example:

#include <M5Core2.h>

RTC_TimeTypeDef RTCtime;
RTC_TimeTypeDef RTCtime_Now;

char timeStrbuff[64];

void setup(){
  M5.begin(true,true,true,true);

  RTCtime.Hours = 10;
  RTCtime.Minutes = 30;
  RTCtime.Seconds = 45;

  M5.Lcd.setCursor(0,80);
  M5.Lcd.println("");
  M5.Lcd.println("BtnA:  shutdown, use power button to turn back on");
  M5.Lcd.println("");
  M5.Lcd.println("BtnB:  shutdown, wake up after 5 seconds");
  M5.Lcd.println("");
  M5.Lcd.println("BtnC:  shutdown, wake up at RTC Time 10:30:45");
}

void loop(){
  M5.update();
  if(M5.BtnA.wasPressed()){
    M5.shutdown();
  }else if(M5.BtnB.wasPressed()){
    M5.shutdown(5);
  }else if(M5.BtnC.wasPressed()){
    M5.shutdown(RTCtime);
  }

  M5.Lcd.setCursor(0,140);
  M5.Rtc.GetTime(&RTCtime_Now);
  sprintf(timeStrbuff,"RTC Time Now is %02d:%02d:%02d",
         RTCtime_Now.Hours,RTCtime_Now.Minutes,RTCtime_Now.Seconds);
  M5.Lcd.println(timeStrbuff);

}
On This Page