Skip to content

Commit 5dccedb

Browse files
authored
Merge branch 'm5stack:master' into master
2 parents e982165 + 9dca80d commit 5dccedb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+44699
-10558
lines changed

examples/Basics/Button/Button.ino

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
11
/*
2-
Name: button.ino
3-
Created: 2018/9/21 14:06:15
4-
Author: sakabin
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core sample source code
5+
* Visit the website for more information:https://docs.m5stack.com/en/products
6+
*
7+
* describe:Button example
8+
* date:2021/7/15
9+
*******************************************************************************
510
*/
6-
711
#include <M5Stack.h>
8-
// The setup() function runs once each time the micro-controller starts
12+
// After M5Core is started or reset
13+
// the program in the setUp () function will be run, and this part will only be run once.
914
void setup() {
10-
// init lcd, serial, but don't init sd card
11-
M5.begin(true, false, true);
12-
13-
/*
14-
Power chip connected to gpio21, gpio22, I2C device
15-
Set battery charging voltage and current
16-
If used battery, please call this function in your project
17-
*/
18-
M5.Power.begin();
15+
M5.begin(); //Init M5Core
16+
M5.Power.begin();//Init Power module
1917

20-
M5.Lcd.clear(BLACK);
21-
M5.Lcd.setTextColor(YELLOW);
22-
M5.Lcd.setTextSize(2);
23-
M5.Lcd.setCursor(65, 10);
24-
M5.Lcd.println("Button example");
18+
M5.Lcd.setTextColor(YELLOW); // Set the font color to yellow
19+
M5.Lcd.setTextSize(2); // Set the font size
20+
M5.Lcd.setCursor(65, 10); //Move the cursor position to (x, y)
21+
M5.Lcd.println("Button example"); //The screen prints the formatted string and wraps the line
2522
M5.Lcd.setCursor(3, 35);
2623
M5.Lcd.println("Press button B for 700ms");
2724
M5.Lcd.println("to clear screen.");
2825
M5.Lcd.setTextColor(RED);
2926
}
3027

31-
// Add the main program code into the continuous loop() function
28+
//After the program in setup() runs, it runs the program in loop()
29+
//The loop() function is an infinite loop in which the program runs repeatedly
3230
void loop() {
33-
// update button state
34-
M5.update();
35-
36-
// if you want to use Releasefor("was released for"), use .wasReleasefor(int time) below
31+
M5.update(); //Read the press state of the key
32+
//Returns 1 if key A is released or pressed longer than the specified time
3733
if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) {
3834
M5.Lcd.print('A');
3935
} else if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) {
4036
M5.Lcd.print('B');
4137
} else if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) {
4238
M5.Lcd.print('C');
4339
} else if (M5.BtnB.wasReleasefor(700)) {
44-
M5.Lcd.clear(BLACK);
40+
M5.Lcd.clear(WHITE); // Clear the screen and set white to the background color
4541
M5.Lcd.setCursor(0, 0);
4642
}
4743
}

examples/Basics/Display/Display.ino

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core sample source code
5+
* Visit the website for more information:https://docs.m5stack.com/en/products
6+
*
7+
* describe:Display Example
8+
* date:2021/7/15
9+
*******************************************************************************
10+
*/
111
#include <M5Stack.h>
212

3-
// the setup routine runs once when M5Stack starts up
13+
// After M5Core is started or reset
14+
// the program in the setUp () function will be run, and this part will only be run once.
415
void setup() {
5-
6-
// initialize the M5Stack object
7-
M5.begin();
16+
M5.begin(); //Init M5Core
17+
M5.Power.begin(); //Init Power module
818

9-
/*
10-
Power chip connected to gpio21, gpio22, I2C device
11-
Set battery charging voltage and current
12-
If used battery, please call this function in your project
13-
*/
14-
M5.Power.begin();
15-
16-
// Lcd display
17-
M5.Lcd.fillScreen(WHITE);
18-
delay(500);
19+
M5.Lcd.fillScreen(WHITE); // Set the screen background color to white
20+
delay(500); //Delay 500ms
1921
M5.Lcd.fillScreen(RED);
2022
delay(500);
2123
M5.Lcd.fillScreen(GREEN);
@@ -25,34 +27,31 @@ void setup() {
2527
M5.Lcd.fillScreen(BLACK);
2628
delay(500);
2729

28-
// text print
29-
M5.Lcd.fillScreen(BLACK);
30-
M5.Lcd.setCursor(10, 10);
31-
M5.Lcd.setTextColor(WHITE);
32-
M5.Lcd.setTextSize(1);
33-
M5.Lcd.printf("Display Test!");
30+
M5.Lcd.setCursor(10, 10); // Move the cursor position to (x,y)
31+
M5.Lcd.setTextColor(WHITE); // Set the font color to white,
32+
M5.Lcd.setTextSize(1); // Set the font size
33+
M5.Lcd.printf("Display Test!"); // Serial output format string
3434

3535
// draw graphic
3636
delay(1000);
37-
M5.Lcd.drawRect(100, 100, 50, 50, BLUE);
37+
M5.Lcd.drawRect(100, 100, 50, 50, BLUE); // Draw a 50x50 blue rectangle wireframe at (x,y)
3838
delay(1000);
39-
M5.Lcd.fillRect(100, 100, 50, 50, BLUE);
39+
M5.Lcd.fillRect(100, 100, 50, 50, BLUE); // Draw a blue rectangle 50x50 at (x,y)
4040
delay(1000);
41-
M5.Lcd.drawCircle(100, 100, 50, RED);
41+
M5.Lcd.drawCircle(100, 100, 50, RED); // Draw a red circle of radius 50 at (x,y)
4242
delay(1000);
43-
M5.Lcd.fillCircle(100, 100, 50, RED);
43+
M5.Lcd.fillCircle(100, 100, 50, RED); //Draw a red circle of radius 50 at (x,y)
4444
delay(1000);
45-
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW);
45+
M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Make a triangle wireframe with (x1,y1) (x2,y2) (x3,y3) as the vertices
4646
delay(1000);
47-
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW);
48-
47+
M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150, YELLOW); // Construct a triangle with (x1,y1) (x2,y2) (x3,y3) as its vertices
4948
}
5049

51-
// the loop routine runs over and over again forever
50+
//After the program in setup() runs, it runs the program in loop()
51+
//The loop() function is an infinite loop in which the program runs repeatedly
5252
void loop(){
5353

54-
//rand draw
5554
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));
5655

57-
M5.update();
56+
M5.update(); //Read the press state of the key
5857
}

0 commit comments

Comments
 (0)