Skip to content

Commit 6cd8ce1

Browse files
committed
add Catch Unit example
1 parent 31f424b commit 6cd8ce1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

examples/Unit/CATCH/CATCH.ino

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Description: Control Catch Unit through PWM.
3+
*/
4+
5+
#include <M5Stack.h>
6+
7+
const int servoPin = 26;
8+
int freq = 50;
9+
int ledChannel = 0;
10+
int resolution = 10;
11+
void setup() {
12+
// put your setup code here, to run once:
13+
M5.begin();
14+
M5.Power.begin();
15+
M5.Lcd.setCursor(100, 50, 4);
16+
M5.Lcd.println("Catch Unit");
17+
M5.Lcd.setCursor(40, 120, 4);
18+
M5.Lcd.println("Connect to the Port B");
19+
ledcSetup(ledChannel, freq, resolution);
20+
ledcAttachPin(servoPin, ledChannel);
21+
}
22+
23+
void loop() {
24+
// High level 0.5ms is angle 0°
25+
// duty = 0.5/20ms = 0.025, 0.025*1023≈25
26+
ledcWrite(ledChannel, 25);
27+
delay(2000);
28+
// High level 1ms is angle 45°
29+
// duty = 1/20ms = 0.05, 0.05*1023≈50
30+
ledcWrite(ledChannel, 50);
31+
delay(2000);
32+
}

0 commit comments

Comments
 (0)