File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments