Skip to content

Commit 6c8a16e

Browse files
committed
update for PR in progress
1 parent 243b52b commit 6c8a16e

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

examples/pioasm_pulsegroup.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def make_sequence():
190190

191191
buf = array.array("L", make_sequence())
192192

193-
self._sm.start_continuous_write(buf)
193+
self._sm.background_write(loop=buf)
194194

195195
def _maybe_update(self):
196196
if self._auto_update:
@@ -237,20 +237,21 @@ def advance(self, delta):
237237
self._phase = (self._phase + delta) % 1
238238

239239

240-
pulsers = PulseGroup(board.SERVO_1, 18, auto_update=False)
241-
servos = [servo.Servo(p) for p in pulsers]
240+
if __name__ == "__main__":
241+
pulsers = PulseGroup(board.SERVO_1, 18, auto_update=False)
242+
servos = [servo.Servo(p) for p in pulsers]
242243

243-
sine = np.sin(np.linspace(0, 2 * np.pi, 50, endpoint=False)) * 0.5 + 0.5
244-
print(sine)
244+
sine = np.sin(np.linspace(0, 2 * np.pi, 50, endpoint=False)) * 0.5 + 0.5
245+
print(sine)
245246

246-
signals = [CyclicSignal(sine, i / len(servos)) for i in range(len(servos))]
247+
signals = [CyclicSignal(sine, i / len(servos)) for i in range(len(servos))]
247248

248-
t0 = adafruit_ticks.ticks_ms()
249-
while True:
250-
t1 = adafruit_ticks.ticks_ms()
251-
for servo, signal in zip(servos, signals):
252-
signal.advance((t1 - t0) / 8000)
253-
servo.fraction = signal.value
254-
pulsers.update()
255-
print(adafruit_ticks.ticks_diff(t1, t0), "ms")
256-
t0 = t1
249+
t0 = adafruit_ticks.ticks_ms()
250+
while True:
251+
t1 = adafruit_ticks.ticks_ms()
252+
for servo, signal in zip(servos, signals):
253+
signal.advance((t1 - t0) / 8000)
254+
servo.fraction = signal.value
255+
pulsers.update()
256+
print(adafruit_ticks.ticks_diff(t1, t0), "ms")
257+
t0 = t1

0 commit comments

Comments
 (0)