Skip to content

Commit

Permalink
Fixed issue with LED strip type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Oct 13, 2023
1 parent 4ce6785 commit 7175828
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 4 additions & 5 deletions examples/modules/led_strip/multiple_strips.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Constants
STRIP_TYPE = LEDStripModule.NEOPIXEL # Change to LEDStripModule.DOTSTAR for APA102 style strips
# Two Neopixel strips can be driven too, by using LEDStripModule.DUAL_NEOPIXEL
LEDS_PER_STRIP = 60 # How many LEDs are on the strip. If using DUAL_NEOPIXEL this can be a tuple
LEDS_PER_STRIP = 60 # How many LEDs are on the strip. If using DUAL_NEOPIXEL this can be a single value or a list or tuple
BRIGHTNESS = 1.0 # The max brightness of the LEDs (only supported by APA102s)
SLEEP = 0.02 # The time to sleep between each update
SPEED = 0.01 # How much to advance the rainbow hue offset by each update
Expand Down Expand Up @@ -58,8 +58,7 @@ def pio_and_sm_generator():

# Wrap the code in a try block, to catch any exceptions (including KeyboardInterrupt)
try:

# Find out which slots of Yukon has LEDStripModules attached
# Find out which slots of Yukon have LEDStripModules attached
for slot in yukon.find_slots_with(LEDStripModule):
pio, sm = next(pio_and_sm) # Get the next PIO and State Machine numbers
module = LEDStripModule(STRIP_TYPE, # Create a LEDStripModule object, with the details of the attached strip(s)
Expand All @@ -74,7 +73,7 @@ def pio_and_sm_generator():
yukon.enable_main_output() # Turn on power to the module slots

for module in modules:
module.enable() # Enable each LEDStripModule's onboard 5V regulator
module.enable() # Enable each LEDStripModule's onboard regulator

current_time = ticks_ms() # Record the start time of the program loop

Expand All @@ -90,7 +89,7 @@ def pio_and_sm_generator():
# Otherwise, just update the single Neopixel or Dotstar strip
update_rainbow(module.strip, hue_offset)

# Advance the rainbow offset, wrapping if it exceeds 1.0
# Advance the hue offset, wrapping if it exceeds 1.0
hue_offset += SPEED
if hue_offset >= 1.0:
hue_offset -= 1.0
Expand Down
4 changes: 2 additions & 2 deletions examples/modules/led_strip/single_strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Two Neopixel strips can be driven too, by using LEDStripModule.DUAL_NEOPIXEL
STRIP_PIO = 0 # The PIO system to use (0 or 1) to drive the strip(s)
STRIP_SM = 0 # The State Machines (SM) to use to drive the strip(s)
LEDS_PER_STRIP = 60 # How many LEDs are on the strip. If using DUAL_NEOPIXEL this can be a tuple
LEDS_PER_STRIP = 60 # How many LEDs are on the strip. If using DUAL_NEOPIXEL this can be a single value or a list or tuple
BRIGHTNESS = 1.0 # The max brightness of the LEDs (only supported by APA102s)
SLEEP = 0.02 # The time to sleep between each update
SPEED = 0.01 # How much to advance the rainbow hue offset by each update
Expand Down Expand Up @@ -62,7 +62,7 @@ def update_rainbow(strip, offset):
# Otherwise, just update the single Neopixel or Dotstar strip
update_rainbow(module.strip, hue_offset)

# Advance the rainbow offset, wrapping if it exceeds 1.0
# Advance the hue offset, wrapping if it exceeds 1.0
hue_offset += SPEED
if hue_offset >= 1.0:
hue_offset -= 1.0
Expand Down
14 changes: 12 additions & 2 deletions lib/pimoroni_yukon/modules/led_strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ def __init__(self, strip_type, pio, sm, num_leds, brightness=1.0, halt_on_not_pg
if sm < 0 or sm > 3:
raise ValueError("sm out of range. Expected 0 to 3")

if num_leds <= 0:
raise ValueError("num_leds out of range. Expected greater than 0")
if strip_type == self.DUAL_NEOPIXEL and isinstance(num_leds, (list, tuple)):
if len(num_leds) != 2:
raise ValueError("num_leds list or tuple should only contain two values")

if num_leds[0] <= 0 or num_leds[1] <= 0:
raise ValueError("value in num_leds list or tuple out of range. Expected greater than 0")
else:
if isinstance(num_leds, (list, tuple)):
raise ValueError("num_leds should not be a list or tuple for the NEOPIXEL and DOTSTAR strip types")

if num_leds <= 0:
raise ValueError("num_leds out of range. Expected greater than 0")

if strip_type == self.DOTSTAR and (brightness < 0.0 or brightness > 1.0):
raise ValueError("brightness out of range. Expected 0.0 to 1.0")
Expand Down

0 comments on commit 7175828

Please sign in to comment.