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
+ */
1
11
#include < M5Stack.h>
2
12
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.
4
15
void setup () {
5
-
6
- // initialize the M5Stack object
7
- M5.begin ();
16
+ M5.begin (); // Init M5Core
17
+ M5.Power .begin (); // Init Power module
8
18
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
19
21
M5.Lcd .fillScreen (RED);
20
22
delay (500 );
21
23
M5.Lcd .fillScreen (GREEN);
@@ -25,34 +27,31 @@ void setup() {
25
27
M5.Lcd .fillScreen (BLACK);
26
28
delay (500 );
27
29
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
34
34
35
35
// draw graphic
36
36
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)
38
38
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)
40
40
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)
42
42
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)
44
44
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
46
46
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
49
48
}
50
49
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
52
52
void loop (){
53
53
54
- // rand draw
55
54
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 ));
56
55
57
- M5.update ();
56
+ M5.update (); // Read the press state of the key
58
57
}
0 commit comments