Skip to content

Commit 82d28d1

Browse files
committed
tuples to bytes
1 parent 936b4e6 commit 82d28d1

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

adafruit_motor/stepper.py

+6-23
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,12 @@
5757
"""Step a fraction of a step by partially activating two neighboring coils. Step size is determined
5858
by ``microsteps`` constructor argument."""
5959

60-
_SINGLE_STEPS = (
61-
(0, 1, 0, 0),
62-
(0, 0, 1, 0),
63-
(1, 0, 0, 0),
64-
(0, 0, 0, 1),
65-
)
60+
_SINGLE_STEPS = bytes([0b0010, 0b0100, 0b0001, 0b1000])
6661

67-
_DOUBLE_STEPS = (
68-
(0, 1, 0, 1),
69-
(0, 1, 1, 0),
70-
(1, 0, 1, 0),
71-
(1, 0, 0, 1),
72-
)
62+
_DOUBLE_STEPS = bytes([0b1010, 0b0110, 0b0101, 0b1001])
7363

74-
_INTERLEAVE_STEPS = (
75-
(0, 1, 0, 1),
76-
(0, 1, 0, 0),
77-
(0, 1, 1, 0),
78-
(0, 0, 1, 0),
79-
(1, 0, 1, 0),
80-
(1, 0, 0, 0),
81-
(1, 0, 0, 1),
82-
(0, 0, 0, 1),
64+
_INTERLEAVE_STEPS = bytes(
65+
[0b1010, 0b0010, 0b0110, 0b0100, 0b0101, 0b0001, 0b1001, 0b1000]
8366
)
8467

8568

@@ -148,12 +131,12 @@ def _update_coils(self, *, microstepping=False):
148131
#
149132
# Get coil activation sequence
150133
if self._steps is None:
151-
steps = (0, 0, 0, 0)
134+
steps = 0b0000
152135
else:
153136
steps = self._steps[self._current_microstep % len(self._steps)]
154137
# Energize coils as appropriate:
155138
for i, coil in enumerate(self._coil):
156-
coil.value = steps[i]
139+
coil.value = (steps >> i) & 0x01
157140
else:
158141
#
159142
# PWM Pins

0 commit comments

Comments
 (0)