FAN.ino 574 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. Description: Adjust the speed of FAN Unit through PWM.
  3. */
  4. #include <M5Stack.h>
  5. const int motor_pin = 21;
  6. int freq = 10000;
  7. int ledChannel = 0;
  8. int resolution = 10;
  9. void setup() {
  10. // put your setup code here, to run once:
  11. M5.begin();
  12. M5.Power.begin();
  13. M5.Lcd.setCursor(120, 110, 4);
  14. M5.Lcd.println("MOTOR");
  15. ledcSetup(ledChannel, freq, resolution);
  16. ledcAttachPin(motor_pin, ledChannel);
  17. }
  18. void loop() {
  19. // put your main code here, to run repeatedly:
  20. ledcWrite(ledChannel, 512);
  21. delay(1000);
  22. ledcWrite(ledChannel, 0);
  23. delay(1000);
  24. }