2019-02-27 12:26:36 +08:00
|
|
|
# System
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
## begin()
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
**Syntax:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2020-11-05 11:39:06 +08:00
|
|
|
`void begin(bool LCDEnable=true, bool SDEnable=true, bool SerialEnable=true,bool I2CEnable=false);`
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
**Description:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-03-04 23:22:39 +09:00
|
|
|
This function sets enable/disable LCD, TF Card,Serial port and I2C port.
|
2019-02-27 12:26:36 +08:00
|
|
|
|
|
|
|
|
**Definition:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2021-02-26 17:27:20 +08:00
|
|
|
```clike
|
2019-03-04 23:22:39 +09:00
|
|
|
void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable,bool I2CEnable) {
|
|
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
// Correct init once
|
|
|
|
|
if (isInited) return;
|
|
|
|
|
else isInited = true;
|
2019-03-04 23:22:39 +09:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
// UART
|
|
|
|
|
if (SerialEnable) {
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
Serial.flush();
|
|
|
|
|
delay(50);
|
|
|
|
|
Serial.print("M5Stack initializing...");
|
|
|
|
|
}
|
2019-03-04 23:22:39 +09:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
// LCD INIT
|
|
|
|
|
if (LCDEnable) {
|
|
|
|
|
Lcd.begin();
|
|
|
|
|
}
|
2019-03-04 23:22:39 +09:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
// TF Card
|
|
|
|
|
if (SDEnable) {
|
|
|
|
|
SD.begin(TFCARD_CS_PIN, SPI, 40000000);
|
|
|
|
|
}
|
2019-03-04 23:22:39 +09:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
// TONE
|
|
|
|
|
// Speaker.begin();
|
2019-03-04 23:22:39 +09:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
// Set wakeup button
|
|
|
|
|
Power.setWakeupButton(BUTTON_A_PIN);
|
2019-03-04 23:22:39 +09:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
// I2C init
|
|
|
|
|
if(I2CEnable)
|
|
|
|
|
{
|
|
|
|
|
Wire.begin(21, 22);
|
|
|
|
|
}
|
2019-03-04 23:22:39 +09:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
if (SerialEnable) {
|
|
|
|
|
Serial.println("OK");
|
|
|
|
|
}
|
2019-02-27 11:57:45 +08:00
|
|
|
}
|
|
|
|
|
|
2019-03-04 23:22:39 +09:00
|
|
|
void M5Stack::update() {
|
2019-02-27 12:26:36 +08:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
//Button update
|
|
|
|
|
BtnA.read();
|
|
|
|
|
BtnB.read();
|
|
|
|
|
BtnC.read();
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
//Speaker update
|
|
|
|
|
Speaker.update();
|
2019-02-27 11:57:45 +08:00
|
|
|
}
|
2019-03-04 23:22:39 +09:00
|
|
|
|
2019-02-27 11:57:45 +08:00
|
|
|
```
|
|
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
## update()
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
**Syntax:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2020-11-05 11:39:06 +08:00
|
|
|
`void update();`
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
**Description:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
This function reads The State of Button A and B and C.
|
|
|
|
|
|
|
|
|
|
**Definition:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2021-02-26 17:27:20 +08:00
|
|
|
```clike
|
2019-02-27 11:57:45 +08:00
|
|
|
void M5Stack::update() {
|
|
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
//Button update
|
|
|
|
|
BtnA.read();
|
|
|
|
|
BtnB.read();
|
|
|
|
|
BtnC.read();
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
//Speaker update
|
|
|
|
|
Speaker.update();
|
2019-02-27 11:57:45 +08:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2019-02-28 15:56:00 +08:00
|
|
|
**Example:**
|
2019-02-27 12:26:36 +08:00
|
|
|
|
2021-02-26 17:27:20 +08:00
|
|
|
```clike
|
2019-02-27 11:57:45 +08:00
|
|
|
#include <M5Stack.h>
|
|
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
void setup() {
|
|
|
|
|
M5.begin();
|
2019-02-27 11:57:45 +08:00
|
|
|
}
|
|
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
void loop() {
|
|
|
|
|
M5.update();
|
2019-02-27 11:57:45 +08:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
## powerOFF()
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-03-30 11:21:24 +08:00
|
|
|
!> Deprecated: Please use Power::deepSleep()
|
|
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
**Syntax:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2020-11-05 11:39:06 +08:00
|
|
|
`void powerOFF();`
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
**Description:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
This function turns off the power of M5.
|
|
|
|
|
|
|
|
|
|
**Definition:**
|
2019-02-27 11:57:45 +08:00
|
|
|
|
2021-02-26 17:27:20 +08:00
|
|
|
```clike
|
2019-02-27 11:57:45 +08:00
|
|
|
void M5Stack::powerOFF() {
|
2019-03-30 11:21:24 +08:00
|
|
|
M5.Power.deepSleep();
|
2019-02-27 11:57:45 +08:00
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2019-02-28 15:56:00 +08:00
|
|
|
**Example:**
|
2019-02-27 12:26:36 +08:00
|
|
|
|
2021-02-26 17:27:20 +08:00
|
|
|
```clike
|
2019-02-27 11:57:45 +08:00
|
|
|
#include <M5Stack.h>
|
|
|
|
|
|
2019-02-27 12:26:36 +08:00
|
|
|
void setup() {
|
2019-02-27 11:57:45 +08:00
|
|
|
M5.begin();
|
|
|
|
|
M5.Lcd.println("This is software power off demo");
|
|
|
|
|
M5.Lcd.println("Press the button A to power off.");
|
|
|
|
|
M5.setWakeupButton(BUTTON_A_PIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void loop() {
|
2019-02-27 12:26:36 +08:00
|
|
|
M5.update();
|
|
|
|
|
if (M5.BtnA.wasPressed()) {
|
2019-02-27 11:57:45 +08:00
|
|
|
M5.powerOFF();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|