def lightShow(jumpVal, jumpPR): heightVal = 10 * jumpVal * ledshim.NUM_PIXELS prVal = 10 * jumpPR * ledshim.NUM_PIXELS # Green lights show your current PR r, g, b = 0, 255, 0 if heightVal < prVal: # Additional red lights if you don't beat your PR r = 255 else: # Additional blue lights if you beat the PR b = 255 # Set LED colors for x in range(ledshim.NUM_PIXELS): if heightVal < 0: r, b = 0, 0 if prVal < 0: g = 0 ledshim.set_pixel(x, r, g, b) heightVal -= 1 prVal -= 1 # Turn on the LEDs ledshim.show()
def on_wait(self, agent, t): FALLOFF = 1.9 SCAN_SPEED = 4 # ledshim.set_brightness(0.4) ledshim.set_clear_on_exit() ledshim.clear() ledshim.show() # Buffering start and end time to avoid hitting associations, # deauths, and handshakes since it can bug out the wait cycle time.sleep(1) start_time = time.time() while (time.time() - start_time) < (t - 2): delta = (time.time() - start_time) offset = (math.sin(delta * SCAN_SPEED) + 1) / 2 hue = int(round(offset * 360)) max_val = ledshim.NUM_PIXELS - 1 offset = int(round(offset * max_val)) for x in range(ledshim.NUM_PIXELS): sat = 1.0 val = max_val - (abs(offset - x) * FALLOFF) val /= float(max_val) # Convert to 0.0 to 1.0 val = max(val, 0.0) # Ditch negative values r, g, b = [255, 0, 0] ledshim.set_pixel(x, r, g, b, val / 4) ledshim.show() time.sleep(0.001) ledshim.clear() ledshim.show()
def show_graph(temp, load): segment_pixels_count = output_device.NUM_PIXELS / 4 temp = temp / 80 * output_device.NUM_PIXELS if isinstance(load, list): load = [x / 100 * segment_pixels_count for x in load] else: load = load / 100 * output_device.NUM_PIXELS pixels = range(output_device.NUM_PIXELS) current = 0 if direction.lower() == "rtl": pixels = reversed(pixels) for x in pixels: r, g, b = 0, 0, 0 if temp > 0: r = get_value(temp) temp -= 1 if isinstance(load, list): segment_index = math.trunc(x / segment_pixels_count) if load[segment_index] > 0: b = get_value(load[segment_index]) load[segment_index] -= 1 else: if load > 0: b = get_value(load) load -= 1 # show the marker, if it's not the last pixel and if it's the last pixel of the segment. if marker and current + 1 != output_device.NUM_PIXELS and ( current + 1) % segment_pixels_count == 0: g = 255 output_device.set_pixel(x, r, g, b) current += 1 output_device.show()
def set_pixel(x, hew, saturation, brightness): r, g, b = [ int(c * 255) for c in colorsys.hsv_to_rgb(hew, saturation, brightness) ] if x >= num_leds: print("Trying to highlight out of range pixel", x) return ledshim.set_pixel(x, r, g, b, brightness)
def reset(): pixelCount = (request.json['pixelCount']) delay = 0.1 for pixel in range(pixelCount - 1, -1, -1): ledshim.set_pixel(pixel, 0, 0, 0) ledshim.show() time.sleep(delay) return '200 OK'
def drawAndReset(self): for i in range(ledshim.NUM_PIXELS): j = ledshim.NUM_PIXELS - i - 1 ledshim.set_pixel(i, self.array[j][0], self.array[j][1], self.array[j][2]) self.array[j] = (0, 0, 0) ledshim.show()
def show_graph(vp, r, g, b): """asdasd""" barlen = vp * ledshim.NUM_PIXELS for x in range(ledshim.NUM_PIXELS): if barlen < 0: r, g, b = 0, 0, 0 else: r, g, b = [int(min(barlen, 1.0) * c / 2) + 127 for c in [r, g, b]] ledshim.set_pixel(abs((27*invert)-x), r, g, b) barlen -= 1
def show_graph(v, r, g, b): v *= ledshim.NUM_PIXELS for x in range(ledshim.NUM_PIXELS): if v < 0: r, g, b = 0, 0, 0 else: r, g, b = [int(min(v, 1.0) * c) for c in [r, g, b]] ledshim.set_pixel(x, r, g, b) v -= 1 ledshim.show()
def drawAndReset(self): for i in range(ledshim.NUM_PIXELS): ledshim.set_pixel( i, self.array[i][0], self.array[i][1], self.array[i][2] ) self.array[i] = (0,0,0) ledshim.show()
def show_graph(v, r, g, b, i, c): v *= ledshim.NUM_PIXELS / c for x in range(int((ledshim.NUM_PIXELS / c) * i), int((ledshim.NUM_PIXELS / c) * (i + 1))): if v < 0: r, g, b = 0, 0, 0 else: r, g, b = [int(min(v, 1.0) * c) for c in [r, g, b]] ledshim.set_pixel(x, r, g, b) v -= 1 ledshim.show()
def blink_ledshim(): for i in range(3): for j in range(ledshim.NUM_PIXELS): ledshim.set_pixel(j, 255, 0, 0) ledshim.show() time.sleep(0.1) for j in range(ledshim.NUM_PIXELS): ledshim.set_pixel(j, 0, 0, 0) ledshim.show() time.sleep(0.2)
def larson(): global animateStop animateStop = False REDS = [0] * 56 SCAN = [1, 2, 4, 8, 16, 32, 64, 128, 255] REDS[28 - len(SCAN):28 + len(SCAN)] = SCAN + SCAN[::-1] start_time = time.time() while not animateStop: delta = (time.time() - start_time) * 56 offset = int(abs((delta % len(REDS)) - 28)) for i in range(0, 28): ledshim.set_pixel(i, REDS[offset + i], 0, 0) ledshim.show() time.sleep(0.05)
def breakup(): stopAnimations() # stop animation thread showTime = 2.0 # show for 2 seconds startTime = time.time() while time.time() - startTime < showTime: pixels = random.sample(range(ledshim.NUM_PIXELS), random.randint(1, 5)) for i in range(ledshim.NUM_PIXELS): if i in pixels: ledshim.set_pixel(i, 255, 150, 0) else: ledshim.set_pixel(i, 0, 0, 0) ledshim.show() time.sleep(0.05) ledshim.clear() # turn off after showTime ledshim.show()
def show_graph(v, r, g, b): v *= ledshim.NUM_PIXELS for x in range(ledshim.NUM_PIXELS): hue = ((hue_start + ((x / float(ledshim.NUM_PIXELS)) * hue_range)) % 360) / 360.0 r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(hue, 1.0, 1.0)] if v < 0: brightness = 0 else: brightness = min(v, 1.0) * max_brightness ledshim.set_pixel(x, r, g, b, brightness) v -= 1 ledshim.show()
def set_pixel(pixel, status): if status == 'red': ledshim.set_pixel(pixel, 255, 0, 0, 0.5) elif status == 'amber': ledshim.set_pixel(pixel, 255, 140, 0, 0.5) elif status == 'green': ledshim.set_pixel(pixel, 0, 255, 0, 0.5) else: ledshim.set_pixel(pixel, 0, 0, 0) ledshim.show() return
def pulse(): global animateStop animateStop = False while not animateStop: for z in list(range(1, 10)[::-1]) + list(range(1, 10)): fwhm = 15.0 / z gauss = make_gaussian(fwhm) y = 4 start = time.time() for x in range(ledshim.NUM_PIXELS): h = 0.5 s = 1.0 v = gauss[x, y] rgb = colorsys.hsv_to_rgb(h, s, v) r, g, b = [int(255.0 * i) for i in rgb] ledshim.set_pixel(x, r, g, b) ledshim.show() end = time.time() t = end - start if t < 0.04: time.sleep(0.04 - t)
def on_deauthentication(self, agent, access_point, client_station): ledshim.set_clear_on_exit() ledshim.clear() ledshim.show() num = 5 while num >= 0: pixels = random.sample(range(ledshim.NUM_PIXELS), random.randint(1, 5)) for i in range(ledshim.NUM_PIXELS): if i in pixels: ledshim.set_pixel(i, 255, 0, 0) else: ledshim.set_pixel(i, 0, 0, 0) ledshim.show() num -= 1 time.sleep(0.02) ledshim.clear() ledshim.show()
def on_message(client, userdata, msg): data = msg.payload.split(',') command = data.pop(0) if command == 'clr' and len(data) == 0: ledshim.clear() ledshim.show() return if command == 'rgb' and len(data) == 4: try: pixel = data.pop(0) if pixel == '*': pixel = None else: pixel = int(pixel) if pixel > 7: print('Pixel out of range: ' + str(pixel)) return r, g, b = [int(x) & 0xff for x in data] print(command, pixel, r, g, b) except ValueError: print('Malformed command: ' + str(msg.payload)) return if pixel is None: for x in range(ledshim.NUM_PIXELS): ledshim.set_pixel(x, r, g, b) else: ledshim.set_pixel(pixel, r, g, b) ledshim.show() return
def on_handshake(self, agent, filename, access_point, client_station): ledshim.set_clear_on_exit() ledshim.clear() ledshim.show() num = 20 while num >= 0: pixels = random.sample(range(ledshim.NUM_PIXELS), random.randint(1, 5)) for i in range(ledshim.NUM_PIXELS): if i in pixels: ledshim.set_pixel(i, random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) else: ledshim.set_pixel(i, 0, 0, 0) ledshim.show() num -= 1 time.sleep(0.001) ledshim.clear() ledshim.show()
def show_all(state): for i in range(ledshim.NUM_PIXELS): val = state * 255 ledshim.set_pixel(i, val, val, val) ledshim.show()
import time import ledshim for x in range(ledshim.width): ledshim.set_pixel(x, 255, 0, 0) ledshim.show() time.sleep(0.05) time.sleep(0.1) ledshim.clear() ledshim.show() for x in range(ledshim.width): ledshim.set_pixel(x, 0, 255, 0) ledshim.show() time.sleep(0.05) time.sleep(0.1) ledshim.clear() ledshim.show() for x in range(ledshim.width): ledshim.set_pixel(x, 0, 0, 255) ledshim.show() time.sleep(0.05)
try: import requests except ImportError: exit( 'This script requires the requests module\nInstall with: sudo pip install requests' ) import ledshim ledshim.set_clear_on_exit() def hex_to_rgb(col_hex): """Convert a hex colour to an RGB tuple.""" col_hex = col_hex.lstrip('#') return bytearray.fromhex(col_hex) while True: r = requests.get( 'http://api.thingspeak.com/channels/1417/field/2/last.json', timeout=2) r, g, b = hex_to_rgb(r.json()['field2']) for i in range(ledshim.NUM_PIXELS): ledshim.set_pixel(i, r, g, b) ledshim.show() time.sleep(5) # Be friendly to the API
# Use offset to pick the right colour from the hue wheel hue = int(round(offset * 360)) # Maximum number basex on NUM_PIXELS max_val = ledshim.NUM_PIXELS - 1 # Now we generate a value from 0 to max_val offset = int(round(offset * max_val)) for x in range(ledshim.NUM_PIXELS): sat = 1.0 val = max_val - (abs(offset - x) * FALLOFF) val /= float(max_val) # Convert to 0.0 to 1.0 val = max(val, 0.0) # Ditch negative values xhue = hue # Grab hue for this pixel xhue += ( 1 - val ) * 10 # Use the val offset to give a slight colour trail variation xhue %= 360 # Clamp to 0-359 xhue /= 360.0 # Convert to 0.0 to 1.0 r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(xhue, sat, val)] ledshim.set_pixel(x, r, g, b, val / 4) ledshim.show() time.sleep(0.001)
def set_one(self, led_number, color): ledshim.set_pixel(led_number, *color)
#!/usr/bin/env python import time import ledshim ledshim.set_clear_on_exit() REDS = [0] * ledshim.NUM_PIXELS * 2 SCAN = [1, 2, 4, 8, 16, 32, 64, 128, 255] REDS[ledshim.NUM_PIXELS - len(SCAN):ledshim.NUM_PIXELS + len(SCAN)] = SCAN + SCAN[::-1] start_time = time.time() while True: # Sine wave, spends a little longer at min/max # delta = (time.time() - start_time) * 8 # offset = int(round(((math.sin(delta) + 1) / 2) * (ledshim.NUM_PIXELS - 1))) # Triangle wave, a snappy ping-pong effect delta = (time.time() - start_time) * ledshim.NUM_PIXELS * 2 offset = int(abs((delta % len(REDS)) - ledshim.NUM_PIXELS)) for i in range(ledshim.NUM_PIXELS): ledshim.set_pixel(i, REDS[offset + i], 0, 0) ledshim.show() time.sleep(0.05)
def update(): for i in range(ledshim.NUM_PIXELS): ledshim.set_pixel(i, grid[i][0], grid[i][1], grid[i][2]) ledshim.show()
def hide(): for line in get_lines(): ledshim.set_pixel(line, 0, 0, 0) ledshim.show()
pixel_list.pop() print('Large rise by: ', diff) logging.info('Large rise by: {}'.format(diff)) elif diff < 0 and diff > -threshold: # value falls: < 0 and > -(threshold) pixel_list.insert(0, fall_1) pixel_list.pop() print('Small fall by: ', diff) elif diff <= -threshold: # value LARGE FALL: < or = to threshold pixel_list.insert(0, fall_2) pixel_list.pop() print('Large fall by: ', diff) logging.info('Large fall by: {}'.format(diff)) else: # value unchanged pixel_list.insert(0, same) pixel_list.pop() print('Price unchanged: ', diff) prevPrice = nebl_price_in_euros #print(pixel_list) print() return pixel_list while True: ledshim.clear() get_NEBL_price_in_btc() for num in range(num_of_pixels): ledshim.set_pixel(num, *pixel_list[num]) #print(num, *pixel_list[num]) # Test code ledshim.show() sleep(wait_secs)
#!/usr/bin/env python import time import ledshim r, g, b = 255, 0, 0 delay = 0.1 half_way = ledshim.NUM_PIXELS / 2 while True: # Turn pixels on for x in range(half_way): ledshim.set_pixel(half_way - 1 - x, r, g, b) ledshim.set_pixel(half_way + x, r, g, b) ledshim.show() time.sleep(delay) # Turn pixels off for x in range(half_way): ledshim.set_pixel(x, 0, 0, 0) ledshim.set_pixel(ledshim.NUM_PIXELS - 1 - x, 0, 0, 0) ledshim.show() time.sleep(delay)
ledshim.set_clear_on_exit() def make_gaussian(fwhm): x = np.arange(0, ledshim.NUM_PIXELS, 1, float) y = x[:, np.newaxis] x0, y0 = 3.5, (ledshim.NUM_PIXELS / 2) - 0.5 fwhm = fwhm gauss = np.exp(-4 * np.log(2) * ((x - x0)**2 + (y - y0)**2) / fwhm**2) return gauss while True: for z in list(range(1, 10)[::-1]) + list(range(1, 10)): fwhm = 15.0 / z gauss = make_gaussian(fwhm) start = time.time() y = 4 for x in range(ledshim.NUM_PIXELS): h = 0.5 s = 1.0 v = gauss[x, y] rgb = colorsys.hsv_to_rgb(h, s, v) r, g, b = [int(255.0 * i) for i in rgb] ledshim.set_pixel(x, r, g, b) ledshim.show() end = time.time() t = end - start if t < 0.04: time.sleep(0.04 - t)
t = r.read() ll = list(t[2]) # Pixels data in boxed row flat pixel format line_number = 0 while (True): line = ll[line_number] # Take one line i = 0 pixel = 0 if t[0] == 1: r, g, b = line ledshim.set_all(r, g, b) else: for value in line: if pixel < ledshim.NUM_PIXELS: if i % 3 == 0: r = value if i % 3 == 1: g = value if i % 3 == 2: b = value ledshim.set_pixel(pixel, r, g, b) pixel = pixel + 1 i = i + 1 ledshim.show() time.sleep(0.001) line_number = line_number + 1 if line_number == t[1]: line_number = 0