Skip to content

Commit 1293a47

Browse files
committed
Corrected position calculation after introducing breath pauses
1 parent 72c6c68 commit 1293a47

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

adafruit_led_animation/helper.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False):
323323
:param dotstar_pwm: Whether to use the dostar per pixel PWM value for brightness control.
324324
"""
325325
period = int((period + (animation_object.breath * 2)) * MS_PER_SECOND)
326-
breath = int(animation_object.breath * MS_PER_SECOND)
326+
half_breath = int(animation_object.breath * MS_PER_SECOND // 2)
327327
half_period = period // 2
328328

329329
last_update = monotonic_ms()
@@ -339,12 +339,12 @@ def pulse_generator(period: float, animation_object, dotstar_pwm=False):
339339
last_pos = pos
340340
if pos > half_period:
341341
pos = period - pos
342-
if pos < half_period and pos > (half_period - breath):
343-
intensity = animation_object.max_intensity
344-
elif pos > (period - breath):
342+
if pos < half_breath:
345343
intensity = animation_object.min_intensity
344+
elif pos > (half_period - half_breath):
345+
intensity = animation_object.max_intensity
346346
else:
347-
intensity = animation_object.min_intensity + ((pos / (half_period - breath)) * (animation_object.max_intensity - animation_object.min_intensity))
347+
intensity = animation_object.min_intensity + (((pos - half_breath) / (half_period - (half_breath * 2))) * (animation_object.max_intensity - animation_object.min_intensity))
348348
if dotstar_pwm:
349349
fill_color = (
350350
animation_object.color[0],

0 commit comments

Comments
 (0)