OLA python color control

25 views
Skip to first unread message

Ananya

unread,
Jul 13, 2021, 12:10:44 PM7/13/21
to open-lighting

Hello,

I am having trouble controlling the colors on my led strip. As mentioned on a previous thread, I am quite new to programming so anything helps! I have seen online that you can control the color of a pixel using an array: for example [55,118,171] for blue; but unsure how to integrate it in the array as it seems like each element only controls the brightness and not the color. 

How can I edit ola_simple_fade to control the color of the first pixel to green or orange?

#!/usr/bin/env python

from array import array
from ola.ClientWrapper import ClientWrapper
from ola.DMXConstants import DMX_MIN_SLOT_VALUE, DMX_MAX_SLOT_VALUE, \
DMX_UNIVERSE_SIZE
import numpy as np

UPDATE_INTERVAL = 25 # In ms, this comes about to ~40 frames a second
SHUTDOWN_INTERVAL = 10000 # in ms, This is 10 seconds
DMX_DATA_SIZE = 100
UNIVERSE = 1


class SimpleFadeController(object):
def __init__(self, universe, update_interval, client_wrapper,
dmx_data_size=DMX_UNIVERSE_SIZE):
dmx_data_size = min(dmx_data_size, DMX_UNIVERSE_SIZE)
self._universe = universe
self._update_interval = update_interval
self._data = array('B', [DMX_MIN_SLOT_VALUE] * dmx_data_size)
self._wrapper = client_wrapper
self._client = client_wrapper.Client()
self._wrapper.AddEvent(self._update_interval, self.UpdateDmx)
self.trial_color = np.zeros((100,), dtype=int)
self.trial_color[3] = 171

def UpdateDmx(self):
"""
This function gets called periodically based on UPDATE_INTERVAL
"""

# Send the DMX data
self._client.SendDmx(self._universe, self.trial_color)
# Add our event again so it becomes periodic
self._wrapper.AddEvent(self._update_interval, self.UpdateDmx)

if __name__ == '__main__':
wrapper = ClientWrapper()
controller = SimpleFadeController(UNIVERSE, UPDATE_INTERVAL, wrapper,
DMX_DATA_SIZE)
# Call it initially
wrapper.AddEvent(SHUTDOWN_INTERVAL, wrapper.Stop)
# Start the wrapper
wrapper.Run()

Thanks in advance!

Glenn Meader

unread,
Jul 13, 2021, 2:01:22 PM7/13/21
to open-l...@googlegroups.com
An individual LED can only display a single color. 

LEDs that can display multiple colors are actually made from more than one LED chip packaged into a single device. Typically three LED chips are included in a RGB device - These are Red, Green, and Blue LED chips. 

To get other colors, such as yellow, the brightness of each of the 3 color LEDs is adjusted to mix the RGB colors to get the desired color. So for example, yellow is made from setting the Red and Green LEDs to full brightness, while setting the Blue LED to zero brightness. 
So the array of three numbers contains the brightness values for the the R, G and B LEDs and thus determines how the three colors are mixed to create the desired color. 

Each pixel needs the array of 3 RGB values to determine the color (and brightness) to be displayed by the pixel. The values typically vary from 0 to 255.

 In your example,  [55,118,171] for blue the Red value is 55 (fairly low brightness), the Green is 118 (medium brightness) and the blue is set to 171 (fairly high brightness) so you end up with a sort of cyan-ish blue that is moderately bright and not fully saturated. 

On Jul 13, 2021, at 9:10 AM, 'Ananya' via open-lighting <open-l...@googlegroups.com> wrote:


--
The Open Lighting Project: open-l...@googlegroups.com, #openlighting (irc.freenode.org)
To unsubscribe from this group, send email to open-lightin...@googlegroups.com
For more options, visit https://groups.google.com/groups/opt_out?hl=en
---
You received this message because you are subscribed to the Google Groups "open-lighting" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-lightin...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/open-lighting/0961fce4-de58-4f72-b453-caa698131746n%40googlegroups.com.

Peter Newman

unread,
Jul 15, 2021, 3:32:12 AM7/15/21
to open-lighting
As Glenn said, you're nearly always going to have three channels for your colour.

As you said you're new to programming Ananya, it might be worth forgetting about the programming for a bit and starting off by just playing around with the control aspect of it. If you browse to http://<your OLA IP>:9090/ you'll find a web UI, you can select your universe and there are some faders, or you can use the command line tool:

This will also confirm everything is patched and working within OLA and it's just your code at issue, not some config within OLA.

Once you've got the colours you want working, then depending on the view you're in, they will probably be decimal values, or maybe hex, and you can stick them into the slots of your array.

Also remember, and this may be the cause of your current issue, that in programming arrays start from zero, whereas DMX channels are normally counted from 1, so your current code:
self.trial_color[3] = 171

Is setting the first channel of the SECOND pixel (normally red), to 171 out of 255.

You probably want this for the (normally blue) of the FIRST pixel:
self.trial_color[2] = 171

Also because DMX channels only go up to 255, if you're using numpy, you want to use uint8 not int for the type, so:
self.trial_color = np.zeros((100,), dtype=uint8)

As an aside, I'd be curious what you're doing with this, I'm assuming it's a science project of some sort rather than a disco?
Reply all
Reply to author
Forward
0 new messages