def setColor(r,g,b): global currentR,currentG,currentB currentR = r currentG = g currentB = b hyperion.setColor(r,g,b)
def doTemp(): fps = 30 current_millis = lambda: int(round(time.time() * 1000)) off = bytearray([0, 0, 0]) sleepTime = 0.1 myledData = bytearray() colors = getColorArgs() for i in range(hyperion.ledCount): myledData += bytearray([0, 0, 0]) color = colors[0] myledData[150] = colors[0][0] myledData[151] = colors[0][1] myledData[152] = colors[0][2] myledData[180] = colors[1][0] myledData[181] = colors[1][1] myledData[182] = colors[1][2] myledData[310] = colors[2][0] myledData[311] = colors[2][1] myledData[312] = colors[2][2] # Start the write data loop while not hyperion.abort(): hyperion.setColor(myledData) time.sleep(sleepTime)
def setColor(r, g, b): global currentR, currentG, currentB currentR = r currentG = g currentB = b hyperion.setColor(r, g, b)
def shiftLED(ledData, increment, limit, lightPos=None): state = 0 while state < limit and not hyperion.abort(): ledData = ledData[increment:] + ledData[:increment] if (lightPos): tmp = ledData[lightPos] ledData[lightPos] = light hyperion.setColor(ledData) if (lightPos): ledData[lightPos] = tmp time.sleep(sleepTime) state += 1
def runScene(self): print "Starting led scene loop..." #30 fps sleep time sleepTime = 1.0 / fps lastTime = current_millis(); while not hyperion.abort(): # hyperion.setColor(ledData[colorIndex]) # colorIndex = (colorIndex + 1) % len(ledData) now = current_millis() elapsed = now - lastTime lastTime = now self.updateObjects(elapsed) #create a new empty scene to paint on ledScene = bytearray() for i in range(hyperion.ledCount): ledScene += off self.paintObjects(ledScene) hyperion.setColor(ledScene) time.sleep(sleepTime)
import hyperion, time # Get the parameters fadeTime = float(hyperion.args.get('fade-time', 5.0)) colorStart = hyperion.args.get('color-start', (255,174,11)) colorEnd = hyperion.args.get('color-end', (100,100,100)) color_step = ( (colorEnd[0] - colorStart[0]) / 256.0, (colorEnd[1] - colorStart[1]) / 256.0, (colorEnd[2] - colorStart[2]) / 256.0 ) # fade color calcChannel = lambda i: min(max(int(colorStart[i] + color_step[i]*step),0),255) for step in range(256): if hyperion.abort(): break hyperion.setColor( calcChannel(0),calcChannel(1),calcChannel(2) ) time.sleep( fadeTime / 256 ) # maintain color until effect end hyperion.setColor(colorEnd[0],colorEnd[1],colorEnd[2]) while not hyperion.abort(): time.sleep(1)
setColor( colors[int(steps)][0],colors[int(steps)][1],colors[int(steps)][2] ) time.sleep(minStepTime) t += minStepTime # fade out if fadeOutTime > 0: setColor( colors[int(steps)][0],colors[int(steps)][1],colors[int(steps)][2] ) for step in range(int(steps),-1,-incrementOut): if hyperion.abort(): break setColor( colors[step][0],colors[step][1],colors[step][2] ) time.sleep(sleepTimeOut) # start color t = 0.0 while t<colorEndTime and not hyperion.abort(): setColor( colors[0][0],colors[0][1],colors[0][2] ) time.sleep(minStepTime) t += minStepTime # repeat if repeat > 0 and repeatCounter >= repeat : break repeatCounter += 1 time.sleep(0.5) # maintain end color until effect end while not hyperion.abort() and maintainEndCol: hyperion.setColor( currentR, currentG, currentB ) time.sleep(1)
import time import colorsys import socket import errno # Get the parameters udpPort = int(hyperion.args.get('udpPort', 2812)) UDPSock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) UDPSock.setblocking(False) listen_addr = ("",udpPort) print "udp.py: bind socket port:",udpPort UDPSock.bind(listen_addr) hyperion.setColor(hyperion.ledCount * bytearray((int(0), int(0), int(0))) ) # Start the write data loop while not hyperion.abort(): try: data,addr = UDPSock.recvfrom(4500) # print data.strip(),len(data),addr if (len(data)%3 == 0): # print "numleds ",len(data)/3 ledData = bytearray() for i in range(hyperion.ledCount): if (i<(len(data)/3)): ledData += data[i*3+0] ledData += data[i*3+1] ledData += data[i*3+2] else:
colors[int(steps)][2]) time.sleep(minStepTime) t += minStepTime # fade out if fadeOutTime > 0: setColor(colors[int(steps)][0], colors[int(steps)][1], colors[int(steps)][2]) for step in range(int(steps), -1, -incrementOut): if hyperion.abort(): break setColor(colors[step][0], colors[step][1], colors[step][2]) time.sleep(sleepTimeOut) # start color t = 0.0 while t < colorEndTime and not hyperion.abort(): setColor(colors[0][0], colors[0][1], colors[0][2]) time.sleep(minStepTime) t += minStepTime # repeat if repeat > 0 and repeatCounter >= repeat: break repeatCounter += 1 time.sleep(0.5) # maintain end color until effect end while not hyperion.abort() and maintainEndCol: hyperion.setColor(currentR, currentG, currentB) time.sleep(1)
for i in range(hyperion.ledCount): hue = (baseHSVValue + hueChange * math.sin(2*math.pi * i / hyperion.ledCount)) % 1.0 rgb = colorsys.hsv_to_rgb(hue, baseHsv[1], baseHsv[2]) colorData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2]))) # set correct rotation after reinitialisation of the array colorData = colorData[-colorDataIncrement*numberOfRotates:] + colorData[:-colorDataIncrement*numberOfRotates] baseColorChangeStepCount += 1 # Calculate new colors for i in range(hyperion.ledCount): amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount)) colors[3*i+0] = int(colorData[3*i+0] * amplitude) colors[3*i+1] = int(colorData[3*i+1] * amplitude) colors[3*i+2] = int(colorData[3*i+2] * amplitude) # set colors hyperion.setColor(colors) # increment the phase amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi) if rotateColors: colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement] numberOfRotates = (numberOfRotates + 1) % hyperion.ledCount rotateColors = not rotateColors # sleep for a while time.sleep(sleepTime)
import hyperion import time import colorsys # Get the parameters sleepTime = float(hyperion.args.get("sleepTime", 1.0)) # Initialize the led data ledDataOdd = bytearray() for i in range(hyperion.ledCount): if i % 2 == 0: ledDataOdd += bytearray((int(255), int(0), int(0))) else: ledDataOdd += bytearray((int(255), int(255), int(255))) ledDataEven = bytearray() for i in range(hyperion.ledCount): if i % 2 == 0: ledDataEven += bytearray((int(255), int(255), int(255))) else: ledDataEven += bytearray((int(255), int(0), int(0))) # Start the write data loop while not hyperion.abort(): hyperion.setColor(ledDataOdd) time.sleep(sleepTime) hyperion.setColor(ledDataEven) time.sleep(sleepTime)
def main(): try: # use GPIO pin numbering convention GPIO.setmode(GPIO.BOARD) # set up GPIO pin for input GPIO.setup(GPIOFrontLight, GPIO.IN) GPIO.setup(GPIOSwitchAmbianceMode, GPIO.IN) GPIO.setup(GPIODimmer, GPIO.IN) GPIO.setup(GPIOFrontLight, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(GPIOSwitchAmbianceMode, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(GPIODimmer, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) frontLightStatus = 0 # 0 = off , 1 = on ambianceLightStatus = 0 # 0 = off, 1 = on ambianceMode = 0 # 0 = normal ambiance light , 1 = tv ambiance mode dimmerValue = 10 # 0 to 10 UDP_IP = "" UDP_PORT = 8888 sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) sock.settimeout(0.3) ledDataWandOn = bytearray() ledDataLampenOn = bytearray() ledDataWandOff = bytearray() ledDataLampenOff = bytearray() hsv = colorsys.rgb_to_hsv(250/255.0, 1.0, 158.0/255.0) hsvFront = colorsys.rgb_to_hsv(250.0/255.0, 1.0, 158.0/255.0) for i in range(1,152): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1]*2, 1) ledDataWandOn += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) ledDataWandOff += bytearray((0,0,0)) for i in range(1,61): rgb = colorsys.hsv_to_rgb(hsvFront[0], hsvFront[1]*2, hsvFront[2]) ledDataLampenOn += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) ledDataLampenOff += bytearray((0,0,0)) while not hyperion.abort(): # get GPIO value if GPIO.input(GPIOSwitchAmbianceMode) and ambianceMode <> 1: ambianceMode = 1 time.sleep(0.2) print("Button 2 pressed") if not GPIO.input(GPIOSwitchAmbianceMode) and ambianceMode <> 0: ambianceMode = 0 ambianceLightStatus = 0 time.sleep(0.2) print("Button 2 released") if GPIO.input(GPIOFrontLight) and frontLightStatus <> 1: frontLightStatus = 1 time.sleep(0.2) print("Button 1 pressed") if not GPIO.input(GPIOFrontLight) and frontLightStatus <> 0: frontLightStatus = 0 time.sleep(0.2) print("Button 1 released") if GPIO.input(GPIODimmer): print("DIMMER 1") timeCounter = 0 if GPIO.input(GPIODimmer) and ambianceLightStatus == 0: print("Light on") ambianceLightStatus = 1 ledData = ledDataWandOn if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) time.sleep(0.4) while GPIO.input(GPIODimmer): timeCounter = timeCounter + 1 print("TIME COUNTER") if timeCounter > 10: ambianceLightStatus = 0 ledData = ledDataWandOff if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) # print("Light off") time.sleep(0.1) if ambianceLightStatus == 1 and timeCounter <=10: print("DIMMING") ledDataWandOn = bytearray() dimmerValue = dimmerValue - 1 if dimmerValue == -1: dimmerValue = 10 for i in range(1,152): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1]*2, dimmerValue/10.0) ledDataWandOn += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) print("Dimmdone") ledData = bytearray() sleepTime = 0.1 if ambianceMode == 1: srgb = bytearray(152*3) try: number,addr = sock.recvfrom_into(srgb) # buffer size is ledDataServer = bytearray() for i in range(1, number-3, 3): ledDataServer += bytearray((srgb[i+2], srgb[i], srgb[i+1])) ledData = ledData + ledDataServer sleepTime = 0.01 except socket.timeout: ledData = ledData + ledDataWandOff else: if ambianceLightStatus == 1: ledData = ledData + ledDataWandOn else: ledData = ledData + ledDataWandOff if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) # wait 100ms time.sleep(sleepTime) # reset GPIO settings if user pressed Ctrl+C except KeyboardInterrupt: print("Execution stopped by user") GPIO.cleanup()
"step": 7, "lvl": lvl }, { "pos": 1, "step": 8, "lvl": lvl }, { "pos": 2, "step": 9, "lvl": lvl }, #{ "pos":0, "step":10, "lvl":lvl}, #{ "pos":1, "step":11, "lvl":lvl}, #{ "pos":2, "step":12, "lvl":lvl}, ] # Start the write data loop counter = 0 while not hyperion.abort(): counter += 1 for r in runners: if counter % r["step"] == 0: ledData[r["pos"]] = whiteLevel r["pos"] = (r["pos"] + 3) % (hyperion.ledCount * 3) ledData[r["pos"]] = r["lvl"] hyperion.setColor(ledData) time.sleep(sleepTime)
ledDataBuf = ledData[:] for i, v in enumerate(projectiles): projectiles[i][0] = projectiles[i][0] + projectiles[i][1] for t in range(0, trailLength): pixel = v[0] - v[1] * t if pixel + 2 < 0: pixel += hyperion.ledCount if pixel + 2 > hyperion.ledCount - 1: pixel -= hyperion.ledCount - 1 rgb = colorsys.hsv_to_rgb(v[2], 1, (trailLength - 1.0 * t) / trailLength) ledDataBuf[3 * pixel] = int(255 * rgb[0]) ledDataBuf[3 * pixel + 1] = int(255 * rgb[1]) ledDataBuf[3 * pixel + 2] = int(255 * rgb[2]) hyperion.setColor(ledDataBuf[-increment:] + ledDataBuf[:-increment]) for i1, p1 in enumerate(projectiles): for i2, p2 in enumerate(projectiles): if (p1 is not p2): prev1 = p1[0] - p1[1] prev2 = p2[0] - p2[1] if (prev1 - prev2 < 0) != (p1[0] - p2[0] < 0): for d in range(0, explodeRadius): for pixel in range(p1[0] - d, p1[0] + d): rgb = colorsys.hsv_to_rgb( random.choice([p1[2], p2[2]]), 1, (1.0 * explodeRadius - d) / explodeRadius) ledDataBuf[3 * pixel] = int(255 * rgb[0]) ledDataBuf[3 * pixel + 1] = int(255 * rgb[1]) ledDataBuf[3 * pixel + 2] = int(255 * rgb[2])
import hyperion, time # Get the rotation time color = hyperion.args.get('color', (255,255,255)) frequency = float(hyperion.args.get('frequency', 10.0)) # Check parameters frequency = min(100.0, frequency) # Compute the strobe interval sleepTime = 0.5 / frequency # Start the write data loop while not hyperion.abort(): hyperion.setColor(0, 0, 0) time.sleep(sleepTime) hyperion.setColor(color[0], color[1], color[2]) time.sleep(sleepTime)
import hyperion, time, colorsys # Get the parameters rotationTime = float(hyperion.args.get('rotation-time', 30.0)) brightness = float(hyperion.args.get('brightness', 100))/100.0 saturation = float(hyperion.args.get('saturation', 100))/100.0 reverse = bool(hyperion.args.get('reverse', False)) # Calculate the sleep time and hue increment sleepTime = 0.1 hueIncrement = sleepTime / rotationTime # Switch direction if needed if reverse: increment = -increment # Start the write data loop hue = 0.0 while not hyperion.abort(): rgb = colorsys.hsv_to_rgb(hue, saturation, brightness) hyperion.setColor(int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])) hue = (hue + hueIncrement) % 1.0 time.sleep(sleepTime)
colorIndex = 0 currentColorCount = 0 currentGapCount = 0 fillingBulb = 1 for i in range(hyperion.ledCount): if fillingBulb: ledStart = i*3 ledData[colorIndex][ledStart] = colors[colorIndex][0] ledData[colorIndex][ledStart+1] = colors[colorIndex][1] ledData[colorIndex][ledStart+2] = colors[colorIndex][2] currentColorCount += 1 if currentColorCount == bulbSize: currentColorCount = 0 if currentGapCount < gapWidth: fillingBulb = 0 colorIndex += 1 colorIndex = colorIndex % len(colors) else: currentGapCount += 1 if currentGapCount == gapWidth: fillingBulb = 1 currentGapCount = 0 # Start the write data loop # switch led array every wake time to go to next color set colorIndex = 0 while not hyperion.abort(): hyperion.setColor(ledData[colorIndex]) colorIndex = (colorIndex + 1) % len(ledData) time.sleep(interval)
import hyperion, time # Get the parameters fadeTime = float(hyperion.args.get('fade-time', 5.0)) colorStart = hyperion.args.get('color-start', (255, 174, 11)) colorEnd = hyperion.args.get('color-end', (100, 100, 100)) color_step = ((colorEnd[0] - colorStart[0]) / 256.0, (colorEnd[1] - colorStart[1]) / 256.0, (colorEnd[2] - colorStart[2]) / 256.0) # fade color calcChannel = lambda i: min(max(int(colorStart[i] + color_step[i] * step), 0), 255) for step in range(256): if hyperion.abort(): break hyperion.setColor(calcChannel(0), calcChannel(1), calcChannel(2)) time.sleep(fadeTime / 256) # maintain color until effect end hyperion.setColor(colorEnd[0], colorEnd[1], colorEnd[2]) while not hyperion.abort(): time.sleep(1)
import hyperion import time import colorsys # Get the rotation time color = hyperion.args.get('color', (255,255,255)) frequency = float(hyperion.args.get('frequency', 10.0)) # Check parameters frequency = min(100.0, frequency) # Compute the strobe interval sleepTime = 1.0 / frequency # Initialize the led data blackLedsData = bytearray(hyperion.ledCount * ( 0, 0, 0)) whiteLedsData = bytearray(hyperion.ledCount * color) # Start the write data loop while not hyperion.abort(): hyperion.setColor(blackLedsData) time.sleep(sleepTime) hyperion.setColor(whiteLedsData) time.sleep(sleepTime)
sleepTime = 0.2 random.seed(time.time()) baseHsv = [0.0, 0.0, 1.0] while not hyperion.abort(): # Move the hue and saturation randomly. # random between -1.0 and 1.0 ran = ((random.random() * 2) - 1) baseHsv[0] += ran * hue_increment * change_speed + hue_tendency baseHsv[0] %= 1.0 # random between -1.0 and 1.0 ran = ((random.random() * 2) - 1) saturation = baseHsv[1] + ran * sat_increment * change_speed # clamp between min and max baseHsv[1] = max(saturation_min, min(saturation_max, saturation)) rgb = colorsys.hsv_to_rgb(baseHsv[0], baseHsv[1], baseHsv[2]) # set colors led_data = bytearray() for i in range(hyperion.ledCount): led_data += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2]))) hyperion.setColor(led_data) # sleep for a while time.sleep(sleepTime) print baseHsv
# Get the parameters sleepTime = float(hyperion.args.get('sleepTime', 1000)) / 1000.0 length = hyperion.args.get('length', 1) color1 = hyperion.args.get('color1', (255, 255, 255)) color2 = hyperion.args.get('color2', (255, 0, 0)) # Initialize the led data i = 0 ledDataOdd = bytearray() while i < hyperion.ledCount: for l in range(length): if i < hyperion.ledCount: ledDataOdd += bytearray( (int(color1[0]), int(color1[1]), int(color1[2]))) i += 1 for l in range(length): if i < hyperion.ledCount: ledDataOdd += bytearray( (int(color2[0]), int(color2[1]), int(color2[2]))) i += 1 ledDataEven = ledDataOdd[3 * length:] + ledDataOdd[0:3 * length] # Start the write data loop while not hyperion.abort(): hyperion.setColor(ledDataOdd) time.sleep(sleepTime) hyperion.setColor(ledDataEven) time.sleep(sleepTime)
def main(): try: # use GPIO pin numbering convention GPIO.setmode(GPIO.BOARD) # set up GPIO pin for input GPIO.setup(GPIOFrontLight, GPIO.IN) GPIO.setup(GPIOSwitchAmbianceMode, GPIO.IN) GPIO.setup(GPIODimmer, GPIO.IN) GPIO.setup(GPIOFrontLight, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(GPIOSwitchAmbianceMode, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(GPIODimmer, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) frontLightStatus = 0 # 0 = off , 1 = on ambianceLightStatus = 0 # 0 = off, 1 = on ambianceMode = 0 # 0 = normal ambiance light , 1 = tv ambiance mode dimmerValue = 1 # 0 to 10 ledDataWandOn = bytearray() ledDataLampenOn = bytearray() ledDataWandOff = bytearray() ledDataLampenOff = bytearray() hsv = colorsys.rgb_to_hsv(250/255.0, 1.0, 158.0/255.0) hsvFront = colorsys.rgb_to_hsv(250.0/255.0, 1.0, 158.0/255.0) for i in range(1,151): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1]*2, 1) ledDataWandOn += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) ledDataWandOff += bytearray((0,0,0)) for i in range(1,62): rgb = colorsys.hsv_to_rgb(hsvFront[0], hsvFront[1]*2, hsvFront[2]) ledDataLampenOn += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) ledDataLampenOff += bytearray((0,0,0)) while not hyperion.abort(): # get GPIO value if GPIO.input(GPIOSwitchAmbianceMode) and ambianceMode <> 1: ambianceMode = 1 # print("Button 2 pressed") if not GPIO.input(GPIOSwitchAmbianceMode) and ambianceMode <> 0: ambianceMode = 0 # print("Button 2 released") if GPIO.input(GPIOFrontLight) and frontLightStatus <> 1: frontLightStatus = 1 # print("Button 1 pressed") if not GPIO.input(GPIOFrontLight) and frontLightStatus <> 0: frontLightStatus = 0 # print("Button 1 released") if GPIO.input(GPIODimmer): # print("DIMMER 1") timeCounter = 0 if GPIO.input(GPIODimmer) and ambianceLightStatus == 0: # print("Light on") ambianceLightStatus = 1 ledData = ledDataWandOn if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) time.sleep(0.4) while GPIO.input(GPIODimmer): timeCounter = timeCounter + 1 # print("TIME COUNTER") if timeCounter > 10: ambianceLightStatus = 0 ledData = ledDataWandOff if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) # print("Light off") time.sleep(0.1) if ambianceLightStatus == 1 and timeCounter <=10: # print("DIMMING") ledDataWandOn = bytearray() dimmerValue = dimmerValue + 1 if dimmerValue == 11: dimmerValue = 1 for i in range(1,151): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], dimmerValue/10.0) ledDataWandOn += bytearray((int(rgb[0]*255), int(rgb[1]*255), int(rgb[2]*255))) # print("Dimmdone") ledData = bytearray() if ambianceLightStatus == 1: ledData = ledData + ledDataWandOn else: ledData = ledData + ledDataWandOff if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) # wait 100ms time.sleep(0.1) # reset GPIO settings if user pressed Ctrl+C except KeyboardInterrupt: print("Execution stopped by user") GPIO.cleanup()
hsv1 = list( colorsys.rgb_to_hsv(rgb1[0] / 255.0, rgb1[1] / 255.0, rgb1[2] / 255.0)) hsv2 = list( colorsys.rgb_to_hsv(rgb2[0] / 255.0, rgb2[1] / 255.0, rgb2[2] / 255.0)) """ The effect loop """ while not hyperion.abort(): """ The algorithm to calculate the change in color """ led_data = bytearray() blend_percantages_rotated = blend_percantages[ -1 * int(rotation):] + blend_percantages[:-1 * int(rotation)] for i in range(hyperion.ledCount): blend = blend_function(rgb1, rgb2, blend_percantages_rotated[i]) led_data += bytearray((int(blend[0]), int(blend[1]), int(blend[2]))) """ send the data to hyperion """ hyperion.setColor(led_data) """ do any other stuff that needs to be done afterwards """ # set rotation rotation = (rotation + rotation_speed) % hyperion.ledCount # change colors # change hue hsv1[0] = (hsv1[0] + color1_change) % 1.0 hsv2[0] = (hsv2[0] + color2_change) % 1.0 # convert to rgb rgb1 = list(colorsys.hsv_to_rgb(hsv1[0], hsv1[1], hsv1[2])) rgb2 = colorsys.hsv_to_rgb(hsv2[0], hsv2[1], hsv2[2]) # convert rgb 0..1 to rgb 0..255 rgb1 = [int(c * 255) for c in rgb1] rgb2 = [int(c * 255) for c in rgb2] """ sleep for a while """
method = locals()[method] red = partial(method, b=color_start[0], c=color_end[0] - color_start[0], d=duration) green = partial(method, b=color_start[1], c=color_end[1] - color_start[1], d=duration) blue = partial(method, b=color_start[2], c=color_end[2] - color_start[2], d=duration) start = time.time() prev_color = None while not hyperion.abort(): current = time.time() - start color = (red(current), green(current), blue(current)) if color != prev_color: #print(color) hyperion.setColor(*color) prev_color = color time.sleep(interval) if current >= duration: break hyperion.setColor(color_end[0], color_end[1], color_end[2]) while not hyperion.abort() and maintain_color: time.sleep(1)
import hyperion import time import colorsys # Get the parameters rotationTime = float(hyperion.args.get('rotation-time', 30.0)) brightness = float(hyperion.args.get('brightness', 1.0)) saturation = float(hyperion.args.get('saturation', 1.0)) reverse = bool(hyperion.args.get('reverse', False)) # Check parameters rotationTime = max(0.1, rotationTime) brightness = max(0.0, min(brightness, 1.0)) saturation = max(0.0, min(saturation, 1.0)) # Calculate the sleep time and hue increment sleepTime = 0.1 hueIncrement = sleepTime / rotationTime # Switch direction if needed if reverse: increment = -increment # Start the write data loop hue = 0.0 while not hyperion.abort(): rgb = colorsys.hsv_to_rgb(hue, saturation, brightness) hyperion.setColor(int(255 * rgb[0]), int(255 * rgb[1]), int(255 * rgb[2])) hue = (hue + hueIncrement) % 1.0 time.sleep(sleepTime)
sleepTime = float(hyperion.args.get('speed', 1.0))*0.5 alarmColor = hyperion.args.get('alarm-color', (255,0,0)) postColor = hyperion.args.get('post-color', (255,174,11)) off = bool(hyperion.args.get('shutdown-enabled', False)) width = 12 height = 10 imageData = bytearray(height * width * (0,0,0)) # Start the write data loop for i in range(6): if hyperion.abort(): off = False break if i % 2: hyperion.setColor(alarmColor[0], alarmColor[1], alarmColor[2]) else: hyperion.setColor(0, 0, 0) time.sleep(sleepTime) for y in range(height,0,-1): if hyperion.abort(): off = False break for x in range(width): setPixel(x, y-1, alarmColor) hyperion.setImage(width, height, imageData) time.sleep(sleepTime) time.sleep(1) for y in range(height):
def main(): try: # use GPIO pin numbering convention GPIO.setmode(GPIO.BOARD) # set up GPIO pin for input GPIO.setup(GPIOFrontLight, GPIO.IN) GPIO.setup(GPIOSwitchAmbianceMode, GPIO.IN) GPIO.setup(GPIODimmer, GPIO.IN) GPIO.setup(GPIOFrontLight, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(GPIOSwitchAmbianceMode, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(GPIODimmer, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) frontLightStatus = 0 # 0 = off , 1 = on ambianceLightStatus = 0 # 0 = off, 1 = on ambianceMode = 0 # 0 = normal ambiance light , 1 = tv ambiance mode dimmerValue = 1 # 0 to 10 ledDataWandOn = bytearray() ledDataLampenOn = bytearray() ledDataWandOff = bytearray() ledDataLampenOff = bytearray() hsv = colorsys.rgb_to_hsv(250 / 255.0, 1.0, 158.0 / 255.0) hsvFront = colorsys.rgb_to_hsv(250.0 / 255.0, 1.0, 158.0 / 255.0) for i in range(1, 151): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1] * 2, 1) ledDataWandOn += bytearray( (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))) ledDataWandOff += bytearray((0, 0, 0)) for i in range(1, 62): rgb = colorsys.hsv_to_rgb(hsvFront[0], hsvFront[1] * 2, hsvFront[2]) ledDataLampenOn += bytearray( (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))) ledDataLampenOff += bytearray((0, 0, 0)) while not hyperion.abort(): # get GPIO value if GPIO.input(GPIOSwitchAmbianceMode) and ambianceMode <> 1: ambianceMode = 1 # print("Button 2 pressed") if not GPIO.input(GPIOSwitchAmbianceMode) and ambianceMode <> 0: ambianceMode = 0 # print("Button 2 released") if GPIO.input(GPIOFrontLight) and frontLightStatus <> 1: frontLightStatus = 1 # print("Button 1 pressed") if not GPIO.input(GPIOFrontLight) and frontLightStatus <> 0: frontLightStatus = 0 # print("Button 1 released") if GPIO.input(GPIODimmer): # print("DIMMER 1") timeCounter = 0 if GPIO.input(GPIODimmer) and ambianceLightStatus == 0: # print("Light on") ambianceLightStatus = 1 ledData = ledDataWandOn if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) time.sleep(0.4) while GPIO.input(GPIODimmer): timeCounter = timeCounter + 1 # print("TIME COUNTER") if timeCounter > 10: ambianceLightStatus = 0 ledData = ledDataWandOff if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) # print("Light off") time.sleep(0.1) if ambianceLightStatus == 1 and timeCounter <= 10: # print("DIMMING") ledDataWandOn = bytearray() dimmerValue = dimmerValue + 1 if dimmerValue == 11: dimmerValue = 1 for i in range(1, 151): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], dimmerValue / 10.0) ledDataWandOn += bytearray( (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))) # print("Dimmdone") ledData = bytearray() if ambianceLightStatus == 1: ledData = ledData + ledDataWandOn else: ledData = ledData + ledDataWandOff if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) # wait 100ms time.sleep(0.1) # reset GPIO settings if user pressed Ctrl+C except KeyboardInterrupt: print("Execution stopped by user") GPIO.cleanup()
ledData0 += bytearray((int(255), int(255), int(255))) if i%3 == 2: ledData0 += bytearray((int(0), int(255), int(0))) ledData1 = bytearray() for i in range(hyperion.ledCount): if i%3 == 0: ledData1 += bytearray((int(255), int(255), int(255))) if i%3 == 1: ledData1 += bytearray((int(0), int(255), int(0))) if i%3 == 2: ledData1 += bytearray((int(255), int(0), int(0))) ledData2 = bytearray() for i in range(hyperion.ledCount): if i%3 == 0: ledData2 += bytearray((int(0), int(255), int(0))) if i%3 == 1: ledData2 += bytearray((int(255), int(0), int(0))) if i%3 == 2: ledData2 += bytearray((int(255), int(255), int(255))) # Start the write data loop while not hyperion.abort(): hyperion.setColor(ledData0) time.sleep(sleepTime) hyperion.setColor(ledData1) time.sleep(sleepTime) hyperion.setColor(ledData2) time.sleep(sleepTime)
percentage = max(1, min(percentage, 100)) # Process parameters factor = percentage / 100.0 hsv = colorsys.rgb_to_hsv(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0) # Initialize the led data snakeLeds = max(1, int(hyperion.ledCount * factor)) ledData = bytearray() for i in range(hyperion.ledCount - snakeLeds): ledData += bytearray((0, 0, 0)) for i in range(1, snakeLeds + 1): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1], hsv[2] / i) ledData += bytearray((int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))) # Calculate the sleep time and rotation increment increment = 3 sleepTime = rotationTime / hyperion.ledCount while sleepTime < 0.05: increment *= 2 sleepTime *= 2 increment %= hyperion.ledCount # Start the write data loop while not hyperion.abort(): hyperion.setColor(ledData) ledData = ledData[increment:] + ledData[:increment] time.sleep(sleepTime)
import hyperion, time # Get the rotation time color = hyperion.args.get('color', (255, 255, 255)) frequency = float(hyperion.args.get('frequency', 10.0)) # Check parameters frequency = min(100.0, frequency) # Compute the strobe interval sleepTime = 1.0 / frequency # Start the write data loop while not hyperion.abort(): hyperion.setColor(0, 0, 0) time.sleep(sleepTime) hyperion.setColor(color[0], color[1], color[2]) time.sleep(sleepTime)
-colorDataIncrement * numberOfRotates:] + colorData[:-colorDataIncrement * numberOfRotates] baseColorChangeStepCount += 1 # Calculate new colors for i in range(hyperion.ledCount): amplitude = max( 0.0, math.sin(-amplitudePhase + 2 * math.pi * blobs * i / hyperion.ledCount)) colors[3 * i + 0] = int(colorData[3 * i + 0] * amplitude) colors[3 * i + 1] = int(colorData[3 * i + 1] * amplitude) colors[3 * i + 2] = int(colorData[3 * i + 2] * amplitude) # set colors hyperion.setColor(colors) # increment the phase amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2 * math.pi) if rotateColors: colorData = colorData[ -colorDataIncrement:] + colorData[:-colorDataIncrement] numberOfRotates = (numberOfRotates + 1) % hyperion.ledCount rotateColors = not rotateColors # sleep for a while time.sleep(sleepTime)
def main(): try: # use GPIO pin numbering convention GPIO.setmode(GPIO.BOARD) # set up GPIO pin for input GPIO.setup(GPIOFrontLight, GPIO.IN) GPIO.setup(GPIOSwitchAmbianceMode, GPIO.IN) GPIO.setup(GPIODimmer, GPIO.IN) GPIO.setup(GPIOFrontLight, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(GPIOSwitchAmbianceMode, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(GPIODimmer, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) frontLightStatus = 0 # 0 = off , 1 = on ambianceLightStatus = 0 # 0 = off, 1 = on ambianceMode = 0 # 0 = normal ambiance light , 1 = tv ambiance mode dimmerValue = 10 # 0 to 10 UDP_IP = "" UDP_PORT = 8888 sock = socket.socket( socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((UDP_IP, UDP_PORT)) sock.settimeout(0.3) ledDataWandOn = bytearray() ledDataLampenOn = bytearray() ledDataWandOff = bytearray() ledDataLampenOff = bytearray() hsv = colorsys.rgb_to_hsv(250 / 255.0, 1.0, 158.0 / 255.0) hsvFront = colorsys.rgb_to_hsv(250.0 / 255.0, 1.0, 158.0 / 255.0) for i in range(1, 152): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1] * 2, 1) ledDataWandOn += bytearray( (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))) ledDataWandOff += bytearray((0, 0, 0)) for i in range(1, 61): rgb = colorsys.hsv_to_rgb(hsvFront[0], hsvFront[1] * 2, hsvFront[2]) ledDataLampenOn += bytearray( (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))) ledDataLampenOff += bytearray((0, 0, 0)) while not hyperion.abort(): # get GPIO value if GPIO.input(GPIOSwitchAmbianceMode) and ambianceMode <> 1: ambianceMode = 1 time.sleep(0.2) print("Button 2 pressed") if not GPIO.input(GPIOSwitchAmbianceMode) and ambianceMode <> 0: ambianceMode = 0 ambianceLightStatus = 0 time.sleep(0.2) print("Button 2 released") if GPIO.input(GPIOFrontLight) and frontLightStatus <> 1: frontLightStatus = 1 time.sleep(0.2) print("Button 1 pressed") if not GPIO.input(GPIOFrontLight) and frontLightStatus <> 0: frontLightStatus = 0 time.sleep(0.2) print("Button 1 released") if GPIO.input(GPIODimmer): print("DIMMER 1") timeCounter = 0 if GPIO.input(GPIODimmer) and ambianceLightStatus == 0: print("Light on") ambianceLightStatus = 1 ledData = ledDataWandOn if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) time.sleep(0.4) while GPIO.input(GPIODimmer): timeCounter = timeCounter + 1 print("TIME COUNTER") if timeCounter > 10: ambianceLightStatus = 0 ledData = ledDataWandOff if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) # print("Light off") time.sleep(0.1) if ambianceLightStatus == 1 and timeCounter <= 10: print("DIMMING") ledDataWandOn = bytearray() dimmerValue = dimmerValue - 1 if dimmerValue == -1: dimmerValue = 10 for i in range(1, 152): rgb = colorsys.hsv_to_rgb(hsv[0], hsv[1] * 2, dimmerValue / 10.0) ledDataWandOn += bytearray( (int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))) print("Dimmdone") ledData = bytearray() sleepTime = 0.1 if ambianceMode == 1: srgb = bytearray(152 * 3) try: number, addr = sock.recvfrom_into(srgb) # buffer size is ledDataServer = bytearray() for i in range(1, number - 3, 3): ledDataServer += bytearray( (srgb[i + 2], srgb[i], srgb[i + 1])) ledData = ledData + ledDataServer sleepTime = 0.01 except socket.timeout: ledData = ledData + ledDataWandOff else: if ambianceLightStatus == 1: ledData = ledData + ledDataWandOn else: ledData = ledData + ledDataWandOff if frontLightStatus == 1: ledData = ledData + ledDataLampenOn else: ledData = ledData + ledDataLampenOff hyperion.setColor(ledData) # wait 100ms time.sleep(sleepTime) # reset GPIO settings if user pressed Ctrl+C except KeyboardInterrupt: print("Execution stopped by user") GPIO.cleanup()