Skip to content

Commit fcc5ec6

Browse files
authored
Merge pull request #45 from Tinyu-Zhao/master
Modify and add some examples, add comments
2 parents d7824df + dfdb530 commit fcc5ec6

File tree

11 files changed

+443
-187
lines changed

11 files changed

+443
-187
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
~/.DS_Store
12

2-
examples/.DS_Store
3+
*/.DS_Store
34
examples/Basics/.DS_Store
45
.development
56
examples/Touch/.DS_Store

examples/Basics/button/button.ino

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core2 sample source code
5+
* 配套 M5Core2 示例源代码
6+
* Visit the website for more information:https://docs.m5stack.com/en/core/core2
7+
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2
8+
*
9+
* describe:Button example. 按键示例
10+
* date:2021/7/21
11+
*******************************************************************************
12+
*/
13+
#include <M5Core2.h>
14+
/* After M5Core2 is started or reset
15+
the program in the setUp () function will be run, and this part will only be run once.
16+
在 M5Core2 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
17+
void setup() {
18+
M5.begin(); //Init M5Core. 初始化 M5Core2
19+
M5.Lcd.setTextColor(YELLOW); //Set the font color to yellow. 设置字体颜色为黄色
20+
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小为2
21+
M5.Lcd.setCursor(65, 10); //Move the cursor position to (x, y). 移动光标位置到 (x, y)处
22+
M5.Lcd.println("Button example"); //The screen prints the formatted string and wraps the line. 输出格式化字符串并换行
23+
M5.Lcd.setCursor(3, 35);
24+
M5.Lcd.println("Press button B for 700ms");
25+
M5.Lcd.println("to clear screen.");
26+
M5.Lcd.setTextColor(RED);
27+
}
28+
29+
/* After the program in setup() runs, it runs the program in loop()
30+
The loop() function is an infinite loop in which the program runs repeatedly
31+
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
32+
loop()函数是一个死循环,其中的程序会不断的重复运行 */
33+
void loop() {
34+
M5.update(); //Read the press state of the key. 读取按键 A, B, C 的状态
35+
if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) {
36+
M5.Lcd.print('A');
37+
} else if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) {
38+
M5.Lcd.print('B');
39+
} else if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) {
40+
M5.Lcd.print('C');
41+
} else if (M5.BtnB.wasReleasefor(700)) {
42+
M5.Lcd.clear(WHITE); // Clear the screen and set white to the background color. 清空屏幕并将白色设置为底色
43+
M5.Lcd.setCursor(0, 0);
44+
}
45+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core2 sample source code
5+
* 配套 M5Core2 示例源代码
6+
* Visit the website for more information:https://docs.m5stack.com/en/core/core2
7+
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2
8+
*
9+
* describe:Display Example. 显示屏示例
10+
* date:2021/7/21
11+
*******************************************************************************
12+
*/
13+
#include <M5Core2.h>
14+
15+
/* After M5Core2 is started or reset
16+
the program in the setUp () function will be run, and this part will only be run once.
17+
在 M5Core2 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
18+
void setup() {
19+
M5.begin(); //Init M5Core2. 初始化 M5Core2
20+
M5.Lcd.fillScreen(WHITE); // Set the screen background. 设置屏幕底色为白色
21+
delay(500); //Delay 500ms. 延迟500ms
22+
M5.Lcd.fillScreen(RED);
23+
delay(500);
24+
M5.Lcd.fillScreen(GREEN);
25+
delay(500);
26+
M5.Lcd.fillScreen(BLUE);
27+
delay(500);
28+
M5.Lcd.fillScreen(BLACK);
29+
delay(500);
30+
31+
M5.Lcd.setCursor(10, 10); //Move the cursor position to (x,y). 移动光标位置到 (x,y)处
32+
M5.Lcd.setTextColor(WHITE); //Set the font color to white. 设置字体颜色为白色
33+
M5.Lcd.setTextSize(1); //Set the font size. 设置字体大小
34+
M5.Lcd.printf("Display Test!"); //Serial output format string. 输出格式化字符串
35+
36+
// draw graphic
37+
delay(1000);
38+
M5.Lcd.drawRect(100, 100, 50, 50, BLUE); //Draw a 50x50 blue rectangle wireframe at (x,y).
39+
delay(1000); //在(x,y)处画 长宽为50x50的蓝色矩形线框
40+
M5.Lcd.fillRect(100, 100, 50, 50, BLUE);//Draw a blue rectangle 50x50 at (x,y)
41+
delay(1000); //在(x,y)处画 长宽为50x50的蓝色矩形
42+
M5.Lcd.drawCircle(100, 100, 50, RED); //Draw a red circle of radius 50 at (x,y)
43+
delay(1000); //在(x,y)处画 半径为50的红色圆线圈
44+
M5.Lcd.fillCircle(100, 100, 50, RED); //Draw a red circle of radius 50 at (x,y)
45+
delay(1000); //在(x,y)处画 半径为50的红色圆
46+
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); //Make a triangle wireframe with (x1,y1) (x2,y2) (x3,y3) as the vertices
47+
delay(1000); //以 (x1,y1) (x2,y2) (x3,y3)为顶点作三角形线框
48+
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW); //以 (x1,y1) (x2,y2) (x3,y3)为顶点作三角形
49+
} // Construct a triangle with (x1,y1) (x2,y2) (x3,y3) as its vertices
50+
51+
/* After the program in setup() runs, it runs the program in loop()
52+
The loop() function is an infinite loop in which the program runs repeatedly
53+
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
54+
loop()函数是一个死循环,其中的程序会不断的重复运行 */
55+
void loop(){
56+
57+
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));
58+
59+
M5.update(); //Read the press state of the key. 读取按键 A, B, C 的状态
60+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core2 sample source code
5+
* 配套 M5Core2 示例源代码
6+
* Visit the website for more information:https://docs.m5stack.com/en/core/core2
7+
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2
8+
*
9+
* describe:Hello World
10+
* date:2021/7/21
11+
*******************************************************************************
12+
*/
13+
#include <M5Core2.h>
14+
15+
/* After M5Core2 is started or reset
16+
the program in the setUp () function will be run, and this part will only be run once.
17+
在 M5Core2 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
18+
void setup(){
19+
M5.begin(); //Init M5Core2. 初始化 M5Core2
20+
/* Power chip connected to gpio21, gpio22, I2C device
21+
Set battery charging voltage and current
22+
If used battery, please call this function in your project */
23+
M5.Lcd.print("Hello World"); // Print text on the screen (string) 在屏幕上打印文本(字符串)
24+
}
25+
26+
/* After the program in setup() runs, it runs the program in loop()
27+
The loop() function is an infinite loop in which the program runs repeatedly
28+
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
29+
loop()函数是一个死循环,其中的程序会不断的重复运行 */
30+
void loop() {
31+
32+
}
Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core2 sample source code
5+
* 配套 M5Core2 示例源代码
6+
* Visit the website for more information:https://docs.m5stack.com/en/core/core2
7+
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2
8+
*
9+
* describe:MPU6886 example. 惯性传感器
10+
* date:2021/7/21
11+
*******************************************************************************
12+
*/
113
#include <M5Core2.h>
214

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

719
float gyroX = 0.0F;
@@ -14,41 +26,44 @@ float yaw = 0.0F;
1426

1527
float temp = 0.0F;
1628

17-
// the setup routine runs once when M5Stack starts up
29+
/* After M5Core2 is started or reset
30+
the program in the setUp () function will be run, and this part will only be run once.
31+
在 M5Core2 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
1832
void setup(){
33+
M5.begin(); //Init M5Core. 初始化 M5Core
34+
M5.IMU.Init(); //Init IMU sensor. 初始化惯性传感器
35+
M5.Lcd.fillScreen(BLACK); //Set the screen background color to black. 设置屏幕背景色为黑色
36+
M5.Lcd.setTextColor(GREEN , BLACK); //Sets the foreground color and background color of the displayed text. 设置显示文本的前景颜色和背景颜色
37+
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小
38+
}
1939

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

25-
M5.Lcd.fillScreen(BLACK);
26-
M5.Lcd.setTextColor(GREEN , BLACK);
27-
M5.Lcd.setTextSize(2);
28-
}
49+
// Accelerometer output is related
50+
//加速度计输出相关
51+
M5.Lcd.setCursor(0, 70);
52+
M5.Lcd.printf("accX, accY, accZ");
53+
M5.Lcd.setCursor(0, 92);
54+
M5.Lcd.printf("%5.2f %5.2f %5.2f G", accX, accY, accZ);
55+
56+
// Pose output is related
57+
//姿态输出相关
58+
M5.Lcd.setCursor(0, 120);
59+
M5.Lcd.printf("pitch, roll, yaw");
60+
M5.Lcd.setCursor(0, 142);
61+
M5.Lcd.printf("%5.2f %5.2f %5.2f deg", pitch, roll, yaw);
2962

30-
// the loop routine runs over and over again forever
31-
void loop() {
32-
// put your main code here, to run repeatedly:
33-
M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ);
34-
M5.IMU.getAccelData(&accX,&accY,&accZ);
35-
M5.IMU.getAhrsData(&pitch,&roll,&yaw);
36-
M5.IMU.getTempData(&temp);
37-
38-
M5.Lcd.setCursor(0, 20);
39-
M5.Lcd.printf("%6.2f %6.2f %6.2f ", gyroX, gyroY, gyroZ);
40-
M5.Lcd.setCursor(220, 42);
41-
M5.Lcd.print(" o/s");
42-
M5.Lcd.setCursor(0, 65);
43-
M5.Lcd.printf(" %5.2f %5.2f %5.2f ", accX, accY, accZ);
44-
M5.Lcd.setCursor(220, 87);
45-
M5.Lcd.print(" G");
46-
M5.Lcd.setCursor(0, 110);
47-
M5.Lcd.printf(" %5.2f %5.2f %5.2f ", pitch, roll, yaw);
48-
M5.Lcd.setCursor(220, 132);
49-
M5.Lcd.print(" degree");
50-
M5.Lcd.setCursor(0, 155);
63+
// Inertial sensor temperature output related
64+
//惯性传感器温度输出相关
65+
M5.Lcd.setCursor(0, 175);
5166
M5.Lcd.printf("Temperature : %.2f C", temp);
5267

53-
delay(1);
68+
delay(1000); // Delay 1000ms (1 sec) //延迟1000ms(1秒)
5469
}

0 commit comments

Comments
 (0)