mirror of
https://github.com/m5stack/m5-docs.git
synced 2026-05-20 10:23:01 -07:00
..
This commit is contained in:
@@ -74,7 +74,7 @@ Select your board name, baudrate, the specified serial port: M5Stack-Core-ESP32,
|
||||
|
||||
<img src="assets/img/getting_started_pics/m5stack_core/get_started_with_arduino_m5core/windows/select_board_baudrate_serial_port.png">
|
||||
|
||||
Then select an example likes `Stick` -> `FactoryTest.ino`
|
||||
<font color="red">Then select an example likes `M5Stack` -> `Stick` -> `FactoryTest.ino`</font>
|
||||
|
||||
<img src="assets/img/getting_started_pics/m5stick/m5stick_arduino_windows_01.png">
|
||||
|
||||
|
||||
+27
-16
@@ -5,24 +5,35 @@
|
||||
|||
|
||||
|:---:|:---:|
|
||||
|**[System](zh_CN/api/system)** | **[喇叭](zh_CN/api/speaker)** |
|
||||
|**[LCD 屏幕](zh_CN/api/lcd)** | **[按键](zh_CN/api/button)** |
|
||||
|**[姿态传感器 (MPU9250)](zh_CN/api/mpu9250)** | **[TF 卡](zh_CN/api/tf)** |
|
||||
|**[LCD 屏](zh_CN/api/lcd)** | **[按键](zh_CN/api/button)** |
|
||||
|**[MPU9250](zh_CN/api/mpu9250)** | **[TF 卡](zh_CN/api/tf)** |
|
||||
|**[Power](zh_CN/api/power)** |
|
||||
|
||||
<!-- ## M5stick
|
||||
<!-- <table>
|
||||
<tr>
|
||||
<th align="center"><a href="#/zh_CN/api/system">System</a></th>
|
||||
<th align="center"><a href="#/zh_CN/api/speaker">喇叭</a></th>
|
||||
<th align="center"><a href="#/zh_CN/api/speaker">LCD 屏幕</a></th>
|
||||
<th align="center"><a href="#/zh_CN/api/speaker">按键</a></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="center"><a href="#/zh_CN/api/system">Power</a></th>
|
||||
<th align="center"><a href="#/zh_CN/api/speaker">TF 卡</a></th>
|
||||
<th align="center"><a href="#/zh_CN/api/speaker">姿态传感器 (MPU9250)</a></th>
|
||||
<th align="center"><a href="#/zh_CN/api/speaker"> </a></th>
|
||||
</tr>
|
||||
</table> -->
|
||||
|
||||
## M5stickC
|
||||
|
||||
<!-- |||
|
||||
|:---:|:---:|
|
||||
|**[System](zh_CN/api/system)** | **[喇叭](zh_CN/api/speaker)** |
|
||||
|**[LCD 屏](zh_CN/api/lcd)** | **[按键](zh_CN/api/button)** |
|
||||
|**[MPU9250](zh_CN/api/mpu9250)** | **[TF 卡](zh_CN/api/tf)** |
|
||||
|**[Power](zh_CN/api/power)** | -->
|
||||
|
||||
|||
|
||||
|:---:|:---:|
|
||||
|**[system](zh_CN/api/system)** | **[Speaker](zh_CN/api/speaker)** |
|
||||
|**[OLED](zh_CN/api/oled)** | **[button](zh_CN/api/button)** |
|
||||
|**[MPU9250](zh_CN/api/mpu9250)** | **[Microphone](zh_CN/api/mic)** | -->
|
||||
|
||||
<!-- |**[Button](zh_CN/api/button)** | **[MPU9250](zh_CN/api/mpu9250)** | -->
|
||||
|
||||
<!-- |[BUTTON](zh_CN/api_reference/micropython/api_lcd) | [BUTTON](zh_CN/api_reference/arduino/api_lcd) |
|
||||
|[SPEAKER](zh_CN/api_reference/micropython/api_lcd) | [SPEAKER](zh_CN/api_reference/arduino/api_lcd) | -->
|
||||
|
||||
<!-- ## [LCD](zh_CN/api_reference/micropython/api_lcd) -->
|
||||
<!-- ## [Peripherals](zh_CN/api_reference/peripherals/api_gpio)
|
||||
### 1. [GPIO](zh_CN/api_reference/peripherals/api_gpio)
|
||||
## [Speaker](zh_CN/api_reference/api_speaker) -->
|
||||
|**[System](zh_CN/api/system_m5stickc)** | **[AXP192](zh_CN/api/axp192_m5stickc)** |
|
||||
|**[TFT 屏](zh_CN/api/lcd_m5stickc)** | **[SH200Q](zh_CN/api/sh200q_m5stickc)** |
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
# TFT 屏幕
|
||||
|
||||
*M5StickC 屏幕像素为 **80x160**,以屏幕左上角为原点 (0,0)*
|
||||
|
||||
## ScreenBreath()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>void ScreenBreath(uint8_t brightness);</mark>
|
||||
|
||||
**功能:调节屏幕背光亮度。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| brightness | 背光值 ( 值: 7 - 16 ) |
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
M5.Lcd.fillScreen(WHITE);
|
||||
|
||||
M5.Axp.ScreenBreath(7);
|
||||
delay(2000);
|
||||
M5.Axp.ScreenBreath(16);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## fillScreen()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>fillScreen(uint16_t color);</mark>
|
||||
|
||||
**功能:以指定的颜色填充整个屏幕。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| color | 颜色值 |
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.fillScreen(WHITE);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## setTextColor()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>setTextColor(uint16_t color, uint16_t backgroundcolor);</mark>
|
||||
|
||||
**功能:设置显示文本的前景颜色和背景颜色。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| color | 文本的前景颜色 |
|
||||
| backgroundcolor| 文本的背景颜色 |
|
||||
|
||||
*如果函数的 backgroundcolor 值没给出,则使用当前的背景颜色。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.setTextColor(RED, WHITE);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## setCursor()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>setCursor(int16_t x0, int16_t y0, uint8_t font);</mark>
|
||||
|
||||
<!-- <mark>setCursor(x0, y0)</mark> # for micropython -->
|
||||
|
||||
**功能:移动光标位置到 (x0, y0) 处。**
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.setCursor(7, 20, 2);
|
||||
M5.Lcd.println("scan done");
|
||||
|
||||
M5.Lcd.setCursor(5, 60, 4);
|
||||
M5.Lcd.printf("50 AP");
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## drawPixel()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>drawPixel(int16_t x, int16_t y, uint16_t color);</mark>
|
||||
|
||||
**功能:在位置(x,y)处画点。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| color | 颜色值 |
|
||||
|
||||
*如果函数的 color 值没给出,则使用当前的背景颜色。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.drawPixel(22,22,RED);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## drawLine()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);</mark>
|
||||
|
||||
**功能:以指定的颜色从点(x,y)到点(x1,y1)画直线。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| color | 颜色值 |
|
||||
|
||||
*如果函数的 color 值没给出,则使用当前的背景颜色。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.drawLine(0,0,12,12,BLUE);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## drawTriangle()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);</mark>
|
||||
|
||||
**功能:以指定颜色画三角形,顶点分别为(x,y),(x1,y1)和(x2,y2)。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| color | 颜色值 |
|
||||
|
||||
*如果函数的 color 值没给出,则使用当前的背景颜色。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.drawTriangle(22,22,69,98,51,22,RED);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## fillTriangle()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);</mark>
|
||||
|
||||
**功能:以指定颜色画<mark>填充形式</mark>的三角形,顶点分别为(x,y),(x1,y1)和(x2,y2)。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| color | 颜色值 |
|
||||
|
||||
*如果函数的 color 值没给出,则使用当前的背景颜色。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.fillTriangle(22,22,69,98,51,22,RED);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## drawRect()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);</mark>
|
||||
|
||||
**功能:以指定颜色画矩形,其中矩形左上角坐标为(x,y),宽高分别为width和height。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| w | 图形宽(单位: 像素) |
|
||||
| h | 图形高(单位: 像素) |
|
||||
| color | 颜色值 |
|
||||
|
||||
*如果函数的 color 值没给出,则使用当前的背景颜色。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.drawRect(50, 100, 30, 10, BLUE);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## fillRect()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);</mark>
|
||||
|
||||
**功能:以指定颜色画<mark>填充形式</mark>的矩形,其左上角坐标为(x,y),宽高分别为width和height。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| w | 图形宽(单位: 像素) |
|
||||
| h | 图形高(单位: 像素) |
|
||||
| color | 颜色值 |
|
||||
|
||||
*如果函数的 color 值没给出,则使用当前的背景颜色。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.fillRect(50, 100, 20, 10, BLUE);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## drawRoundRect()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, int16_t radius, uint16_t color);</mark>
|
||||
|
||||
**功能:以指定颜色画<mark>圆角</mark>矩形,其中矩形左上角坐标为(x,y),宽高分别为width和height,圆角半径为radius。**
|
||||
|
||||
| 参数 | 描述 |
|
||||
| --- | --- |
|
||||
| w | 图形宽(单位: 像素) |
|
||||
| h | 图形高(单位: 像素) |
|
||||
| radius | 圆角半径 |
|
||||
| color | 颜色值 |
|
||||
|
||||
*如果函数的 color 值没给出,则使用当前的背景颜色。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.fillRoundRect(40,70,20,10,4,BLUE);
|
||||
```
|
||||
|
||||
* * *
|
||||
|
||||
## print()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>print();</mark>
|
||||
|
||||
**功能:在屏幕的当前位置开始打印文本(字符串) text。**
|
||||
|
||||
*默认打印的内容颜色样式是黑底白字。*
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.print("print text");
|
||||
```
|
||||
|
||||
## Usage {docsify-ignore}
|
||||
|
||||
```arduino
|
||||
#include <M5StackC.h>
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5.Lcd.fillScreen(WHITE) #set the default background color
|
||||
M5.Lcd.drawLine(0, 0, WHITE);
|
||||
M5.Lcd.drawTriangle(22,22,69,98,51,22,RED);
|
||||
M5.Lcd.fillTriangle(22,22,69,98,51,22,RED);
|
||||
M5.Lcd.drawRect(50, 100, 30, 10, BLUE);
|
||||
M5.Lcd.fillRect(50, 100, 30, 10, BLUE);
|
||||
M5.Lcd.drawRoundRect(40,70,20,10,4,BLUE);
|
||||
M5.Lcd.fillRoundRect(40,70,20,10,4,BLUE);
|
||||
M5.Lcd.print("print text");
|
||||
```
|
||||
@@ -4,154 +4,87 @@
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>void begin(bool LCDEnable=true, bool SDEnable=true, bool SerialEnable=true,bool I2CEnable=false);</mark>
|
||||
<mark>void begin(bool LCDEnable=true, bool PowerEnable=true, bool SerialEnable=true);</mark>
|
||||
|
||||
<!-- <mark>fillScreen(color)</mark> # for micropython -->
|
||||
|
||||
**功能:清串口缓冲区,设置串口波特率为 115200;初始化 LCD;初始化 SD 卡;初始化 I2C;设置按键 A 是睡眠唤醒按键。**
|
||||
**功能:清串口缓冲区,设置串口波特率为 115200;初始化 LCD;初始化电源管理芯片 AXP192。**
|
||||
|
||||
**函数实现**
|
||||
|
||||
```arduino
|
||||
void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable,bool I2CEnable) {
|
||||
void M5StickC::begin(bool LCDEnable, bool PowerEnable, bool SerialEnable){
|
||||
|
||||
// Correct init once
|
||||
if (isInited) return;
|
||||
else isInited = true;
|
||||
//! Correct init once
|
||||
if (isInited) return;
|
||||
else isInited = true;
|
||||
|
||||
// UART
|
||||
if (SerialEnable) {
|
||||
Serial.begin(115200);
|
||||
Serial.flush();
|
||||
delay(50);
|
||||
Serial.print("M5Stack initializing...");
|
||||
}
|
||||
//! UART
|
||||
if (SerialEnable) {
|
||||
Serial.begin(115200);
|
||||
Serial.flush();
|
||||
delay(50);
|
||||
Serial.print("M5StickC initializing...");
|
||||
}
|
||||
|
||||
// LCD INIT
|
||||
if (LCDEnable) {
|
||||
Lcd.begin();
|
||||
}
|
||||
// Power
|
||||
if (PowerEnable) {
|
||||
Axp.begin();
|
||||
}
|
||||
|
||||
// TF Card
|
||||
if (SDEnable) {
|
||||
SD.begin(TFCARD_CS_PIN, SPI, 40000000);
|
||||
}
|
||||
// LCD INIT
|
||||
if (LCDEnable) {
|
||||
Lcd.begin();
|
||||
}
|
||||
|
||||
// TONE
|
||||
// Speaker.begin();
|
||||
|
||||
// Set wakeup button
|
||||
Power.setWakeupButton(BUTTON_A_PIN);
|
||||
|
||||
// I2C init
|
||||
if(I2CEnable)
|
||||
{
|
||||
Wire.begin(21, 22);
|
||||
}
|
||||
|
||||
if (SerialEnable) {
|
||||
Serial.println("OK");
|
||||
}
|
||||
if (SerialEnable) {
|
||||
Serial.println("OK");
|
||||
}
|
||||
}
|
||||
|
||||
void M5Stack::update() {
|
||||
|
||||
//Button update
|
||||
BtnA.read();
|
||||
BtnB.read();
|
||||
BtnC.read();
|
||||
|
||||
//Speaker update
|
||||
Speaker.update();
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
**例程**
|
||||
|
||||
```arduino
|
||||
#include <M5Stack.h>
|
||||
#include <M5StackC.h>
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
}
|
||||
```
|
||||
|
||||
## update()
|
||||
## GetBm8563Time()
|
||||
|
||||
*这是 BM8563 芯片的 API 函数。该芯片与 ESP32 之间通过 IIC 通信,IIC 地址为 0x51*
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>void update();</mark>
|
||||
<mark>void GetBm8563Time(void);</mark>
|
||||
|
||||
<!-- <mark>fillScreen(color)</mark> # for micropython -->
|
||||
|
||||
**功能:读取按键 A, B, C 的状态。**
|
||||
|
||||
**函数实现**
|
||||
**功能:获取当前时分秒的值,并保存到 M5.Rtc.Hour,M5.Rtc.Minute,M5.Rtc.Second 中,ASCII 格式。**
|
||||
|
||||
**例程:**
|
||||
```arduino
|
||||
void M5Stack::update() {
|
||||
|
||||
//Button update
|
||||
BtnA.read();
|
||||
BtnB.read();
|
||||
BtnC.read();
|
||||
|
||||
//Speaker update
|
||||
Speaker.update();
|
||||
}
|
||||
```
|
||||
|
||||
**例程**
|
||||
|
||||
```arduino
|
||||
#include <M5Stack.h>
|
||||
#include <M5StickC.h>
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
M5.begin();
|
||||
M5.Lcd.setRotation(3);
|
||||
M5.Lcd.fillScreen(BLACK);
|
||||
|
||||
M5.Lcd.setTextSize(2);
|
||||
M5.Lcd.println("rtc test");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
M5.update();
|
||||
}
|
||||
```
|
||||
|
||||
## powerOFF()
|
||||
|
||||
!> 不推荐使用:请使用Power::deepSleep()
|
||||
|
||||
**函数原型:**
|
||||
|
||||
<mark>void powerOFF();</mark>
|
||||
|
||||
<!-- <mark>fillScreen(color)</mark> # for micropython -->
|
||||
|
||||
**功能:系统进入深度睡眠状态。**
|
||||
|
||||
**函数实现**
|
||||
|
||||
```arduino
|
||||
void M5Stack::powerOFF() {
|
||||
M5.Power.deepSleep();
|
||||
}
|
||||
```
|
||||
|
||||
**例程**
|
||||
|
||||
```arduino
|
||||
#include <M5Stack.h>
|
||||
|
||||
void setup() {
|
||||
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() {
|
||||
M5.update();
|
||||
if (M5.BtnA.wasPressed()) {
|
||||
M5.powerOFF();
|
||||
}
|
||||
// put your main code here, to run repeatedly:
|
||||
M5.Rtc.GetBm8563Time();
|
||||
M5.Lcd.setCursor(0, 30, 2);
|
||||
M5.Lcd.printf("%02d : %02d : %02d\n",M5.Rtc.Hour, M5.Rtc.Minute, M5.Rtc.Second);
|
||||
delay(1000);
|
||||
}
|
||||
```
|
||||
@@ -74,7 +74,7 @@
|
||||
|
||||
<img src="assets/img/getting_started_pics/m5stack_core/get_started_with_arduino_m5core/windows/select_board_baudrate_serial_port.png">
|
||||
|
||||
选择示例程序 `Stick` -> `FactoryTest.ino`
|
||||
<font color="red">选择示例程序 `M5Stack` -> `Stick` -> `FactoryTest.ino`</font>
|
||||
|
||||
<img src="assets/img/getting_started_pics/m5stick/m5stick_arduino_windows_01.png">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user