Skip to content

Commit

Permalink
Merge branch 'master' of github.com:m5stack/M5Stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitshaoxiang committed Jul 28, 2021
2 parents d7529e7 + b5a9dbe commit 462a4da
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 178 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ examples/Advanced/Proof
docs/datesheet

.vscode/*

examples/.DS_Store
.DS_Store
examples/Basics/.DS_Store
.development
examples/Touch/.DS_Store
37 changes: 20 additions & 17 deletions examples/Basics/Button/Button.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,45 @@
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more information:https://docs.m5stack.com/en/products
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describe:Button example
* date:2021/7/15
* describe:Button example. 按键示例
* date:2021/7/21
*******************************************************************************
*/
#include <M5Stack.h>
// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
/* After M5Core is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup() {
M5.begin(); //Init M5Core
M5.Power.begin();//Init Power module

M5.Lcd.setTextColor(YELLOW); // Set the font color to yellow
M5.Lcd.setTextSize(2); // Set the font size
M5.Lcd.setCursor(65, 10); //Move the cursor position to (x, y)
M5.Lcd.println("Button example"); //The screen prints the formatted string and wraps the line
M5.begin(); //Init M5Core. 初始化 M5Core
M5.Power.begin(); //Init Power module. 初始化电源模块
M5.Lcd.setTextColor(YELLOW); //Set the font color to yellow. 设置字体颜色为黄色
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小为2
M5.Lcd.setCursor(65, 10); //Move the cursor position to (x, y). 移动光标位置到 (x, y)处
M5.Lcd.println("Button example"); //The screen prints the formatted string and wraps the line. 输出格式化字符串并换行
M5.Lcd.setCursor(3, 35);
M5.Lcd.println("Press button B for 700ms");
M5.Lcd.println("to clear screen.");
M5.Lcd.setTextColor(RED);
}

//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
M5.update(); //Read the press state of the key
//Returns 1 if key A is released or pressed longer than the specified time
M5.update(); //Read the press state of the key. 读取按键 A, B, C 的状态
if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) {
M5.Lcd.print('A');
} else if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) {
M5.Lcd.print('B');
} else if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) {
M5.Lcd.print('C');
} else if (M5.BtnB.wasReleasefor(700)) {
M5.Lcd.clear(WHITE); // Clear the screen and set white to the background color
M5.Lcd.clear(WHITE); // Clear the screen and set white to the background color. 清空屏幕并将白色设置为底色
M5.Lcd.setCursor(0, 0);
}
}
60 changes: 32 additions & 28 deletions examples/Basics/Display/Display.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more information:https://docs.m5stack.com/en/products
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describe:Display Example
* date:2021/7/15
* describe:Display Example. 显示屏示例
* date:2021/7/21
*******************************************************************************
*/
#include <M5Stack.h>

// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
/* After M5Core is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup() {
M5.begin(); //Init M5Core
M5.Power.begin(); //Init Power module

M5.Lcd.fillScreen(WHITE); // Set the screen background color to white
delay(500); //Delay 500ms
M5.begin(); //Init M5Core. 初始化 M5Core
M5.Power.begin(); //Init Power module. 初始化电源模块
M5.Lcd.fillScreen(WHITE); // Set the screen background. 设置屏幕底色为白色
delay(500); //Delay 500ms. 延迟500ms
M5.Lcd.fillScreen(RED);
delay(500);
M5.Lcd.fillScreen(GREEN);
Expand All @@ -27,31 +29,33 @@ void setup() {
M5.Lcd.fillScreen(BLACK);
delay(500);

M5.Lcd.setCursor(10, 10); // Move the cursor position to (x,y)
M5.Lcd.setTextColor(WHITE); // Set the font color to white,
M5.Lcd.setTextSize(1); // Set the font size
M5.Lcd.printf("Display Test!"); // Serial output format string
M5.Lcd.setCursor(10, 10); //Move the cursor position to (x,y). 移动光标位置到 (x,y)处
M5.Lcd.setTextColor(WHITE); //Set the font color to white. 设置字体颜色为白色
M5.Lcd.setTextSize(1); //Set the font size. 设置字体大小
M5.Lcd.printf("Display Test!"); //Serial output format string. 输出格式化字符串

// draw graphic
delay(1000);
M5.Lcd.drawRect(100, 100, 50, 50, BLUE); // Draw a 50x50 blue rectangle wireframe at (x,y)
delay(1000);
M5.Lcd.fillRect(100, 100, 50, 50, BLUE); // Draw a blue rectangle 50x50 at (x,y)
delay(1000);
M5.Lcd.drawCircle(100, 100, 50, RED); // Draw a red circle of radius 50 at (x,y)
delay(1000);
M5.Lcd.drawRect(100, 100, 50, 50, BLUE); //Draw a 50x50 blue rectangle wireframe at (x,y).
delay(1000); //在(x,y)处画 长宽为50x50的蓝色矩形线框
M5.Lcd.fillRect(100, 100, 50, 50, BLUE);//Draw a blue rectangle 50x50 at (x,y)
delay(1000); //在(x,y)处画 长宽为50x50的蓝色矩形
M5.Lcd.drawCircle(100, 100, 50, RED); //Draw a red circle of radius 50 at (x,y)
delay(1000); //在(x,y)处画 半径为50的红色圆线圈
M5.Lcd.fillCircle(100, 100, 50, RED); //Draw a red circle of radius 50 at (x,y)
delay(1000);
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Make a triangle wireframe with (x1,y1) (x2,y2) (x3,y3) as the vertices
delay(1000);
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Construct a triangle with (x1,y1) (x2,y2) (x3,y3) as its vertices
}
delay(1000); //在(x,y)处画 半径为50的红色圆
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); //Make a triangle wireframe with (x1,y1) (x2,y2) (x3,y3) as the vertices
delay(1000); //以 (x1,y1) (x2,y2) (x3,y3)为顶点作三角形线框
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW); //(x1,y1) (x2,y2) (x3,y3)为顶点作三角形
} // Construct a triangle with (x1,y1) (x2,y2) (x3,y3) as its vertices

//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop(){

M5.Lcd.fillTriangle(random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(M5.Lcd.width()-1), random(M5.Lcd.height()-1), random(0xfffe));

M5.update(); //Read the press state of the key
M5.update(); //Read the press state of the key. 读取按键 A, B, C 的状态
}
27 changes: 16 additions & 11 deletions examples/Basics/HelloWorld/HelloWorld.ino
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
/*
*******************************************************************************
*Copyright (c) 2021 by M5Stack
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
*Visit the website for more information:https://docs.m5stack.com/en/products
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describe:Hello World
* date:2021/7/15
*******************************************************************************
*/
#include <M5Stack.h>

// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
/* After M5Core is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup(){
M5.begin(); //Init M5Core
M5.Power.begin(); /*Power chip connected to gpio21, gpio22, I2C device
M5.begin(); //Init M5Core. 初始化 M5Core
M5.Power.begin(); //Init Power module. 初始化电源模块
/* Power chip connected to gpio21, gpio22, I2C device
Set battery charging voltage and current
If used battery, please call this function in your project*/

M5.Lcd.print("Hello World"); // Print text on the screen (string)
If used battery, please call this function in your project */
M5.Lcd.print("Hello World"); // Print text on the screen (string) 在屏幕上打印文本(字符串)
}

//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {

}
60 changes: 36 additions & 24 deletions examples/Basics/IMU/IMU.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more information:https://docs.m5stack.com/en/products
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describe:MPU6886 example
* date:2021/7/15
* describe:MPU6886 example. 惯性传感器
* date:2021/7/21
*******************************************************************************
*/
#define M5STACK_MPU6886
#include <M5Stack.h>

float accX = 0.0F; // Define variables for storing inertial sensor data
float accY = 0.0F;
float accY = 0.0F; //定义存储惯性传感器相关数据的相关变量
float accZ = 0.0F;

float gyroX = 0.0F;
Expand All @@ -25,49 +27,59 @@ float yaw = 0.0F;

float temp = 0.0F;

// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
/* After M5Core is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup(){
M5.begin(); //Init M5Core
M5.Power.begin(); //Init Power module

M5.IMU.Init(); //Init IMU sensor
M5.begin(); //Init M5Core. 初始化 M5Core
M5.Power.begin(); //Init Power module. 初始化电源

M5.Lcd.fillScreen(BLACK); // Set the screen background color to black
M5.Lcd.setTextColor(GREEN , BLACK); // Sets the foreground color and background color of the displayed text
M5.Lcd.setTextSize(2); // Set the font size
M5.IMU.Init(); //Init IMU sensor. 初始化惯性传感器

M5.Lcd.fillScreen(BLACK); //Set the screen background color to black. 设置屏幕背景色为黑色
M5.Lcd.setTextColor(GREEN , BLACK); //Sets the foreground color and background color of the displayed text. 设置显示文本的前景颜色和背景颜色
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小
}

//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ); // Stores the triaxial gyroscope data of the inertial sensor to the relevant variable
M5.IMU.getAccelData(&accX,&accY,&accZ); // Stores the triaxial accelerometer data of the inertial sensor to the relevant variable
M5.IMU.getAhrsData(&pitch,&roll,&yaw); // Stores the inertial sensor attitude to the relevant variable
M5.IMU.getTempData(&temp); // Stores the inertial sensor temperature to temp
//Stores the triaxial gyroscope data of the inertial sensor to the relevant variable
//将惯性传感器的三轴陀螺仪数据存储至相关变量
M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ);
M5.IMU.getAccelData(&accX,&accY,&accZ); //Stores the triaxial accelerometer. 存储三轴加速度计数据
M5.IMU.getAhrsData(&pitch,&roll,&yaw); //Stores the inertial sensor attitude. 存储惯性传感器的姿态
M5.IMU.getTempData(&temp); //Stores the inertial sensor temperature to temp. 存储惯性传感器的温度

// The M5Core screen is 320x240 pixels, starting at the top left corner of the screen (0,0).
// gyroscope output related
M5.Lcd.setCursor(0, 20); // Move the cursor position to (x,y)
M5.Lcd.printf("gyroX, gyroY, gyroZ"); // Screen printingformatted string
/* The M5Core screen is 320x240 pixels, starting at the top left corner of the screen (0,0).
gyroscope output related
M5Stack屏幕像素为 320x240,以屏幕左上角为原点 (0,0)*/
//gyroscope output related. 陀螺仪输出相关
M5.Lcd.setCursor(0, 20); //Move the cursor position to (x,y). 移动光标位置到(x,y)处
M5.Lcd.printf("gyroX, gyroY, gyroZ"); //Screen printingformatted string. 输出格式化字符串
M5.Lcd.setCursor(0, 42);
M5.Lcd.printf("%6.2f %6.2f%6.2f o/s", gyroX, gyroY, gyroZ);

// Accelerometer output is related
//加速度计输出相关
M5.Lcd.setCursor(0, 70);
M5.Lcd.printf("accX, accY, accZ");
M5.Lcd.setCursor(0, 92);
M5.Lcd.printf("%5.2f %5.2f %5.2f G", accX, accY, accZ);

// Pose output is related
//姿态输出相关
M5.Lcd.setCursor(0, 120);
M5.Lcd.printf("pitch, roll, yaw");
M5.Lcd.setCursor(0, 142);
M5.Lcd.printf("%5.2f %5.2f %5.2f deg", pitch, roll, yaw);

// Inertial sensor temperature output related
//惯性传感器温度输出相关
M5.Lcd.setCursor(0, 175);
M5.Lcd.printf("Temperature : %.2f C", temp);

delay(1000); // Delay 1000ms (1 sec)
delay(1000); // Delay 1000ms (1 sec) //延迟1000ms(1秒)
}
39 changes: 22 additions & 17 deletions examples/Basics/PowerOFF/PowerOFF.ino
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
*Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* Visit the website for more information:https://docs.m5stack.com/en/products
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/gray
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray
*
* describe:Power Management Example
* date:2021/7/15
* describe:Power Management Example 电源管理
* date:2021/7/21
*******************************************************************************
*/
#include <M5Stack.h>

// After M5Core is started or reset
// the program in the setUp () function will be run, and this part will only be run once.
/* After M5Core is started or reset
the program in the setUp () function will be run, and this part will only be run once.
在 M5Core 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
void setup(){
M5.begin(); //Init M5Core
M5.Power.begin(); //Init Power module
M5.Power.lightSleep(SLEEP_SEC(5));
M5.Lcd.setTextSize(2); // Set the font size
M5.Lcd.print("press ButtonA: shutdown, use power button to turn back on");// Screen printing the formatted string
}
M5.begin(); //Init M5Core. 初始化 M5Core
M5.Power.begin(); //Init Power module. 初始化电源
M5.Power.lightSleep(SLEEP_SEC(5));
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小
M5.Lcd.print("press ButtonA: shutdown, use power button to turn back on"); //Screen printingformatted string. 输出格式化字符串
}

//After the program in setup() runs, it runs the program in loop()
//The loop() function is an infinite loop in which the program runs repeatedly
/* After the program in setup() runs, it runs the program in loop()
The loop() function is an infinite loop in which the program runs repeatedly
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
loop()函数是一个死循环,其中的程序会不断的重复运行 */
void loop() {
M5.update(); //Read the press state of the key
if(M5.BtnA.wasPressed()) { // Check if the key is pressed
M5.Power.powerOFF(); //Turn off power
M5.update(); //Read the press state of the key. 读取按键 A, B, C 的状态
if(M5.BtnA.wasPressed()) { //Check if the key is pressed. 如果按键A被按下
M5.Power.powerOFF(); //Turn off power. 关闭电源
}
}
Loading

0 comments on commit 462a4da

Please sign in to comment.