Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SPIKE Essential 3x3 Color Light Matrix #440

Closed
dlech opened this issue Aug 17, 2021 · 7 comments
Closed

Support for SPIKE Essential 3x3 Color Light Matrix #440

dlech opened this issue Aug 17, 2021 · 7 comments
Assignees
Labels
enhancement New feature or request platform: essentialhub Issues related to the LEGO SPIKE Essential hub software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: lights Issues involving lights

Comments

@dlech
Copy link
Member

dlech commented Aug 17, 2021

Is your feature request related to a problem? Please describe.
LEGO Education just released a new Color Light Matrix I/O device with the new SPIKE Essential set.

spec sheet

@dlech dlech added enhancement New feature or request software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: lights Issues involving lights platform: essentialhub Issues related to the LEGO SPIKE Essential hub labels Aug 17, 2021
@dlech
Copy link
Member Author

dlech commented Aug 17, 2021

Give this issue a 👍 if you would like to see support for this hub added sooner rather than later.

@laurensvalk
Copy link
Member

We're going to need at least 6 😲

image

@laurensvalk laurensvalk self-assigned this Sep 8, 2021
laurensvalk added a commit to pybricks/pybricks-micropython that referenced this issue Sep 8, 2021
This is required to support the new LEGO SPIKE Color Light Matrix (pybricks/support#440)
@laurensvalk
Copy link
Member

If anyone is curious, you can already try this device using the special build referenced above.

Then use this script to see what it could do.

from pybricks.iodevices import PUPDevice
from pybricks.parameters import Port, Color
from pybricks.tools import wait

from urandom import randint


class ColorMatrix(PUPDevice):

    def _hue_to_id(self, h):

        h = h % 360

        # Color.RED
        if h < 15 or h > 330:
            return 9
        # Color.ORANGE
        if 15 <= h <= 45:
            return 8
        # Color.YELLOW
        if 45 <= h <= 90:
            return 7
        # Color.GREEN
        if 90 <= h <= 135:
            return 6
        # Turquoise?
        if 135 <= h <= 165:
            return 5
        # Color.CYAN
        if 165 <= h <= 210:
            return 4
        # Color.BLUE
        if 210 <= h <= 255:
            return 3
        # Color.VIOLET
        if 255 <= h <= 285:
            return 2
        # Color.MAGENTA
        if 285 <= h <= 330:
            return 1

    def _color_to_id(self, color):

        brightness = color.v // 10

        if color.s < 30:
            return 10 if color.v <= 10 else 10 + 16 * brightness
        else:
            return self._hue_to_id(color.h) + 16 * brightness

    def off(self):
        self.write(2, [0]*9)

    def on(self, colors):

        if type(colors) == type(Color.RED):
            self.write(2, [self._color_to_id(colors)] * 9)
        else:
            self.write(2, [self._color_to_id(c) for c in colors])


color_matrix = ColorMatrix(Port.B)

# Static single color example
color_matrix.on(Color.ORANGE)
wait(1000)

# Static multi color example
color_matrix.on([Color.RED, Color.WHITE, Color.BLUE] * 3)
wait(1000)

# Fade example
for i in range(3):
    for brightness in tuple(range(0, 110, 10)) + tuple(range(100, -10, -10)):
        color_matrix.on(Color.BLUE * (brightness / 100) )
        wait(50)

# Randomness
for i in range(1000):
    color_matrix.on([Color(randint(0, 360), v=40) for i in range(9)])
    wait(200)

laurensvalk added a commit to pybricks/pybricks-micropython that referenced this issue Sep 11, 2021
This is required to support the new LEGO SPIKE Color Light Matrix (pybricks/support#440)
laurensvalk added a commit to pybricks/pybricks-micropython that referenced this issue Sep 11, 2021
This is required to support the new LEGO SPIKE Color Light Matrix (pybricks/support#440)
dlech added a commit to pybricks/pybricks-micropython that referenced this issue Sep 14, 2021
This adds a new driver for the TI LP50XX chip found on the SPIKE Essential hub.

Issue: pybricks/support#440
dlech added a commit to pybricks/pybricks-micropython that referenced this issue Sep 14, 2021
This adds support for the new SPIKE Essential hub.

Issue: pybricks/support#440
@laurensvalk
Copy link
Member

This device seems quite susceptible to #304. And as pointed out in that issue, even without prints, possibly just a particular timing.

@dlech
Copy link
Member Author

dlech commented Sep 15, 2021

Does the hub "freeze" or does it trigger the watchdog timer reset?

@laurensvalk
Copy link
Member

Watchdog.

@dlech
Copy link
Member Author

dlech commented Sep 17, 2021

This device seems quite susceptible to #304.

This is fixed now.

@dlech dlech closed this as completed Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request platform: essentialhub Issues related to the LEGO SPIKE Essential hub software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: lights Issues involving lights
Projects
None yet
Development

No branches or pull requests

2 participants