def appear_from_back(pixels, color=(255, 0, 0)): pos = 0 for i in range(pixels.count()): for j in reversed(range(i, pixels.count())): pixels.clear() # first set all pixels at the begin for k in range(i): pixels.set_pixel( k, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) # set then the pixel at position j pixels.set_pixel( j, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) pixels.show() time.sleep(0.02)
def running_on_chain(pixels, basecolor=(255, 255, 255), runningcolor=(255, 0, 0), number_of_running=(5), sleep_time=(0.1)): global do_run for i in range(pixels.count()): pixels.set_pixel( i, Adafruit_WS2801.RGB_to_color(basecolor[0], basecolor[1], basecolor[2])) pixels.show() for i in range(pixels.count()): if i + number_of_running >= pixels.count(): break for k in range(pixels.count()): pixels.set_pixel( k, Adafruit_WS2801.RGB_to_color(basecolor[0], basecolor[1], basecolor[2])) for j in range(i, i + number_of_running): pixels.set_pixel( j, Adafruit_WS2801.RGB_to_color(runningcolor[0], runningcolor[1], runningcolor[2])) pixels.show() time.sleep(sleep_time)
def burning(pixels, basecolor=(100, 20, 0), number_of_running=15): setalltocolor(pixels, (int(basecolor[0]), int(basecolor[1]), int(basecolor[2]))) startpixel = randrange(0, PIXEL_COUNT - number_of_running) for i in range(0, 100): ###maximum all pixels - number of changed brightness(pixels, (startpixel, startpixel + number_of_running), 1, "increase", (None, "g", "b")) pixels.set_pixel(randrange(startpixel, startpixel + number_of_running), Adafruit_WS2801.RGB_to_color( 255, 255, 26)) #set a random pixel to yellow time.sleep(0.2) for j in range(0, 100): brightness(pixels, (startpixel, startpixel + number_of_running), 1, "decrease", (None, "g", "b")) pixels.set_pixel(randrange(startpixel, startpixel + number_of_running), Adafruit_WS2801.RGB_to_color( 255, 255, 26)) #set a random pixel to yellow time.sleep(0.1) print("decreased spot") for j in range(0, 60): brightness(pixels, (0, PIXEL_COUNT), 1, "decrease", (None, "g", "b")) time.sleep(0.0) print("decreased all") for j in range(0, 60): brightness(pixels, (0, PIXEL_COUNT), 1, "increase", (None, "g", "b")) time.sleep(0.2) print("increased all")
def appear_from_end(self, color=(255, 0, 0), reverse=False): pos = 0 jump = 1 start = 0 end = self.length - 1 order = range(start, end, jump) if reverse: order.reverse() jump = -1 start = self.length - 1 end = 0 for i in order: old_j = end for j in (range(end, i - jump, 0 - jump)): #pixels.clear() # first set all pixels at the begin #for k in range(start, i, jump): # pixels.set_pixel(self.index[k], # Adafruit_WS2801.RGB_to_color( color[0], color[1], # color[2] )) pixels.set_pixel(self.index[old_j], Adafruit_WS2801.RGB_to_color(0, 0, 0)) # set then the pixel at position j pixels.set_pixel( self.index[j], Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) pixels.show() #print(j, old_j) old_j = j time.sleep(0.05) yield
def one_side(pixels): for i in range(pixels.count()): if i % 20 < 10: pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 84, 3)) else: pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(128, 0, 0)) pixels.show()
def appear_from_end_rgb(pixels, index, color=(255, 0, 0), steps=25, reverse=False): '''Chases a 'pixel' from one end, to the other, where it remains illuminated. Thus as as each 'chase' ends one more pixel is permemanly illuminated until the entire string is illuminated. The hard part here is going to be how to work out how to complete this in a set number of steps as it naturally has n(n+1)/2 steps where n is no. of pixels''' pos = 0 jump = 1 start = 0 end = len(index) -1 order = range(start,end,jump) if reverse: order.reverse() jump =-1 start = len(index) -1 end = 0 for i in order: old_j = end for j in (range(end, i-jump, 0 - jump)): pixels.set_pixel(index[old_j], Adafruit_WS2801.RGB_to_color( 0,0,0 )) # set then the pixel at position j pixels.set_pixel(index[j], Adafruit_WS2801.RGB_to_color( color[0], color[1], color[2] )) pixels.show() #print(j, old_j) old_j = j time.sleep(0.02) yield
def xmas_eight_party(wait=4): for i in range(0, 8): ga_Listening() ga_Responding() phone_Ring(pixels) pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 0, 0)) pixels.show() #if wait > 0.0: #time.sleep(wait) for i in range(8, 16): ga_Listening() ga_Responding() phone_Ring(pixels) pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(0, 255, 0)) pixels.show() #if wait > 0.0: #time.sleep(wait) for i in range(16, 24): ga_Listening() ga_Responding() phone_Ring(pixels) pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(255, 0, 0)) pixels.show() #if wait > 0.0: #time.sleep(wait) for i in range(24, 32): ga_Listening() ga_Responding() phone_Ring(pixels) pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(0, 255, 0)) pixels.show() if wait > 0.0: time.sleep(wait)
def wheel_rgb(self, pos): if pos < 85: return Adafruit_WS2801.RGB_to_color(255, 0, 0) elif pos < 170: return Adafruit_WS2801.RGB_to_color(0, 255, 0) else: return Adafruit_WS2801.RGB_to_color(0, 0, 255)
def checker_board(pixels=pixels, blink_times=5, wait=0.005, color=(255, 0, 0)): if args.verbosity > 1: print("blink_color(pixels={p},blink_times={b},wait={w},color={c})". format(p=pixels, b=blink_times, w=wait, c=[color[0], color[1], color[2]])) for i in range(blink_times): # blink two times, then wait pixels.clear() for j in range(2): for k in range(pixels.count()): if k % 2 == 1: pixels.set_pixel( k, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) else: pixels.set_pixel(k, Adafruit_WS2801.RGB_to_color(0, 0, 0)) pixels.show() time.sleep(0.08) pixels.clear() for k in range(pixels.count()): if k % 2 == 0: pixels.set_pixel( k, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) else: pixels.set_pixel(k, Adafruit_WS2801.RGB_to_color(0, 0, 0)) pixels.show() time.sleep(0.08) pixels.clear() time.sleep(wait)
def blue_one_by_one(pixels, wait=0.005, color=(0, 0, 255)): start = time.time() turned_off = False while True: #pos = 0 if not turned_off and time.time() > (start + SHUT_DOWN): sequence_off1() turned_off = True sequence_off() else: for i in range(pixels.count()): for j in reversed(range(i, pixels.count())): ga_Listening() ga_Responding() phone_Ring(pixels) pixels.clear() # first set all pixels at the begin for k in range(i): ga_Listening() ga_Responding() phone_Ring(pixels) pixels.set_pixel( k, Adafruit_WS2801.RGB_to_color( color[0], color[1], color[2])) # set then the pixel at position j pixels.set_pixel( j, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) pixels.show() if wait > 0: time.sleep(wait)
def check_rauswerfen(neuer_standort): if neuer_standort is standort_rot: # rot wird rausgekegelt standort_rot = START_ROT pixels.set_pixel(spielfeld_leds.get(standort_rot), Adafruit_WS2801.RGB_to_color(50, 0, 0)) pixels.show() sleep(0.2) # warte kurz elif neuer_standort is standort_blau: # blau wird rausgekegelt standort_blau = START_BLAU pixels.set_pixel(spielfeld_leds.get(standort_blau), Adafruit_WS2801.RGB_to_color(0, 0, 50)) pixels.show() sleep(0.2) # warte kurz elif neuer_standort is standort_gelb: # gelb wird rausgekegelt standort_gelb = START_GELB pixels.set_pixel(spielfeld_leds.get(standort_gelb), Adafruit_WS2801.RGB_to_color(50, 50, 0)) pixels.show() sleep(0.2) # warte kurz elif neuer_standort is standort_gruen: # gruen wird rausgekegelt standort_gruen = START_GRUEN pixels.set_pixel(spielfeld_leds.get(standort_gruen), Adafruit_WS2801.RGB_to_color(0, 50, 0)) pixels.show() sleep(0.2) # warte kurz
def blink_color(pixels, blink_times=5, wait=0.1, color=(255, 0, 0)): step = 1 for i in range(blink_times): # blink two times, then wait pixels.clear() for j in range(2): for k in range(pixels.count()): pixels.set_pixel( k, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) pixels.show() time.sleep(0.08) pixels.clear() pixels.show() time.sleep(0.08) time.sleep(wait) for k in range(pixels.count()): pixels.set_pixel( k, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) pixels.show() for j in range(int(256 // step)): for i in range(pixels.count()): r, g, b = pixels.get_pixel_rgb(i) r = int(max(0, r - step)) g = int(max(0, g - step)) b = int(max(0, b - step)) pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(r, g, b)) pixels.show() if wait > 0: time.sleep(0.01)
def appear_from_back_blocking(pixels=Pixels, color="changing", step=1, wait=0.02): pos = 0 if color == "changing": change = True else: change = False for i in range(0, pixels.count(), step): for j in reversed(range(i, pixels.count() - step + 1, step)): pixels.clear() # first set all pixels at the begin for k in range(i): if change: pixels.set_pixel( k, wheel(((k * 256 // pixels.count())) % 256)) else: pixels.set_pixel( k, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) # set then the pixel at position j if change: for l in range(j, j + step): pixels.set_pixel( l, wheel(((j * 256 // pixels.count())) % 256)) else: for l in range(j, j + step): pixels.set_pixel( l, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) pixels.show() time.sleep(wait)
def brightness(pixels, affected_pixels=(0, PIXEL_COUNT), step=1, dec_or_inc="decrease", exclude_color=(None, None, None)): # for j in range(int(256 // step)): if dec_or_inc == "decrease": for i in range(affected_pixels[0], affected_pixels[1]): r, g, b = pixels.get_pixel_rgb(i) if not "r" in exclude_color: r = int(r - step) if not "g" in exclude_color: g = int(g - step) if not "b" in exclude_color: b = int(b - step) pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(r, g, b)) if dec_or_inc == "increase": for i in range(affected_pixels[0], affected_pixels[1]): r, g, b = pixels.get_pixel_rgb(i) if not "r" in exclude_color: r = int(r + step) if not "g" in exclude_color: g = int(g + step) if not "b" in exclude_color: b = int(b + step) pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(r, g, b))
def on_print_progress(self, storage, path, progress): for x in range(PROGRESSBAR): pixels.set_pixel(x, Adafruit_WS2801.RGB_to_color(0, 0, 255)) pixels.set_pixel((PROGRESSBAR - 1 - (progress * PROGRESSBAR / 100)), Adafruit_WS2801.RGB_to_color(0, 255, 0)) if progress == 100: for y in range(PROGRESSBAR): pixels.set_pixel(y, Adafruit_WS2801.RGB_to_color(255, 0, 0)) pixels.show()
def rotate_color(self, r, g, b, rotate_times): for j in range(rotate_times): self.pixels.clear() for i in range(self.pixels.count()): if i > 1: self.pixels.set_pixel(i - 2, Adafruit_WS2801.RGB_to_color(0, 0, 0)) self.pixels.set_pixel(i, Adafruit_WS2801.RGB_to_color(r, b, g)) time.sleep(0.05) self.pixels.show()
def wheel(pos): if pos < 85: return Adafruit_WS2801.RGB_to_color(pos * 3, 255 - pos * 3, 0) elif pos < 170: pos -= 85 return Adafruit_WS2801.RGB_to_color(255 - pos * 3, 0, pos * 3) else: pos -= 170 return Adafruit_WS2801.RGB_to_color(0, pos * 3, 255 - pos * 3)
def test(): global pixels clear() for j in range(LED_COUNT): if j % 2 == 0: pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color(255, 0, 0)) else: pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color(0, 0, 255)) pixels.show() time.sleep(10)
def wheel(pos): """The wheel function to interpolate between different hues""" if pos < 85: return Adafruit_WS2801.RGB_to_color(pos * 3, 255 - pos * 3, 0) elif pos < 170: pos -= 85 return Adafruit_WS2801.RGB_to_color(255 - pos * 3, 0, pos * 3) else: pos -= 170 return Adafruit_WS2801.RGB_to_color(0, pos * 3, 255 - pos * 3)
def face(pixels, lefteye, righteye, mouth): mouthcolor = Adafruit_WS2801.RGB_to_color(mouth[0], mouth[1], mouth[2]) for i in range(0, pixels.count() - 2): pixels.set_pixel(i, mouthcolor) pixels.set_pixel( pixels.count() - 1, Adafruit_WS2801.RGB_to_color(lefteye[0], lefteye[1], lefteye[2])) pixels.set_pixel( pixels.count() - 2, Adafruit_WS2801.RGB_to_color(righteye[0], righteye[1], righteye[2])) pixels.show()
def move_out(wait_time=0.05): for i in range(pixels.count()): for j in reversed(xrange(i)): pixels.clear() # first set all pixels at the end for k in range(i, pixels.count()): pixels.set_pixel(k, Adafruit_WS2801.RGB_to_color(*color)) # set then the pixel at position j pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color(*color)) pixels.show() time.sleep(wait_time)
def final_warning_lights(pixels): color = [254, 0, 0] #red r1 = color[0] * MAX_INTENSITY / 255 g1 = color[1] * MAX_INTENSITY / 255 b1 = color[2] * MAX_INTENSITY / 255 pixels.clear() for j in range(PIXEL_COUNT): pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color(r1, g1, b1)) pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color(r1, g1, b1)) pixels.show() time.sleep(0.2)
def timer_interval_lights(pixels): color = [46, 139, 87] #seagreen r1 = color[0] * MAX_INTENSITY / 255 g1 = color[1] * MAX_INTENSITY / 255 b1 = color[2] * MAX_INTENSITY / 255 pixels.clear() for j in range(PIXEL_COUNT): pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color(r1, g1, b1)) pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color(r1, g1, b1)) pixels.show() time.sleep(0.2)
def wheel(pos, spread): pos = pos % spread band = spread / 3.0 if pos < band: return Adafruit_WS2801.RGB_to_color(pos, int(band - pos), 0) elif pos < (2 * band): pos -= int(band) return Adafruit_WS2801.RGB_to_color(int(band - pos), 0, pos) else: pos -= int(2 * band) return Adafruit_WS2801.RGB_to_color(0, pos, int(band - pos))
def color(pos): if 0*85 <= pos < 1*85: cval = (pos - 0*85) * 3 return Adafruit_WS2801.RGB_to_color(cval, 255 - cval, 0) if 1*85 <= pos < 2*85: cval = (pos - 1*85) * 3 return Adafruit_WS2801.RGB_to_color(255 - cval, 0, cval) if 2*85 <= pos < 3*85: cval = (pos - 2*85) * 3 return Adafruit_WS2801.RGB_to_color(0, cval, 255 - cval)
def set_leds(): for led in range(0, 86): output = Adafruit_WS2801.RGB_to_color(0, 0, 0) ws2801.pixels.set_pixel(led, output) for led in range(86, 200): color = Adafruit_WS2801.RGB_to_color(red, blue, green) ws2801.pixels.set_pixel(led, color) ws2801.pixels.show() time.sleep(0.1) ws2801.pixels.show()
def wheel(pos): """ Wheel method to generate all the RGB colors for rainbow effects """ if pos < 85: return Adafruit_WS2801.RGB_to_color(pos * 3, 255 - pos * 3, 0) elif pos < 170: pos -= 85 return Adafruit_WS2801.RGB_to_color(255 - pos * 3, 0, pos * 3) else: pos -= 170 return Adafruit_WS2801.RGB_to_color(0, pos * 3, 255 - pos * 3)
def one_at_a_time(pixels, wait=0.9, color=(255, 0, 0)): pixels.clear() for i in range(pixels.count()): for j in range(pixels.count()): if i != j: pixels.set_pixel(j, Adafruit_WS2801.RGB_to_color(0, 0, 0)) else: pixels.set_pixel( j, Adafruit_WS2801.RGB_to_color(color[0], color[1], color[2])) pixels.show() if wait > 0: time.sleep(wait)
def wheel(pos, intensity=0.1): if pos < 85: return Adafruit_WS2801.RGB_to_color(int(pos * 3 * intensity), int((255 - pos * 3) * intensity), 0) elif pos < 170: pos -= 85 return Adafruit_WS2801.RGB_to_color(int((255 - pos * 3) * intensity), 0, int(pos * 3 * intensity)) else: pos -= 170 return Adafruit_WS2801.RGB_to_color(0, int(pos * 3 * intensity), int((255 - pos * 3) * intensity))
def _color_wheel(wheelPos): wheelPos = 255 - wheelPos if (wheelPos < 85): return Adafruit_WS2801.RGB_to_color(255 - wheelPos * 3, 0, wheelPos * 3) if (wheelPos < 170): wheelPos -= 85 return Adafruit_WS2801.RGB_to_color(0, wheelPos * 3, 255 - wheelPos * 3) wheelPos -= 170 return Adafruit_WS2801.RGB_to_color(wheelPos * 3, 255 - wheelPos * 3, 0)