EARTH.ino 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  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: EARTH. 土壤湿度
  10. * Date: 2021/8/11
  11. *******************************************************************************
  12. Please connect to Port B(26、36),Read the analog quantity and digital quantity
  13. returned by the EARTH unit, and convert the analog quantity into 12-bit data and
  14. display it on the screen. 请连接端口B(26、36),读取EARTH Unit
  15. 返回的模拟量和数字量,并将模拟量转换为12位数据显示在屏幕上。
  16. */
  17. #include <M5Stack.h>
  18. void setup() {
  19. M5.begin(); // Init M5Stack. 初始化M5Stack
  20. M5.Power.begin(); // Init power 初始化电源模块
  21. M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
  22. M5.Lcd.printf("UNIT_EARTH EXAMPLE\n");
  23. pinMode(26, INPUT); // Set pin 26 to input mode. 将引脚26设置为输入模式
  24. dacWrite(25, 0); // disable the speak noise. 禁用喇叭
  25. }
  26. void loop() {
  27. M5.Lcd.setCursor(0, 80); // Set the cursor at (0,80). 将光标设置在(0,80)
  28. M5.Lcd.printf("AnalogRead:%d\n", analogRead(36));
  29. M5.Lcd.printf("DigitalRead:%d\n", digitalRead(26));
  30. delay(1000);
  31. }