Matrix Creator Python Everloop


#1

Hi everyone,

I’ve just got the matrix creator and would like to use python as my language on it,

I’ve found the following link https://matrix-io.github.io/matrix-documentation/matrix-core/getting-started/python-installation/, which shows me how to use python and has an everloop example.

I can’t understand this example as its too complicated, I’d be grateful if someone could provide me an everloop example just to turn the all the leds one colour and leave them that way.

Many thanks.


#2

Hey @alley1245,

I posted a smaller example below and put it in a function to easily call. I hope this helps give you a better understanding of MATRIX Core. Let us know if you have any more questions. :slight_smile:

Everloop Documentation: https://matrix-io.github.io/matrix-documentation/matrix-core/python-examples/everloop/

import zmq # Asynchronous messaging framework
from matrix_io.proto.malos.v1 import driver_pb2 # MATRIX Protocol Buffer drivers
from matrix_io.proto.malos.v1 import io_pb2 # MATRIX Protocol Buffer sensors

## Set Initial Variables ##
matrix_ip = '127.0.0.1' # Local device ip
everloop_base_port = 20021

# Create & connect PUSH socket to Base Port
socket = zmq.Context().socket(zmq.PUSH)
socket.connect('tcp://{0}:{1}'.format(matrix_ip, everloop_base_port))

# Set all LEDs to one color
def led(color):  
    # Create a new driver config
    driver_config_proto = driver_pb2.DriverConfig()

    # For each LED (MATRIX Creator has 35 LEDs)
    everloop_image = []
    for _ in range(35):
        # Create an LED
        ledValue = io_pb2.LedValue()

        # Set LED color
        ledValue.red   = color["red"]
        ledValue.green = color["green"]
        ledValue.blue  = color["blue"]
        ledValue.white = color["white"]

        # Add LED to everloop image
        everloop_image.append(ledValue)

    # Store the Everloop image in driver config
    driver_config_proto.image.led.extend(everloop_image)

    # Send driver config
    socket.send(driver_config_proto.SerializeToString())


led({
    "red"   : 100,
    "blue"  : 100,
    "green" : 0,
    "white" : 0,
})