Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from __future__ import division
- import threading
- import random
- import usbdmx
- import time
- import sys
- import datetime
- dmxkill=[0]*512
- def default():
- print "Used default configuration"
- interfaces = usbdmx.scan()
- if not interfaces:
- print "No interfaces found."
- sys.exit()
- global dmx
- dmx = interfaces[0]
- dmx.open()
- dmx.mode(6)
- def fade(channel, fromvalue, tovalue, duration): ### THIS IS loopwrapper()
- global dmxkill
- dmxkill[channel]=1
- value=fademeta(channel, fromvalue, tovalue, duration)
- return channel, value
- def fademeta(channel, fromvalue, tovalue, duration): ### THIS IS loop()
- print dmxkill[channel]
- global dmxkill
- dmxkill[channel]=0
- value = fromvalue
- if fromvalue > tovalue:
- difference = fromvalue-tovalue
- else:
- difference = tovalue-fromvalue
- frametime=duration/difference
- dmx.set_dmx(channel, fromvalue)
- #print(value)
- time.sleep(frametime)
- while value <> tovalue:
- #print dmxkill[channel]
- if dmxkill[channel]==1:
- print "Dead."
- if fromvalue > tovalue:
- value-=1
- dmx.set_dmx(channel, value)
- #print(value)
- time.sleep(frametime)
- else:
- value+=1
- dmx.set_dmx(channel, value)
- #print(value)
- time.sleep(frametime)
- return value
- def fadet(channel, fromvalue, tovalue, duration): ### THIS IS loopwrapperwrapper()
- t = threading.Thread(target=fade, args=(channel, fromvalue, tovalue, duration))
- t.start()
- return channel, tovalue
- def flicker(channel, low, high, speed, duration):
- frame=duration*speed
- randomlast=random.randint(int(low),int(high))
- for i in range(frame):
- if i==frame:
- dmx.set_dmx(channel, randomlast)
- return channel, randomlast
- else:
- randomnow=random.randint(int(low),int(high))
- dmx.set_dmx(channel, randomnow)
- time.sleep(duration/speed/duration)
- def flickert_dont_use(channel, low, high, speed, duration, randomlast):
- frame=duration*speed
- for i in range(frame):
- if i==frame-1:
- dmx.set_dmx(channel, randomlast)
- else:
- randomnow=random.randint(int(low),int(high))
- dmx.set_dmx(channel, randomnow)
- time.sleep(duration/speed/duration)
- def flickert(channel, low, high, speed, duration):
- randomlast=random.randint(int(low),int(high))
- t = threading.Thread(target=flickert_dont_use, args=(channel, low, high, speed, duration, randomlast))
- t.start()
- return channel, randomlast
- def setval(channel, value):
- dmx.set_dmx(channel, value)
- return channel, value
- def setvalt(channel, value):
- t = threading.Thread(target=setval, args=(channel, value))
- t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement