Skip to content

[Bug] Limit to number of user defined colors when using Spike light sensor. #2900

Open

Description

@SMTCS2020

Describe the bug
There seems to be a limit on the number of user defined colors when using the code AttmntClr.detectable_colors block. It fails to compile/run if more than 8 are included in the list - generates the python code with more than 8 entities but creates an error on running the code. This is when using a Spike Prime controller.

image

If all the defined colours in the example are added to the block it will fail as there are more than 8. Example only has eight included but more than 8 colors have been defined above this block.

Maybe the documentation could state the limit if it is hard to fix in the firmware.

Activity

  1. added
    triage
    on Nov 17, 2026
  2. BertLindeman commented on Nov 17, 2026

    @BertLindeman

    Hello,

    This is not the block coding but the python representation of it.

    The python I created loosely based upon your snippet:

    from pybricks.hubs import PrimeHub
    from pybricks.parameters import Color, Port
    from pybricks.pupdevices import ColorSensor
    
    # Set up.
    prime_hub = PrimeHub()
    Color.MY_RED = Color(0, 100, 100)
    Color.MY_RED_2 = Color(0, 100, 100)
    Color.MY_RED_3 = Color(0, 100, 100)
    Color.MY_RED_4 = Color(0, 100, 100)
    Color.MY_RED_5 = Color(0, 100, 100)
    Color.MY_RED_6 = Color(0, 100, 100)
    Color.MY_RED_7 = Color(0, 100, 100)
    Color.MY_RED_8 = Color(0, 100, 100)
    Color.MY_RED_9 = Color(0, 100, 100)
    Color.MY_RED_10 = Color(0, 100, 100)
    color_sensor = ColorSensor(Port.E)
    color_sensor.detectable_colors((Color.MY_RED, Color.MY_RED_2, Color.MY_RED_3, Color.MY_RED_4, Color.MY_RED_5, Color.MY_RED_6, Color.MY_RED_7, Color.MY_RED_8))
    color_sensor_2 = ColorSensor(Port.E)
    color_sensor_2.detectable_colors((Color.MY_RED, Color.MY_RED_2, Color.MY_RED_3, Color.MY_RED_4, Color.MY_RED_5, Color.MY_RED_6, Color.MY_RED_7, Color.MY_RED_8, Color.MY_RED_9))
    
    
    # The main program starts here.
    print('Hello, Pybricks!')

    This program runs OK on the 8 color detectable colors and "fails" on the 9 colors one with:

    Traceback (most recent call last):
      File "issue_2900_python.py", line 20, in <module>
    ValueError: Invalid argument
    

    I think the simplest way to fix this is an indication in the color sensor documentation like:
    You can have up to 8 colors in the detectable colors definition

    Bert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions