FAN.ino 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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: Fan. 风扇
  10. * Date: 2021/8/16
  11. *******************************************************************************
  12. Please connect to Port B(26), Adjust the speed of FAN Unit through PWM.
  13. 请连接端口B(26),通过PWM调节风扇单元的转速。
  14. */
  15. #include <M5Stack.h>
  16. #define motor_pin 26
  17. int freq = 10000;
  18. int ledChannel = 0;
  19. int resolution = 10;
  20. void setup() {
  21. M5.begin(); // Init M5Stack. 初始化M5Stack
  22. M5.Power.begin(); // Init power 初始化电源模块
  23. M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
  24. M5.Lcd.setCursor(140,
  25. 10); // Set the cursor at (140,10). 将光标设置在(140,10)处
  26. M5.Lcd.println("Fan");
  27. ledcSetup(
  28. ledChannel, freq,
  29. resolution); // Sets the frequency and number of counts corresponding
  30. // to the channel. 设置通道对应的频率和计数位数
  31. ledcAttachPin(
  32. motor_pin,
  33. ledChannel); // Binds the specified channel to the specified I/O port
  34. // for output. 将指定通道绑定到指定 IO 口上以实现输出
  35. }
  36. void loop() {
  37. ledcWrite(ledChannel, 512); // Output PWM. 输出PWM
  38. delay(1000);
  39. ledcWrite(ledChannel, 0);
  40. delay(1000);
  41. }