pdf-icon

System Functions

Class Name: 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 function; initialize RTC.

Syntax:

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

Function Implementation:

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();
}

Example:

#include <M5Core2.h>

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

update()

Function:

Read the state of the buttons.

Syntax:

void update()

Function Implementation:

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

Example:

#include <M5Core2.h>

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

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

shutdown()

Overload 1:

Turn off the power, wake up again using the PWR button.

void shutdown()

Overload 2:

Turn off the power, wake up after the specified number of seconds using RTC.

int shutdown( int seconds )

Overload 3:

Turn off the power, wake up at the specified time using RTC.

int shutdown( const RTC_TimeTypeDef &RTC_TimeStruct)

Overload 4:

Turn off the power, wake up at the specified time and date using RTC.

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