File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ // SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
5
+ const int DIR = 5 ;
6
+ const int STEP = 6 ;
7
+ const int microMode = 16 ; // microstep mode, default is 1/16 so 16; ex: 1/4 would be 4
8
+ // full rotation * microstep divider
9
+ const int steps = 200 * microMode;
10
+
11
+ void setup ()
12
+ {
13
+ // setup step and dir pins as outputs
14
+ pinMode (STEP, OUTPUT);
15
+ pinMode (DIR, OUTPUT);
16
+ }
17
+
18
+ void loop ()
19
+ {
20
+ // change direction every loop
21
+ digitalWrite (DIR, !digitalRead (DIR));
22
+ // toggle STEP to move
23
+ for (int x = 0 ; x < steps; x++)
24
+ {
25
+ digitalWrite (STEP, HIGH);
26
+ delay (2 );
27
+ digitalWrite (STEP, LOW);
28
+ delay (2 );
29
+ }
30
+ delay (1000 ); // 1 second delay
31
+ }
Original file line number Diff line number Diff line change
1
+ # SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ import time
6
+ import board
7
+ from digitalio import DigitalInOut , Direction
8
+
9
+ # direction and step pins as outputs
10
+ DIR = DigitalInOut (board .D5 )
11
+ DIR .direction = Direction .OUTPUT
12
+ STEP = DigitalInOut (board .D6 )
13
+ STEP .direction = Direction .OUTPUT
14
+
15
+ # microstep mode, default is 1/16 so 16
16
+ # another ex: 1/4 microstep would be 4
17
+ microMode = 16
18
+ # full rotation multiplied by the microstep divider
19
+ steps = 200 * microMode
20
+
21
+ while True :
22
+ # change direction every loop
23
+ DIR .value = not DIR .value
24
+ # toggle STEP pin to move the motor
25
+ for i in range (steps ):
26
+ STEP .value = True
27
+ time .sleep (0.001 )
28
+ STEP .value = False
29
+ time .sleep (0.001 )
30
+ print ("rotated! now reverse" )
31
+ # 1 second delay before starting again
32
+ time .sleep (1 )
You can’t perform that action at this time.
0 commit comments