CATCH.ino 789 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. Description: Control Catch Unit through PWM.
  3. */
  4. #include <M5Stack.h>
  5. const int servoPin = 26;
  6. int freq = 50;
  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(100, 50, 4);
  14. M5.Lcd.println("Catch Unit");
  15. M5.Lcd.setCursor(40, 120, 4);
  16. M5.Lcd.println("Connect to the Port B");
  17. ledcSetup(ledChannel, freq, resolution);
  18. ledcAttachPin(servoPin, ledChannel);
  19. }
  20. void loop() {
  21. // High level 0.5ms is angle 0°
  22. // duty = 0.5/20ms = 0.025, 0.025*1023≈25
  23. ledcWrite(ledChannel, 25);
  24. delay(2000);
  25. // High level 1ms is angle 45°
  26. // duty = 1/20ms = 0.05, 0.05*1023≈50
  27. ledcWrite(ledChannel, 50);
  28. delay(2000);
  29. }