def run(self): while self.updating: for i in range(0,self.CONST_LED_COUNT): self.diodes[i].update() ws2812.write2812(self.spi, self.get_array()) #self.counter(self.delay) time.sleep(self.delay)
def test_gauss(spi, shape=(8, 8), intensity=20): stepTime = 0.05 nLED = shape[0] * shape[1] index_i = numpy.array(range(nLED)) % shape[0] index_j = numpy.array(range(nLED)) / shape[0] mid_i = shape[0] / 2. mid_j = shape[1] / 2. period_i, period_j = 3, 3.1 ri, rj = 2, 2 tStart = time.time() try: while True: t = time.time() - tStart mi = mid_i + sin(2 * pi * t / period_i) * ri mj = mid_j + sin(2 * pi * t / period_j) * rj rg0 = 2 * (sin(2 * pi * t / 6.25) + 1) rg1 = 2 * (sin(2 * pi * t / 6.5) + 1) rg2 = 2 * (sin(2 * pi * t / 6.75) + 1) distances2 = ((index_i - mi)**2 + (index_j - mj)**2) d = numpy.zeros((nLED, 3)) d[:, 0] = exp(-distances2 / rg0**2) d[:, 1] = exp(-distances2 / rg1**2) d[:, 2] = exp(-distances2 / rg2**2) di = numpy.array(d * intensity, dtype=numpy.uint32) ws2812.write2812(spi, di) time.sleep(stepTime) except KeyboardInterrupt: ws2812.write2812(spi, [[0, 0, 0]] * (shape[0] * shape[1]))
def test_loop(spi, nLED=8, intensity=20): stepTime = 0.1 iStep = 0 while True: d = [[0, 0, 0]] * nLED d[iStep % nLED] = [intensity] * 3 ws2812.write2812(spi, d) iStep = (iStep + 1) % nLED time.sleep(stepTime)
def signal_handler(sig, frame): print('You pressed Ctrl+C!') #clear leds data = numpy.zeros((PIXELS, 3), dtype=numpy.uint8) ws2812.write2812(spi, data) #stop audio stream.stop_stream() stream.close() p.terminate() sys.exit(0)
def wave(spi, nLED, intencity): t=wave_tStart-time.time() #t=1.1 f=numpy.zeros((nLED,3)) f[:,0]=numpy.sin(2*numpy.pi*t/wave_period0+wave_indices) f[:,1]=numpy.sin(2*numpy.pi*t/wave_period1+wave_indices) f[:,2]=numpy.sin(2*numpy.pi*t/wave_period2+wave_indices) f=(intencity)*((f+1.0)/2.0) fi=numpy.array(f, dtype=numpy.uint8) #print fi[0] #time_write2812(spi, fi) ws2812.write2812(spi, fi) time.sleep(0.01)
def show_light_first_inverse(wait_time, color='None'): signal_list = [[0, 0, 0]] * 8 on_color = set_color(color) try: for i in range(7, -1, -1): signal_list[i] = on_color write2812(spi, signal_list) time.sleep(wait_time) signal_list[i] = set_color('None') write2812(spi, signal_list) except: print("ERROR ouccurs in first led")
def test_heart(spi, shape=(8, 8), intensity=20): stepTime = 0.05 nLED = shape[0] * shape[1] index_i = numpy.array(range(nLED)) % shape[0] index_j = numpy.array(range(nLED)) / shape[0] mid_i = shape[0] / 2. mid_j = shape[1] / 2. period_i, period_j = 3, 3.1 ri, rj = 1.5, 1.5 #2,2 tStart = time.time() try: while True: t = time.time() - tStart mi = mid_i + sin(2 * pi * t / period_i) * ri - 2 mj = mid_j + sin(2 * pi * t / period_j) * rj rg0 = 2 * (sin(2 * pi * t / 6.25) + 1) rg1 = 2 * (sin(2 * pi * t / 6.5) + 1) rg2 = 2 * (sin(2 * pi * t / 6.75) + 1) distances2 = ((index_i - mi)**2 + (index_j - mj)**2) angles = numpy.abs(numpy.arctan2(index_j - mj, index_i - mi)) heart = (angles**.5 + 5 / (0.01 + abs(angles - numpy.pi))**2) / (1 * numpy.pi**.5) distances2 *= heart d = numpy.zeros((nLED, 3)) d[:, 0] = exp(-(distances2 / rg0**2)**2) d[:, 1] = exp(-(distances2 / rg1**2)**2) d[:, 2] = exp(-(distances2 / rg2**2)**2) #rg0=1.5 #d[:,0]=distances2<rg0*2 #d[:,1]=distances2<rg0*2 #d[:,2]=distances2<rg0*2 di = numpy.array(d * intensity, dtype=numpy.uint32) ws2812.write2812(spi, di) time.sleep(stepTime) except KeyboardInterrupt: ws2812.write2812(spi, [[0, 0, 0]] * (shape[0] * shape[1]))
def test_pattern_sin(spi, nLED=8, intensity=20): tStart = time.time() indices = 4 * numpy.array(range(nLED), dtype=numpy.uint32) * numpy.pi / nLED period0 = 2 period1 = 2.1 period2 = 2.2 try: while True: t = tStart - time.time() #t=1.1 f = numpy.zeros((nLED, 3)) f[:, 0] = sin(2 * pi * t / period0 + indices) f[:, 1] = sin(2 * pi * t / period1 + indices) f[:, 2] = sin(2 * pi * t / period2 + indices) f = (intensity) * ((f + 1.0) / 2.0) fi = numpy.array(f, dtype=numpy.uint8) #print fi[0] #time_write2812(spi, fi) ws2812.write2812(spi, fi) time.sleep(0.01) except KeyboardInterrupt: test_off(spi, nLED)
def test_off(spi, nLED): """ Clears LED to show blank """ ws2812.write2812(spi, [[0, 0, 0] * nLED])
frames_per_buffer=CHUNK) def signal_handler(sig, frame): print('You pressed Ctrl+C!') #clear leds data = numpy.zeros((PIXELS, 3), dtype=numpy.uint8) ws2812.write2812(spi, data) #stop audio stream.stop_stream() stream.close() p.terminate() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) out = numpy.zeros((PIXELS, 3), dtype=int) while True: #for i in range(int(10*44100/1024)): #go for a few seconds data = numpy.fromstring(stream.read(CHUNK), dtype=numpy.int16) #peak=np.average(np.abs(data))*2 #bars="#"*int(50*peak/2**16) peak = numpy.amax(numpy.abs(data)) bars = "#" * int(peak / 200) #print("%04d %05d %s"%(i,peak,bars)) #print("%05d %s"%(peak,bars)) out.fill(0) out[0:int(peak / 200)] = (100, 0, 0) ws2812.write2812(spi, out)
def neopixels_off(): ws2812.write2812(spi, [[0, 0, 0]] * 16)
164, 167, 169, 171, 173, 175, 177, 180, 182, 184, 186, 189, 191, 193, 196, 198, 200, 203, 205, 208, 210, 213, 215, 218, 220, 223, 225, 228, 231, 233, 236, 239, 241, 244, 247, 249, 252, 255) def gamma(c): r = max(min(int(c[0]), 255), 0) g = max(min(int(c[1]), 255), 0) b = max(min(int(c[2]), 255), 0) return (r, g, b) data = numpy.zeros((PIXELS, 3), dtype=numpy.uint8) while True: t = time.time() / VELOCITY for i in range(PIXELS): #h = (i/PIXELS + t) % 1.0 #data[i] = gamma(colorsys.hsv_to_rgb(h, 1.0, BRIGHTNESS)) m = t * 10 p = 7 p2 = 5 v = math.sin(m + (i / p)) v2 = math.sin((-m) + (i / p)) v3 = math.sin(m * 3.5 + (i / p2)) r = (v + 1) / 2 g = (v2 + 1) / 2 b = (v3 + 1) / 2 data[i] = gamma([r * 255, g * 255, b * 255]) ws2812.write2812(spi, data) time.sleep(0.05)
def signal_handler(sig, frame): print('You pressed Ctrl+C!') data = numpy.zeros((PIXELS, 3), dtype=numpy.uint8) ws2812.write2812(spi, data) sys.exit(0)
#!/usr/bin/python import spidev import ws2812 spi = spidev.SpiDev() spi.open(1,0) #write 4 WS2812's, with the following colors: red, green, blue, yellow #def qwe(i): # ws2812.write2812(spi, [[1,1,1]]) # print i #i = 10 #while True: # i += 1 # qwe(i) ws2812.write2812(spi, [[0,0,40], [0,40,0], [40,0,0], [1,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0]]) #for i in range(10): # qwe()
def rvb(spi, nLED, intencity): ws2812.write2812(spi, [(intencity/3, intencity, intencity/9)]*nLED)
def neopixels_green(): ws2812.write2812(spi, [[5, 0, 0]] * 16)
import spidev import ws2812 from random import randint import time spi = spidev.SpiDev() spi.open(0,0) N = 10 # g r b pixels = [] for x in range(0, 10): pixels.append([0, 0, 0]) while True: for i in range(0, N): pixels[i] = [randint(0, 64), randint(0, 64), randint(0, 64)] ws2812.write2812(spi, pixels) time.sleep(0.1)
import spidev import ws2812 spi = spidev.SpiDev() spi.open(0,0) #write 4 WS2812's, with the following colors: red, green, blue, yellow ws2812.write2812(spi, [[10,0,0], [0,10,0], [0,0,10], [10, 10, 0]])
def neopixels_yellow(): ws2812.write2812(spi, [[5, 5, 0]] * 16)
def neopixels_white(): ws2812.write2812(spi, [[3, 3, 3]] * 16)
def neopixels_blue(): ws2812.write2812(spi, [[0, 0, 5]] * 16)
def neopixels_red(): ws2812.write2812(spi, [[0, 5, 0]] * 16)
def show(): ws2812.write2812(_spi, _cols)
def white(spi, nLED, intencity): ws2812.write2812(spi, [(intencity, intencity, intencity)]*nLED)
def clock(time, Led_old): Led_data = Led_list(time) if Led_old != Led_data: ws2812.write2812(spi, Led_data) return Led_data
def test_off(spi, nLED): ws2812.write2812(spi, [0, 0, 0] * nLED)