ola_simple_fade turn off

29 views
Skip to first unread message

Ananya

unread,
Jul 2, 2021, 8:58:12 PM7/2/21
to open-lighting
Hi all, 

I've been trying to turn off the lights after running ola_simple_fade.py from the examples but can't figure it out. Does anyone have any ideas on what I can edit in the code to turn the lights off after the script is run?

Peter Newman

unread,
Jul 5, 2021, 10:40:55 PM7/5/21
to open-lighting
Hi Annanya,

Google ate my first message, so here's a slightly briefer one. What do you actually want it to do, fade out, go off, only go round once? After a certain number of cycles or amount of time?

UpdateDmx is setting the values, so you could change them to zero at a certain point, or switch to a different AddEvent call so it starts doing a different update or call Stop to cease sending all DMX data.

Ananya

unread,
Jul 5, 2021, 10:56:32 PM7/5/21
to open-lighting
Hi Peter, 

Thanks for getting back to me. Currently, I want the lights to turn off 3 seconds after I run the code. 

So if I initialize total_time = 3000 at the start of the code, how should I edit UpdateDmx to take this into account? 

 (I should say that I don't have much experience programming if that wasn't obvious already) 

Peter Newman

unread,
Jul 6, 2021, 12:08:09 PM7/6/21
to open-lighting
So the bit that got missed from my second earlier message, if you just want them to fade on and off a bit for three seconds, have you considered ola_recorder:

Or do you need more interactivity of the levels or duration?

Do you want a complete number of cycles to fit in the 3 seconds, or just for it to guarantee it goes off at 3 seconds?

What happens next, should the script do something again in the future, or is that it until someone runs it again?

There are a few ways to achieve what you want in code, but the simplest may be to track when you want it to finish, so for example within the init of SimpleFadeController, you could store this into a variable:
datetime.datetime.now() + datetime.timedelta(milliseconds=total_time)

Which will be the time to finish, then within UpdateDmx you could check if your expiry time is <= datetime.datetime.now() and use that to decide whether to run the normal for loop or to set everything to 0 and then stop the wrapper or wait for the next action.

Ananya

unread,
Jul 6, 2021, 2:49:54 PM7/6/21
to open-lighting
Thanks for the tips! I've tried updating the script with the datetime property, but I am still unclear on how I can send the 0 signal to turn everything off after 3 seconds. 

import datetime
from array import array
from ola.ClientWrapper import ClientWrapper
from ola.DMXConstants import DMX_MIN_SLOT_VALUE, DMX_MAX_SLOT_VALUE, \
DMX_UNIVERSE_SIZE

UPDATE_INTERVAL = 25 # In ms, this comes about to ~40 frames a second. Frequency of blinks
FADE_NUMBER = 6 # number of fades
DMX_DATA_SIZE = 100
UNIVERSE = 1
loop_count = 0
total_time = 3000 #3 seconds

SHUTDOWN_INTERVAL = FADE_NUMBER ** 4 #total val is ms
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.tracker = datetime.datetime.now() + datetime.timedelta(milliseconds=total_time) #3 seconds into the future
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)

def UpdateDmx(self):
"""
This function gets called periodically based on UPDATE_INTERVAL
"""
if datetime.datetime.now() <= self.tracker:
for i in range(len(self._data)):
self._data[i] = (self._data[i] + 1) % DMX_MAX_SLOT_VALUE
# Send the DMX data
self._client.SendDmx(self._universe, self._data)
# Add our event again so it becomes periodic
self._wrapper.AddEvent(self._update_interval, self.UpdateDmx)
else:
pass #help needed - how to send 0 signal

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

Peter Newman

unread,
Jul 6, 2021, 9:05:50 PM7/6/21
to open-lighting
So you're pretty much there, you just need an else, and then something like this again to set it to a blackout:
self._data = array('B', [DMX_MIN_SLOT_VALUE] * dmx_data_size)

Or another for loop iterating round setting each value to zero.

It's only the for i in range bit you need to switch between, the SendDmx and AddEvent could stay as they are (assuming you don't want the programme to exit until SHUTDOWN_INTERVAL. You could do the if within the for loop, but I'd imagine evaluating datetime.datetime.now 512 times for each frame may be rather slow.

Reply all
Reply to author
Forward
0 new messages