Files

43 lines
1007 B
Arduino
Raw Permalink Normal View History

2021-03-12 14:30:06 +08:00
/*
2025-01-14 10:53:33 +08:00
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/
/*
* @Hardwares: M5Core + Catch
* @Platform Version: Arduino M5Stack Board Manager v2.1.3
* @Dependent Library:
* M5Stack@^0.4.6: https://github.com/m5stack/M5Stack
*/
2021-03-12 14:30:06 +08:00
#include <M5Stack.h>
const int servoPin = 26;
2022-07-06 12:15:36 +08:00
int freq = 50;
int ledChannel = 0;
int resolution = 10;
2025-01-14 10:53:33 +08:00
void setup()
{
2022-07-06 12:15:36 +08:00
// put your setup code here, to run once:
M5.begin();
M5.Power.begin();
M5.Lcd.setCursor(100, 50, 4);
M5.Lcd.println("Catch Unit");
M5.Lcd.setCursor(40, 120, 4);
M5.Lcd.println("Connect to the Port B");
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(servoPin, ledChannel);
2021-03-12 14:30:06 +08:00
}
2025-01-14 10:53:33 +08:00
void loop()
{
2022-07-06 12:15:36 +08:00
// High level 0.5ms is angle 0°
// duty = 0.5/20ms = 0.025, 0.025*1023≈25
2021-03-12 14:30:06 +08:00
ledcWrite(ledChannel, 25);
delay(2000);
2022-07-06 12:15:36 +08:00
// High level 1ms is angle 45°
// duty = 1/20ms = 0.05, 0.05*1023≈50
2021-03-12 14:30:06 +08:00
ledcWrite(ledChannel, 50);
delay(2000);
}