RELAY.ino 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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: Relay. 继电器
  10. * Date: 2021/8/16
  11. *******************************************************************************
  12. Please connect to Port B(26),Use RELAY to switch on and off the circuit.
  13. 请连接端口B(26),使用继电器开关电路。
  14. */
  15. #include <M5Stack.h>
  16. void setup() {
  17. M5.begin(); // Init M5Stack. 初始化M5Stack
  18. M5.Power.begin(); // Init power 初始化电源模块
  19. M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
  20. M5.Lcd.setCursor(50, 0);
  21. M5.Lcd.println(("Relay Example"));
  22. dacWrite(25, 0); // disable the speak noise. 禁用喇叭
  23. pinMode(26, OUTPUT); // Set pin 26 to output mode. 设置26号引脚为输出模式
  24. }
  25. void loop(void) {
  26. M5.Lcd.setCursor(100, 40);
  27. M5.Lcd.print("ON");
  28. digitalWrite(26, HIGH);
  29. delay(1000);
  30. M5.Lcd.fillRect(100, 40, 60, 50, BLACK);
  31. M5.Lcd.print("OFF");
  32. digitalWrite(26, LOW);
  33. delay(1000);
  34. M5.Lcd.fillRect(100, 40, 60, 50, BLACK);
  35. }