Display.ino 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. *******************************************************************************
  3. * Copyright (c) 2022 by M5Stack
  4. * Equipped with M5Core sample source code
  5. * 配套 M5Core 示例源代码
  6. * Visit for more information: https://docs.m5stack.com/en/core/gray
  7. * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray
  8. *
  9. * Describe: Display Example. 显示屏示例
  10. * Date: 2021/7/21
  11. *******************************************************************************
  12. */
  13. #include <M5Stack.h>
  14. /* After M5Core is started or reset
  15. the program in the setUp () function will be run, and this part will only be run
  16. once. 在 M5Core
  17. 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
  18. void setup() {
  19. M5.begin(); // Init M5Core. 初始化 M5Core
  20. M5.Power.begin(); // Init Power module. 初始化电源模块
  21. M5.Lcd.fillScreen(WHITE); // Set the screen background. 设置屏幕底色为白色
  22. delay(500); // Delay 500ms. 延迟500ms
  23. M5.Lcd.fillScreen(RED);
  24. delay(500);
  25. M5.Lcd.fillScreen(GREEN);
  26. delay(500);
  27. M5.Lcd.fillScreen(BLUE);
  28. delay(500);
  29. M5.Lcd.fillScreen(BLACK);
  30. delay(500);
  31. M5.Lcd.setCursor(
  32. 10, 10); // Move the cursor position to (x,y). 移动光标位置到 (x,y)处
  33. M5.Lcd.setTextColor(
  34. WHITE); // Set the font color to white. 设置字体颜色为白色
  35. M5.Lcd.setTextSize(1); // Set the font size. 设置字体大小
  36. M5.Lcd.printf(
  37. "Display Test!"); // Serial output format string. 输出格式化字符串
  38. // draw graphic
  39. delay(1000);
  40. M5.Lcd.drawRect(100, 100, 50, 50,
  41. BLUE); // Draw a 50x50 blue rectangle wireframe at (x,y).
  42. delay(1000); //在(x,y)处画 长宽为50x50的蓝色矩形线框
  43. M5.Lcd.fillRect(100, 100, 50, 50,
  44. BLUE); // Draw a blue rectangle 50x50 at (x,y)
  45. delay(1000); //在(x,y)处画 长宽为50x50的蓝色矩形
  46. M5.Lcd.drawCircle(100, 100, 50,
  47. RED); // Draw a red circle of radius 50 at (x,y)
  48. delay(1000); //在(x,y)处画 半径为50的红色圆线圈
  49. M5.Lcd.fillCircle(100, 100, 50,
  50. RED); // Draw a red circle of radius 50 at (x,y)
  51. delay(1000); //在(x,y)处画 半径为50的红色圆
  52. M5.Lcd.drawTriangle(30, 30, 180, 100, 80, 150,
  53. YELLOW); // Make a triangle wireframe with (x1,y1)
  54. // (x2,y2) (x3,y3) as the vertices
  55. delay(1000); //以 (x1,y1) (x2,y2) (x3,y3)为顶点作三角形线框
  56. M5.Lcd.fillTriangle(30, 30, 180, 100, 80, 150,
  57. YELLOW); //以 (x1,y1) (x2,y2) (x3,y3)为顶点作三角形
  58. } // Construct a triangle with (x1,y1) (x2,y2) (x3,y3) as its vertices
  59. /* After the program in setup() runs, it runs the program in loop()
  60. The loop() function is an infinite loop in which the program runs repeatedly
  61. 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
  62. loop()函数是一个死循环,其中的程序会不断的重复运行 */
  63. void loop() {
  64. M5.Lcd.fillTriangle(random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1),
  65. random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1),
  66. random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1),
  67. random(0xfffe));
  68. M5.update(); // Read the press state of the key. 读取按键 A, B, C 的状态
  69. }